diff --git a/.github/workflows/bc.yml b/.github/workflows/bc.yml index 75f97a7..ba3e9ef 100644 --- a/.github/workflows/bc.yml +++ b/.github/workflows/bc.yml @@ -3,13 +3,12 @@ on: - push name: backwards compatibility + jobs: roave_bc_check: - name: Roave BC Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: fetch tags - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - - name: Roave BC Check - uses: docker://nyholm/roave-bc-check-ga + uses: yiisoft/actions/.github/workflows/bc.yml@master + with: + os: >- + ['ubuntu-latest'] + php: >- + ['8.0'] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0dde6b6..ed9a60b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,4 +28,4 @@ jobs: os: >- ['ubuntu-latest', 'windows-latest'] php: >- - ['7.4', '8.0', '8.1'] + ['8.0', '8.1', '8.2'] diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml new file mode 100644 index 0000000..adacd73 --- /dev/null +++ b/.github/workflows/rector.yml @@ -0,0 +1,21 @@ +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' + +name: rector + +jobs: + rector: + uses: yiisoft/actions/.github/workflows/rector.yml@master + with: + os: >- + ['ubuntu-latest'] + php: >- + ['8.0'] diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 40ac260..fb7fc77 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -28,4 +28,4 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['7.4', '8.0', '8.1'] + ['8.0', '8.1', '8.2'] diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aa4c2e..c83fc4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,17 @@ # Yii Config Change Log -## 1.1.2 under development +## 1.2.0 under development -- Enh #119: Improve performance of collecting data for `ReverseMerge` and `RecursiveMerge` (samdark) +- Enh #119: Improve performance of collecting data for `ReverseMerge` and `RecursiveMerge` (@samdark) +- Enh #122: Raise minimal PHP version to 8.0 (@vjik, @xepozz) ## 1.1.1 January 05, 2022 -- Enh #110: Improve the error message by displaying a name of the group where the error occurred when merging (devanych) +- Enh #110: Improve the error message by displaying a name of the group where the error occurred when merging (@devanych) ## 1.1.0 December 31, 2021 -- New #108: Add `Yiisoft\Config\ConfigInterface` to allow custom implementations of a config loader (devanych) +- New #108: Add `Yiisoft\Config\ConfigInterface` to allow custom implementations of a config loader (@devanych) ## 1.0.0 December 17, 2021 diff --git a/README.md b/README.md index bc76231..a6b436f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ a plugin system. The package becomes a plugin holding both the code and its conf ## Requirements -- PHP 7.4 or higher. +- PHP 8.0 or higher. - Composer 2.0 or higher. ## Installation diff --git a/composer.json b/composer.json index 5a32384..41cfe12 100644 --- a/composer.json +++ b/composer.json @@ -28,18 +28,19 @@ } ], "require": { - "php": "^7.4|^8.0", + "php": "^8.0", "composer-plugin-api": "^2.0", "yiisoft/strings": "^2.0", "yiisoft/var-dumper": "^1.1" }, "require-dev": { + "ext-json": "*", "composer/composer": "^2.0", "phpunit/phpunit": "^9.5", + "rector/rector": "^0.15.7", "roave/infection-static-analysis-plugin": "^1.16", "spatie/phpunit-watcher": "^1.23", - "vimeo/psalm": "^4.18", - "ext-json": "*" + "vimeo/psalm": "^4.18" }, "config": { "sort-packages": true, diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..e5f54a6 --- /dev/null +++ b/rector.php @@ -0,0 +1,29 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + // register a single rule + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + + // define sets of rules + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_80, + ]); + + $rectorConfig->skip([ + RemoveExtraParametersRector::class, + NonVariableToVariableOnFunctionCallRector::class, + ]); +}; diff --git a/src/Composer/PackageFile.php b/src/Composer/PackageFile.php index 7f8ff4b..41d848c 100644 --- a/src/Composer/PackageFile.php +++ b/src/Composer/PackageFile.php @@ -9,15 +9,11 @@ */ final class PackageFile { - private string $filename; - private string $relativePath; - private string $absolutePath; - - public function __construct(string $filename, string $relativePath, string $absolutePath) - { - $this->filename = $filename; - $this->relativePath = $relativePath; - $this->absolutePath = $absolutePath; + public function __construct( + private string $filename, + private string $relativePath, + private string $absolutePath, + ) { } public function filename(): string diff --git a/src/Composer/PackagesListBuilder.php b/src/Composer/PackagesListBuilder.php index 4a8a442..6766a85 100644 --- a/src/Composer/PackagesListBuilder.php +++ b/src/Composer/PackagesListBuilder.php @@ -15,11 +15,9 @@ */ final class PackagesListBuilder { - private Composer $composer; - - public function __construct(Composer $composer) - { - $this->composer = $composer; + public function __construct( + private Composer $composer, + ) { } /** diff --git a/src/Config.php b/src/Config.php index 2796c8d..1146301 100644 --- a/src/Config.php +++ b/src/Config.php @@ -21,7 +21,6 @@ final class Config implements ConfigInterface { private Merger $merger; private FilesExtractor $filesExtractor; - private string $paramsGroup; private bool $isBuildingParams = false; /** @@ -41,10 +40,9 @@ public function __construct( ConfigPaths $paths, string $environment = null, array $modifiers = [], - string $paramsGroup = 'params' + private string $paramsGroup = 'params' ) { $environment = empty($environment) ? Options::DEFAULT_ENVIRONMENT : $environment; - $this->paramsGroup = $paramsGroup; /** @psalm-suppress UnresolvableInclude, MixedArgument */ $mergePlan = new MergePlan(require $paths->absolute(Options::MERGE_PLAN_FILENAME)); @@ -196,8 +194,6 @@ private function buildFile(string $filePath): array } /** - * @param string $message - * * @throws ErrorException */ private function throwException(string $message): void diff --git a/src/ConfigPaths.php b/src/ConfigPaths.php index 333fd46..f9dd5e0 100644 --- a/src/ConfigPaths.php +++ b/src/ConfigPaths.php @@ -5,7 +5,6 @@ namespace Yiisoft\Config; use function strlen; -use function strpos; use function substr; use function trim; @@ -14,7 +13,6 @@ */ final class ConfigPaths { - private string $rootPath; private string $configPath; private string $vendorPath; @@ -23,10 +21,11 @@ final class ConfigPaths * @param string|null $configDirectory The relative path to the configuration storage location. * @param string|null $vendorDirectory The relative path to the vendor directory. */ - public function __construct(string $rootPath, string $configDirectory = null, string $vendorDirectory = null) - { - $this->rootPath = $rootPath; - + public function __construct( + private string $rootPath, + string $configDirectory = null, + string $vendorDirectory = null, + ) { $configDirectory = trim($configDirectory ?? Options::DEFAULT_CONFIG_DIRECTORY, '/'); $this->configPath = $rootPath . ($configDirectory === '' ? '' : "/$configDirectory"); @@ -64,7 +63,7 @@ public function absolute(string $file, string $package = Options::ROOT_PACKAGE_N */ public function relative(string $file): string { - return strpos($file, "$this->rootPath/") === 0 + return str_starts_with($file, "$this->rootPath/") ? substr($file, strlen("$this->rootPath/")) : $file; } diff --git a/src/Context.php b/src/Context.php index e1c94f8..280e5d5 100644 --- a/src/Context.php +++ b/src/Context.php @@ -14,19 +14,13 @@ final class Context public const APPLICATION = 3; public const ENVIRONMENT = 4; - private string $group; - private string $package; - private int $layer; - private string $file; - private bool $isVariable; - - public function __construct(string $group, string $package, int $layer, string $file, bool $isVariable) - { - $this->group = $group; - $this->package = $package; - $this->layer = $layer; - $this->file = $file; - $this->isVariable = $isVariable; + public function __construct( + private string $group, + private string $package, + private int $layer, + private string $file, + private bool $isVariable, + ) { } public function group(): string diff --git a/src/DataModifiers.php b/src/DataModifiers.php index f9f23bc..19c69d5 100644 --- a/src/DataModifiers.php +++ b/src/DataModifiers.php @@ -33,12 +33,12 @@ final class DataModifiers /** * @psalm-var array */ - private array $removeFromVendorGroupsIndex; + private array $removeFromVendorGroupsIndex = []; /** * @psalm-var array> */ - private array $removeFromVendorKeysIndex; + private array $removeFromVendorKeysIndex = []; /** * @param object[] $modifiers Modifiers that affect merge process. @@ -48,9 +48,6 @@ public function __construct(array $modifiers = []) $reverseMergeGroups = []; $recursiveMergeGroups = []; - $this->removeFromVendorGroupsIndex = []; - $this->removeFromVendorKeysIndex = []; - foreach ($modifiers as $modifier) { if ($modifier instanceof ReverseMerge) { array_unshift($reverseMergeGroups, $modifier->getGroups()); diff --git a/src/FilesExtractor.php b/src/FilesExtractor.php index d42ec3a..a40be43 100644 --- a/src/FilesExtractor.php +++ b/src/FilesExtractor.php @@ -17,21 +17,12 @@ */ final class FilesExtractor { - private ConfigPaths $paths; - private MergePlan $mergePlan; - private DataModifiers $dataModifiers; - private string $environment; - public function __construct( - ConfigPaths $paths, - MergePlan $mergePlan, - DataModifiers $dataModifiers, - string $environment + private ConfigPaths $paths, + private MergePlan $mergePlan, + private DataModifiers $dataModifiers, + private string $environment, ) { - $this->paths = $paths; - $this->mergePlan = $mergePlan; - $this->dataModifiers = $dataModifiers; - $this->environment = $environment; } /** @@ -171,8 +162,6 @@ private function prepareEnvironment(string $group): string } /** - * @param string $message - * * @throws ErrorException */ private function throwException(string $message): void diff --git a/src/MergePlan.php b/src/MergePlan.php index b505e39..ca9bea4 100644 --- a/src/MergePlan.php +++ b/src/MergePlan.php @@ -9,17 +9,12 @@ */ final class MergePlan { - /** - * @psalm-var array>> - */ - private array $mergePlan; - /** * @psalm-param array>> $mergePlan */ - public function __construct(array $mergePlan = []) - { - $this->mergePlan = $mergePlan; + public function __construct( + private array $mergePlan = [], + ) { } /** diff --git a/src/Merger.php b/src/Merger.php index e4f77dd..a10aacc 100644 --- a/src/Merger.php +++ b/src/Merger.php @@ -22,9 +22,6 @@ */ final class Merger { - private ConfigPaths $paths; - private DataModifiers $dataModifiers; - /** * @psalm-var array */ @@ -34,10 +31,10 @@ final class Merger * @param ConfigPaths $configPaths The config paths instance. * @param DataModifiers $dataModifiers The data modifiers that affect merge process. */ - public function __construct(ConfigPaths $configPaths, DataModifiers $dataModifiers) - { - $this->paths = $configPaths; - $this->dataModifiers = $dataModifiers; + public function __construct( + private ConfigPaths $configPaths, + private DataModifiers $dataModifiers, + ) { } public function reset(): void @@ -80,8 +77,6 @@ public function merge(Context $context, array $arrayA, array $arrayB): array * @param string[] $recursiveKeyPath The key path for recursive merging of arrays in configuration files. * @param array $arrayA First array to merge. * @param array $arrayB Second array to merge. - * @param bool $isRecursiveMerge - * @param bool $isReverseMerge * * @throws ErrorException If an error occurred during the merge. * @@ -231,11 +226,9 @@ private function prepareArrayForReverse( } /** - * @param mixed $value - * * @psalm-param non-empty-array $keyPath */ - private function setValue(Context $context, array $keyPath, array &$array, string $key, $value): bool + private function setValue(Context $context, array $keyPath, array &$array, string $key, mixed $value): bool { if ($this->dataModifiers->shouldRemoveKeyFromVendor($context, $keyPath)) { return false; @@ -262,7 +255,7 @@ private function throwDuplicateKeyErrorException( array $absoluteFilePaths ): void { $filePaths = array_map( - fn (string $filePath) => ' - ' . $this->paths->relative($filePath), + fn (string $filePath) => ' - ' . $this->configPaths->relative($filePath), $absoluteFilePaths, ); diff --git a/src/Modifier/RecursiveMerge.php b/src/Modifier/RecursiveMerge.php index edb0a55..fa3535a 100644 --- a/src/Modifier/RecursiveMerge.php +++ b/src/Modifier/RecursiveMerge.php @@ -78,17 +78,12 @@ */ final class RecursiveMerge { - /** - * @var string[] - */ - private array $groups; - /** * @param string[] $groups */ - private function __construct(array $groups) - { - $this->groups = $groups; + private function __construct( + private array $groups, + ) { } public static function groups(string ...$groups): self diff --git a/src/Modifier/RemoveGroupsFromVendor.php b/src/Modifier/RemoveGroupsFromVendor.php index e9756e6..041c709 100644 --- a/src/Modifier/RemoveGroupsFromVendor.php +++ b/src/Modifier/RemoveGroupsFromVendor.php @@ -12,14 +12,13 @@ final class RemoveGroupsFromVendor /** * @psalm-var array */ - private array $groups; + private array $groups = []; /** * @psalm-param array $groups */ public function __construct(array $groups) { - $this->groups = []; foreach ($groups as $package => $groupNames) { $this->groups[$package] = (array) $groupNames; } diff --git a/src/Modifier/ReverseMerge.php b/src/Modifier/ReverseMerge.php index 1770998..7b1e557 100644 --- a/src/Modifier/ReverseMerge.php +++ b/src/Modifier/ReverseMerge.php @@ -68,17 +68,12 @@ */ final class ReverseMerge { - /** - * @var string[] - */ - private array $groups; - /** * @param string[] $groups */ - private function __construct(array $groups) - { - $this->groups = $groups; + private function __construct( + private array $groups, + ) { } public static function groups(string ...$groups): self diff --git a/src/Options.php b/src/Options.php index 4d5e33b..f1eeaf1 100644 --- a/src/Options.php +++ b/src/Options.php @@ -6,7 +6,6 @@ use function is_array; use function str_replace; -use function strpos; use function trim; /** @@ -48,17 +47,17 @@ public function __construct(array $extra) public static function containsWildcard(string $file): bool { - return strpos($file, '*') !== false; + return str_contains($file, '*'); } public static function isOptional(string $file): bool { - return strpos($file, '?') === 0; + return str_starts_with($file, '?'); } public static function isVariable(string $file): bool { - return strpos($file, '$') === 0; + return str_starts_with($file, '$'); } public function buildMergePlan(): bool diff --git a/tests/ConfigPathsTest.php b/tests/ConfigPathsTest.php index fece431..8b9150b 100644 --- a/tests/ConfigPathsTest.php +++ b/tests/ConfigPathsTest.php @@ -27,10 +27,6 @@ public function absolutePathsDataProvider(): array /** * @dataProvider absolutePathsDataProvider - * - * @param string $file - * @param string $package - * @param string $expected */ public function testAbsolute(string $file, string $package, string $expected): void { diff --git a/tests/OptionsTest.php b/tests/OptionsTest.php index d2b6f7d..3dbe7a3 100644 --- a/tests/OptionsTest.php +++ b/tests/OptionsTest.php @@ -22,10 +22,8 @@ public function buildMergePlanDataProvider(): array /** * @dataProvider buildMergePlanDataProvider - * - * @param mixed $value */ - public function testBuildMergePlanTrue($value): void + public function testBuildMergePlanTrue(mixed $value): void { $options = new Options([ 'config-plugin-options' => [ @@ -48,10 +46,8 @@ public function noBuildMergePlanDataProvider(): array /** * @dataProvider noBuildMergePlanDataProvider - * - * @param mixed $value */ - public function testBuildMergePlanFalse($value): void + public function testBuildMergePlanFalse(mixed $value): void { $options = new Options([ 'config-plugin-options' => [ @@ -71,10 +67,8 @@ public function packagePatternDataProvider(): array /** * @dataProvider packagePatternDataProvider - * - * @param array|string $packages */ - public function testVendorOverrideLayerPackages($packages): void + public function testVendorOverrideLayerPackages(array|string $packages): void { $options = new Options([ 'config-plugin-options' => [