diff --git a/.gitattributes b/.gitattributes index 071a6a2..534c645 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,6 +9,7 @@ /.gitignore export-ignore /.gitreview export-ignore /.php_cs.dist export-ignore +/rector.php export-ignore .gitkeep export-ignore # Enforce checkout with linux lf consistent over all plattforms diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 07817ec..bc13c14 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -58,6 +58,43 @@ jobs: - name: Check dependencies run: vendor/bin/composer ci:composer:require-checker + yaml_lint: + name: YAML Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + coverage: none + extensions: intl, zip + ini-values: memory_limit=-1, error_reporting=E_ALL, display_errors=On + php-version: latest + tools: composer + + - name: Composer Cache Vars + id: composer-cache-vars + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + echo "::set-output name=timestamp::$(date +"%s")" + + - name: Cache Composer dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache-vars.outputs.dir }} + key: ${{ runner.os }}-composer-${{ steps.composer-cache-vars.outputs.timestamp }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install ${{ env.COMPOSER_FLAGS }} + + - name: Lint YAML files + run: vendor/bin/composer ci:yaml:lint + php_lint: name: PHP Lint runs-on: ubuntu-latest @@ -67,7 +104,7 @@ jobs: fail-fast: false matrix: php-version: - - '7.2' + - '7.4' - 'latest' experimental: - false @@ -241,7 +278,7 @@ jobs: fail-fast: false matrix: php-version: - - '7.2' + - '7.4' - 'latest' dependencies: - 'lowest' @@ -319,7 +356,6 @@ jobs: os: - ubuntu-latest php-version: - - '7.2' - '7.4' - 'latest' composer-version: diff --git a/composer.json b/composer.json index 7828e2a..a577998 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "source": "https://github.com/GsTYPO3/core-patches" }, "require": { - "php": "^7.2.5 || ^8.0", + "php": "^7.4.1 || ^8.0", "ext-json": "*", "composer-plugin-api": "^2.0", "cweagans/composer-patches": "^1.7" @@ -115,6 +115,7 @@ "ci:tests:functional": "echo 'phpunit -c phpunit.xml.dist --log-junit var/log/phpunit-functional.xml --testsuite \"Functional Test Suite\"'", "ci:tests:smoke": "echo 'phpunit -c phpunit.xml.dist --log-junit var/log/phpunit-unit.xml --testsuite \"Smoke Test Suite\"'", "ci:tests:unit": "echo 'phpunit -c phpunit.xml.dist --log-junit var/log/phpunit-unit.xml --testsuite \"Unit Test Suite\"'", + "ci:yaml:lint": "yaml-lint .ddev .github", "clean": [ "@tools:setup:clean", "rm -fr vendor .php-cs-fixer.cache .phplint-cache composer.lock" @@ -201,6 +202,6 @@ "tools:tests:functional": "phpunit -c phpunit.xml.dist --log-junit var/log/phpunit-functional.xml --testsuite \"Functional Test Suite\"", "tools:tests:smoke": "phpunit -c phpunit.xml.dist --log-junit var/log/phpunit-unit.xml --testsuite \"Smoke Test Suite\"", "tools:tests:unit": "phpunit -c phpunit.xml.dist --log-junit var/log/phpunit-unit.xml --testsuite \"Unit Test Suite\"", - "tools:yaml:lint": "yaml-lint .ddev" + "tools:yaml:lint": "yaml-lint .ddev .github" } } diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..1aaf317 --- /dev/null +++ b/rector.php @@ -0,0 +1,39 @@ +parameters(); + $parameters->set(Option::PATHS, [ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $parameters->set(Option::BOOTSTRAP_FILES, [ + __DIR__ . '/vendor/autoload.php', + ]); + + // Define what rule sets will be applied + $containerConfigurator->import(LevelSetList::UP_TO_PHP_74); + + // get services (needed for register a single rule) + // $services = $containerConfigurator->services(); + + // register a single rule + // $services->set(TypedPropertyRector::class); +}; diff --git a/src/Command/Typo3/Patch/ApplyCommand.php b/src/Command/Typo3/Patch/ApplyCommand.php index 0d55dac..9be119b 100644 --- a/src/Command/Typo3/Patch/ApplyCommand.php +++ b/src/Command/Typo3/Patch/ApplyCommand.php @@ -82,7 +82,7 @@ public function execute(InputInterface $input, OutputInterface $output) // Get Composer instance if (!($composer = $this->getComposer(true)) instanceof Composer) { - throw new UnexpectedValueException('Invalid Composer instance.', 1640857365); + throw new UnexpectedValueException('Invalid Composer instance.', 1_640_857_365); } $io = $this->getIO(); diff --git a/src/Command/Typo3/Patch/RemoveCommand.php b/src/Command/Typo3/Patch/RemoveCommand.php index c5cb99f..0eb0332 100644 --- a/src/Command/Typo3/Patch/RemoveCommand.php +++ b/src/Command/Typo3/Patch/RemoveCommand.php @@ -57,7 +57,7 @@ public function execute(InputInterface $input, OutputInterface $output) // Get Composer instance if (!($composer = $this->getComposer(true)) instanceof Composer) { - throw new UnexpectedValueException('Invalid Composer instance.', 1640857366); + throw new UnexpectedValueException('Invalid Composer instance.', 1_640_857_366); } $io = $this->getIO(); diff --git a/src/Plugin.php b/src/Plugin.php index a6a8b83..ec3816c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -15,6 +15,7 @@ use Composer\Composer; use Composer\IO\IOInterface; +use Composer\Plugin\Capability\CommandProvider as ComposerCommandProvider; use Composer\Plugin\Capable; use Composer\Plugin\PluginInterface; @@ -54,7 +55,7 @@ public function uninstall(Composer $composer, IOInterface $io) public function getCapabilities() { return [ - 'Composer\Plugin\Capability\CommandProvider' => 'GsTYPO3\CorePatches\CommandProvider', + ComposerCommandProvider::class => CommandProvider::class, ]; } } diff --git a/src/Utility/ComposerUtils.php b/src/Utility/ComposerUtils.php index bf4284a..6912c26 100644 --- a/src/Utility/ComposerUtils.php +++ b/src/Utility/ComposerUtils.php @@ -36,16 +36,11 @@ final class ComposerUtils private const EXTRA_APPLIED_CHANGES = 'applied-changes'; private const EXTRA_PREFERRED_INSTALL_CHANGED = 'preferred-install-changed'; - /** @var Composer */ - private $composer; - /** @var IOInterface */ - private $io; - /** @var Application */ - private $application; - /** @var JsonFile */ - private $configFile; - /** @var JsonConfigSource */ - private $configSource; + private Composer $composer; + private IOInterface $io; + private Application $application; + private JsonFile $configFile; + private JsonConfigSource $configSource; public function __construct(Composer $composer, IOInterface $io) { @@ -216,9 +211,7 @@ private function removeAppliedChange(int $numericId): void return; } - $currentValue = array_filter($currentValue, function ($value) use ($numericId) { - return $value !== $numericId; - }); + $currentValue = array_filter($currentValue, fn ($value) => $value !== $numericId); sort($currentValue); $this->configSource->addProperty( @@ -262,9 +255,7 @@ private function removePreferredInstallChanged(string $packageName): void return; } - $currentValue = array_filter($currentValue, function ($value) use ($packageName) { - return $value !== $packageName; - }); + $currentValue = array_filter($currentValue, fn ($value) => $value !== $packageName); sort($currentValue); $this->configSource->addProperty( @@ -347,7 +338,7 @@ public function addPatches(array $changeIds, string $destination, bool $includeT $this->addPatchesToConfigFile($patches); $this->addAppliedChange($numericId); - $affectedPackages = array_merge($affectedPackages, array_keys($patches)); + $affectedPackages = [...$affectedPackages, ...array_keys($patches)]; $patchesCount += $patchesCreated; } @@ -377,9 +368,7 @@ public function addPatches(array $changeIds, string $destination, bool $includeT $promises[] = $this->uninstallPackage($package); // Remove package from the array - $affectedPackages = array_filter($affectedPackages, function ($value) use ($packageName) { - return $value !== $packageName; - }); + $affectedPackages = array_filter($affectedPackages, fn ($value) => $value !== $packageName); } } diff --git a/src/Utility/GerritUtils.php b/src/Utility/GerritUtils.php index 3f54f86..67d85b3 100644 --- a/src/Utility/GerritUtils.php +++ b/src/Utility/GerritUtils.php @@ -23,10 +23,9 @@ final class GerritUtils { private const BASE_URL = 'https://review.typo3.org/'; - /** @var HttpDownloader */ - private $downloader; + private HttpDownloader $downloader; /** @var array>|null */ - private $changeInfo; + private ?array $changeInfo = null; /** * @param HttpDownloader $downloader A HttpDownloader instance @@ -68,10 +67,10 @@ public function getChange(string $changeId): array $body = substr($body, 4); } - $changeInfo = json_decode(trim($body), true); + $changeInfo = json_decode(trim($body), true, 512, JSON_THROW_ON_ERROR); if ($changeInfo === null || !is_array($changeInfo)) { - throw new InvalidResponseException('Error invalid response.', 1640784346); + throw new InvalidResponseException('Error invalid response.'); } $this->changeInfo[$changeId] = $changeInfo; } @@ -93,11 +92,11 @@ public function getSubject(string $changeId): string $changeInfo = $this->getChange($changeId); if (!is_string($subject = ($changeInfo['subject'] ?? null))) { - throw new UnexpectedValueException('Subject was not found.', 1640944473); + throw new UnexpectedValueException('Subject was not found.'); } if (($normalizedSubject = preg_replace('/^\[.+?\] /', '', $subject)) === null) { - throw new UnexpectedValueException(sprintf('Subject "%s" could not be normalized.', $subject), 1640944474); + throw new UnexpectedValueException(sprintf('Subject "%s" could not be normalized.', $subject)); } return $normalizedSubject; @@ -117,7 +116,7 @@ public function getNumericId(string $changeId): int $changeInfo = $this->getChange($changeId); if (!is_int($numericId = ($changeInfo['_number'] ?? null))) { - throw new UnexpectedValueException('Number was not found.', 1640944475); + throw new UnexpectedValueException('Number was not found.'); } return $numericId; diff --git a/src/Utility/PatchUtils.php b/src/Utility/PatchUtils.php index 4ac7f63..de41696 100644 --- a/src/Utility/PatchUtils.php +++ b/src/Utility/PatchUtils.php @@ -21,10 +21,8 @@ final class PatchUtils { - /** @var Composer */ - private $composer; - /** @var IOInterface */ - private $io; + private Composer $composer; + private IOInterface $io; public function __construct(Composer $composer, IOInterface $io) {