Skip to content

Commit

Permalink
[TASK] Apply TYPO3 CGL and added code quality stage
Browse files Browse the repository at this point in the history
  • Loading branch information
derhansen committed Sep 21, 2023
1 parent 0b4ad79 commit 7d40c22
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 112 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/CodeQuality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Code Quality Checks

on: [ push, pull_request ]

jobs:
build:

runs-on: ubuntu-20.latest

strategy:
matrix:
env:
- { php: 7.4 }
- { php: 8.0 }
- { php: 8.1 }

env: ${{ matrix.env }}

steps:
- uses: actions/checkout@v3

- name: Set up PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.env.php }}
tools: composer:v2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Install composer dependencies
run: |
composer install --no-progress
- name: Validate PHP coding guidelines
run: |
.Build/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.Build
composer.lock
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
23 changes: 10 additions & 13 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<?php
$header = <<<'EOF'

This file is part of the TYPO3 extension uw_a11_check.
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;
return PhpCsFixer\Config::create()
return (new \PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@DoctrineAnnotation' => true,
'@PSR2' => true,
'@PER' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'braces' => ['allow_single_line_closure' => true],
Expand All @@ -20,7 +14,6 @@
'declare_equal_normalize' => ['space' => 'none'],
'dir_constant' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'lowercase_cast' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'modernize_types_casting' => true,
Expand All @@ -30,7 +23,7 @@
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_null_property_initialization' => true,
Expand All @@ -41,9 +34,10 @@
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_nullsafe_operator' => true,
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'php_unit_construct' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame'],
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
'php_unit_mock_short_will_return' => true,
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'phpdoc_no_access' => true,
Expand All @@ -55,12 +49,15 @@
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'return_type_declaration' => ['space_before' => 'none'],
'single_quote' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
'single_trait_insert_per_statement' => true,
'whitespace_after_comma_in_array' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude(['.Build', 'Documentation', 'Resources'])
->notName('ext_emconf.php')
);
);
2 changes: 1 addition & 1 deletion Classes/Analyzers/AbstractAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
abstract class AbstractAnalyzer implements AnalyzerInterface
{
const TYPE_INTERNAL = 'internal';
public const TYPE_INTERNAL = 'internal';

/**
* @var string
Expand Down
12 changes: 6 additions & 6 deletions Classes/Check/Result/Impact.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*/
class Impact
{
const FAILED = 0;
const NONE = 1;
const MINOR = 2;
const MODERATE = 3;
const SERIOUS = 4;
const CRITICAL = 5;
public const FAILED = 0;
public const NONE = 1;
public const MINOR = 2;
public const MODERATE = 3;
public const SERIOUS = 4;
public const CRITICAL = 5;
}
8 changes: 4 additions & 4 deletions Classes/Check/Result/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
class Status
{
const PASSES = 0;
const VIOLATIONS = 1;
const INAPPLICABLE = 2;
const INCOMPLETE = 3;
public const PASSES = 0;
public const VIOLATIONS = 1;
public const INAPPLICABLE = 2;
public const INCOMPLETE = 3;
}
2 changes: 1 addition & 1 deletion Classes/CheckUrlGenerators/PageContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getCheckUrl(int $pageUid): string
'tx_uwa11ycheck_pi1[controller]' => 'ContentElements',
'tx_uwa11ycheck_pi1[pageUid]' => $pageUid,
'tx_uwa11ycheck_pi1[ignoreContentTypes]' => $ignoreContentTypes,
'tx_uwa11ycheck_pi1[hmac]' => $hmac
'tx_uwa11ycheck_pi1[hmac]' => $hmac,
];
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($this->targetPid);

Expand Down
1 change: 1 addition & 0 deletions Classes/Command/AbstractCheckCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace UniWue\UwA11yCheck\Command;

use Symfony\Component\Console\Command\Command;
Expand Down
1 change: 1 addition & 0 deletions Classes/Command/PresetByPageUidCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace UniWue\UwA11yCheck\Command;

use Symfony\Component\Console\Input\InputArgument;
Expand Down
1 change: 1 addition & 0 deletions Classes/Command/PresetByRecordUidsCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace UniWue\UwA11yCheck\Command;

use Symfony\Component\Console\Input\InputArgument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public function __construct()
*/
public function getTypes($class, $property, array $context = [])
{
if (is_a($class, ResultSet::class, true) && 'results' === $property) {
if (is_a($class, ResultSet::class, true) && $property === 'results') {
return [
new Type(Type::BUILTIN_TYPE_OBJECT, true, Result::class . '[]')
new Type(Type::BUILTIN_TYPE_OBJECT, true, Result::class . '[]'),
];
}
if (is_a($class, Result::class, true) && 'nodes' === $property) {
if (is_a($class, Result::class, true) && $property === 'nodes') {
return [
new Type(Type::BUILTIN_TYPE_OBJECT, true, Node::class . '[]')
new Type(Type::BUILTIN_TYPE_OBJECT, true, Node::class . '[]'),
];
}
return $this->reflectionExtractor->getTypes($class, $property, $context);
Expand Down
14 changes: 7 additions & 7 deletions Classes/Controller/A11yCheckController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
*/
class A11yCheckController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
const LANG_CORE = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:';
const LANG_LOCAL = 'LLL:EXT:uw_a11y_check/Resources/Private/Language/locallang.xlf:';
public const LANG_CORE = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:';
public const LANG_LOCAL = 'LLL:EXT:uw_a11y_check/Resources/Private/Language/locallang.xlf:';

/**
* @var PresetService
Expand Down Expand Up @@ -120,7 +120,7 @@ public function indexAction($checkDemand = null): void
null,
null,
[
'checkDemand' => $checkDemand->toArray()
'checkDemand' => $checkDemand->toArray(),
]
);
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public function checkAction(CheckDemand $checkDemand): void
$this->view->assignMultiple([
'checkDemand' => $checkDemand,
'results' => $results,
'date' => new \DateTime()
'date' => new \DateTime(),
]);
}

Expand All @@ -177,7 +177,7 @@ public function resultsAction(): void
$resultsArray = $this->resultsService->getResultsArrayByPid($this->pid);

$this->view->assignMultiple([
'resultsArray' => $resultsArray
'resultsArray' => $resultsArray,
]);
}

Expand Down Expand Up @@ -254,7 +254,7 @@ protected function createAcknowledgeButton(int $pid): void
->setDataAttributes([
'toggle' => 'tooltip',
'placement' => 'bottom',
'title' => $title
'title' => $title,
])
->setTitle($title)
->setShowLabelText(true)
Expand All @@ -273,7 +273,7 @@ protected function getLevelSelectorOptions(): array
2 => $this->getLanguageService()->sL(self::LANG_CORE . 'labels.depth_2'),
3 => $this->getLanguageService()->sL(self::LANG_CORE . 'labels.depth_3'),
4 => $this->getLanguageService()->sL(self::LANG_CORE . 'labels.depth_4'),
999 => $this->getLanguageService()->sL(self::LANG_CORE . 'labels.depth_infi')
999 => $this->getLanguageService()->sL(self::LANG_CORE . 'labels.depth_infi'),
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace UniWue\UwA11yCheck\Utility\Exception;

/**
Expand Down
5 changes: 2 additions & 3 deletions Classes/Utility/Exception/MissingConfigurationException.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

declare(strict_types=1);

namespace UniWue\UwA11yCheck\Utility\Exception;

/**
* Exception thrown if the configuration does not contain an expected entry
*/
class MissingConfigurationException extends \RuntimeException
{
}
class MissingConfigurationException extends \RuntimeException {}
8 changes: 4 additions & 4 deletions Tests/Unit/Tests/Utility/Tests/HeaderUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ public function headersSequentiallyDescendingTestsDataProvider()
'h1 followed by h2' => [
'<h1>h1</h1>',
'<h2>h2</h2>',
true
true,
],
'h1 followed by h3' => [
'<h1>h1</h1>',
'<h3>h3</h3>',
false
false,
],
'h1 followed by h6' => [
'<h1>h1</h1>',
'<h6>h6</h6>',
false
false,
],
'h3 followed by h2' => [
'<h3>h3</h3>',
'<h2>h2</h2>',
true
true,
],
];
}
Expand Down
Loading

0 comments on commit 7d40c22

Please sign in to comment.