diff --git a/composer.json b/composer.json index 802005fbcb..75fe999712 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "ocramius/package-versions": "^1.4", "phar-io/version": "^3.0.3", "phpstan/phpdoc-parser": "^0.4.9", - "phpstan/phpstan": "^0.12.64", + "phpstan/phpstan": "^0.12.64, <0.12.70", "phpunit/phpunit": "^9.5", "psr/simple-cache": "^1.0", "sebastian/diff": "^3.0|^4.0", @@ -65,8 +65,7 @@ "symfony/security-core": "^4.4|^5.1", "symfony/templating": "^4.4|^5.1", "symfony/translation": "^4.4|^5.1", - "symfony/twig-bundle": "^4.4|^5.1", - "tracy/tracy": "^2.8.1" + "symfony/twig-bundle": "^4.4|^5.1" }, "autoload": { "files": [ diff --git a/packages/changelog-linker/src/DependencyInjection/CompilerPass/AddRepositoryUrlAndRepositoryNameParametersCompilerPass.php b/packages/changelog-linker/src/DependencyInjection/CompilerPass/AddRepositoryUrlAndRepositoryNameParametersCompilerPass.php index 8c47b801d1..eed69b3f3f 100644 --- a/packages/changelog-linker/src/DependencyInjection/CompilerPass/AddRepositoryUrlAndRepositoryNameParametersCompilerPass.php +++ b/packages/changelog-linker/src/DependencyInjection/CompilerPass/AddRepositoryUrlAndRepositoryNameParametersCompilerPass.php @@ -48,7 +48,7 @@ private function detectRepositoryUrlFromGit(): string private function detectRepositoryName(ContainerBuilder $containerBuilder): string { - $repositoryUrl = $containerBuilder->getParameter(Option::REPOSITORY_URL); + $repositoryUrl = (string) $containerBuilder->getParameter(Option::REPOSITORY_URL); return Strings::substring($repositoryUrl, Strings::length('https://github.com/')); } diff --git a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AbstractComposerKeyMerger.php b/packages/monorepo-builder/packages/merge/src/Arrays/SortedParameterMerger.php similarity index 54% rename from packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AbstractComposerKeyMerger.php rename to packages/monorepo-builder/packages/merge/src/Arrays/SortedParameterMerger.php index c1a5111927..02d41c0d8e 100644 --- a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AbstractComposerKeyMerger.php +++ b/packages/monorepo-builder/packages/merge/src/Arrays/SortedParameterMerger.php @@ -2,30 +2,24 @@ declare(strict_types=1); -namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger; +namespace Symplify\MonorepoBuilder\Merge\Arrays; -use Symplify\MonorepoBuilder\Merge\Arrays\ArraySorter; use Symplify\PackageBuilder\Yaml\ParametersMerger; -abstract class AbstractComposerKeyMerger +final class SortedParameterMerger { /** * @var ParametersMerger */ - protected $parametersMerger; + private $parametersMerger; /** * @var ArraySorter */ - protected $arraySorter; + private $arraySorter; - /** - * @required - */ - public function autowireAbstractComposerKeyMerger( - ParametersMerger $parametersMerger, - ArraySorter $arraySorter - ): void { + public function __construct(ParametersMerger $parametersMerger, ArraySorter $arraySorter) + { $this->parametersMerger = $parametersMerger; $this->arraySorter = $arraySorter; } @@ -33,7 +27,7 @@ public function autowireAbstractComposerKeyMerger( /** * @return mixed[] */ - protected function mergeRecursiveAndSort(array $firstArray, array $secondArray): array + public function mergeRecursiveAndSort(array $firstArray, array $secondArray): array { $mergedArray = $this->parametersMerger->mergeWithCombine($firstArray, $secondArray); @@ -43,7 +37,7 @@ protected function mergeRecursiveAndSort(array $firstArray, array $secondArray): /** * @return mixed[] */ - protected function mergeAndSort(array $firstArray, array $secondArray): array + public function mergeAndSort(array $firstArray, array $secondArray): array { $mergedArray = $this->parametersMerger->merge($firstArray, $secondArray); diff --git a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AuthorComposerKeyMerger.php b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AuthorComposerKeyMerger.php index 956d197956..f251189623 100644 --- a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AuthorComposerKeyMerger.php +++ b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AuthorComposerKeyMerger.php @@ -7,7 +7,7 @@ use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson; use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface; -final class AuthorComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface +final class AuthorComposerKeyMerger implements ComposerKeyMergerInterface { public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void { diff --git a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AutoloadComposerKeyMerger.php b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AutoloadComposerKeyMerger.php index 6faa08bb9c..8624511aef 100644 --- a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AutoloadComposerKeyMerger.php +++ b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AutoloadComposerKeyMerger.php @@ -5,19 +5,28 @@ namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger; use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson; +use Symplify\MonorepoBuilder\Merge\Arrays\SortedParameterMerger; use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface; use Symplify\MonorepoBuilder\Merge\Validation\AutoloadPathValidator; -final class AutoloadComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface +final class AutoloadComposerKeyMerger implements ComposerKeyMergerInterface { /** * @var AutoloadPathValidator */ private $autoloadPathValidator; - public function __construct(AutoloadPathValidator $autoloadPathValidator) - { + /** + * @var SortedParameterMerger + */ + private $sortedParameterMerger; + + public function __construct( + AutoloadPathValidator $autoloadPathValidator, + SortedParameterMerger $sortedParameterMerger + ) { $this->autoloadPathValidator = $autoloadPathValidator; + $this->sortedParameterMerger = $sortedParameterMerger; } public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void @@ -28,7 +37,10 @@ public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJ $this->autoloadPathValidator->ensureAutoloadPathExists($newComposerJson); - $autoload = $this->mergeRecursiveAndSort($mainComposerJson->getAutoload(), $newComposerJson->getAutoload()); + $autoload = $this->sortedParameterMerger->mergeRecursiveAndSort( + $mainComposerJson->getAutoload(), + $newComposerJson->getAutoload() + ); $mainComposerJson->setAutoload($autoload); } } diff --git a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AutoloadDevComposerKeyMerger.php b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AutoloadDevComposerKeyMerger.php index db4f3ae147..f699417232 100644 --- a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AutoloadDevComposerKeyMerger.php +++ b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/AutoloadDevComposerKeyMerger.php @@ -5,19 +5,28 @@ namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger; use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson; +use Symplify\MonorepoBuilder\Merge\Arrays\SortedParameterMerger; use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface; use Symplify\MonorepoBuilder\Merge\Validation\AutoloadPathValidator; -final class AutoloadDevComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface +final class AutoloadDevComposerKeyMerger implements ComposerKeyMergerInterface { /** * @var AutoloadPathValidator */ private $autoloadPathValidator; - public function __construct(AutoloadPathValidator $autoloadPathValidator) - { + /** + * @var SortedParameterMerger + */ + private $sortedParameterMerger; + + public function __construct( + AutoloadPathValidator $autoloadPathValidator, + SortedParameterMerger $sortedParameterMerger + ) { $this->autoloadPathValidator = $autoloadPathValidator; + $this->sortedParameterMerger = $sortedParameterMerger; } public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void @@ -28,7 +37,7 @@ public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJ $this->autoloadPathValidator->ensureAutoloadPathExists($newComposerJson); - $autoloadDev = $this->mergeRecursiveAndSort( + $autoloadDev = $this->sortedParameterMerger->mergeRecursiveAndSort( $mainComposerJson->getAutoloadDev(), $newComposerJson->getAutoloadDev() ); diff --git a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/ExtraComposerKeyMerger.php b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/ExtraComposerKeyMerger.php index e8925536d6..0302d97f8a 100644 --- a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/ExtraComposerKeyMerger.php +++ b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/ExtraComposerKeyMerger.php @@ -6,14 +6,25 @@ use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson; use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface; +use Symplify\PackageBuilder\Yaml\ParametersMerger; -final class ExtraComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface +final class ExtraComposerKeyMerger implements ComposerKeyMergerInterface { /** * @var string */ private const PHPSTAN = 'phpstan'; + /** + * @var ParametersMerger + */ + private $parametersMerger; + + public function __construct(ParametersMerger $parametersMerger) + { + $this->parametersMerger = $parametersMerger; + } + public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void { if ($newComposerJson->getExtra() === []) { diff --git a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/MinimalStabilityKeyMerger.php b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/MinimalStabilityKeyMerger.php index 90e2b2364f..914169b978 100644 --- a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/MinimalStabilityKeyMerger.php +++ b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/MinimalStabilityKeyMerger.php @@ -7,7 +7,7 @@ use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson; use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface; -final class MinimalStabilityKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface +final class MinimalStabilityKeyMerger implements ComposerKeyMergerInterface { public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void { diff --git a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/PreferStableKeyMerger.php b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/PreferStableKeyMerger.php index 332d07d91f..c4be02ff2e 100644 --- a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/PreferStableKeyMerger.php +++ b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/PreferStableKeyMerger.php @@ -7,7 +7,7 @@ use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson; use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface; -final class PreferStableKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface +final class PreferStableKeyMerger implements ComposerKeyMergerInterface { public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void { diff --git a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RepositoriesComposerKeyMerger.php b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RepositoriesComposerKeyMerger.php index 220d445131..99403d90fb 100644 --- a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RepositoriesComposerKeyMerger.php +++ b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RepositoriesComposerKeyMerger.php @@ -5,17 +5,28 @@ namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger; use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson; +use Symplify\MonorepoBuilder\Merge\Arrays\SortedParameterMerger; use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface; -final class RepositoriesComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface +final class RepositoriesComposerKeyMerger implements ComposerKeyMergerInterface { + /** + * @var SortedParameterMerger + */ + private $sortedParameterMerger; + + public function __construct(SortedParameterMerger $sortedParameterMerger) + { + $this->sortedParameterMerger = $sortedParameterMerger; + } + public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void { if ($newComposerJson->getRepositories() === []) { return; } - $repositories = $this->mergeRecursiveAndSort( + $repositories = $this->sortedParameterMerger->mergeRecursiveAndSort( $mainComposerJson->getRepositories(), $newComposerJson->getRepositories() ); diff --git a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RequireComposerKeyMerger.php b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RequireComposerKeyMerger.php index ac32a8af95..e8c639ed92 100644 --- a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RequireComposerKeyMerger.php +++ b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RequireComposerKeyMerger.php @@ -5,17 +5,31 @@ namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger; use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson; +use Symplify\MonorepoBuilder\Merge\Arrays\SortedParameterMerger; use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface; -final class RequireComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface +final class RequireComposerKeyMerger implements ComposerKeyMergerInterface { + /** + * @var SortedParameterMerger + */ + private $sortedParameterMerger; + + public function __construct(SortedParameterMerger $sortedParameterMerger) + { + $this->sortedParameterMerger = $sortedParameterMerger; + } + public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void { if ($newComposerJson->getRequire() === []) { return; } - $require = $this->mergeAndSort($newComposerJson->getRequire(), $mainComposerJson->getRequire()); + $require = $this->sortedParameterMerger->mergeAndSort( + $newComposerJson->getRequire(), + $mainComposerJson->getRequire() + ); $mainComposerJson->setRequire($require); } } diff --git a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RequireDevComposerKeyMerger.php b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RequireDevComposerKeyMerger.php index 74f2ea6913..97c5940ab2 100644 --- a/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RequireDevComposerKeyMerger.php +++ b/packages/monorepo-builder/packages/merge/src/ComposerKeyMerger/RequireDevComposerKeyMerger.php @@ -5,17 +5,31 @@ namespace Symplify\MonorepoBuilder\Merge\ComposerKeyMerger; use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson; +use Symplify\MonorepoBuilder\Merge\Arrays\SortedParameterMerger; use Symplify\MonorepoBuilder\Merge\Contract\ComposerKeyMergerInterface; -final class RequireDevComposerKeyMerger extends AbstractComposerKeyMerger implements ComposerKeyMergerInterface +final class RequireDevComposerKeyMerger implements ComposerKeyMergerInterface { + /** + * @var SortedParameterMerger + */ + private $sortedParameterMerger; + + public function __construct(SortedParameterMerger $sortedParameterMerger) + { + $this->sortedParameterMerger = $sortedParameterMerger; + } + public function merge(ComposerJson $mainComposerJson, ComposerJson $newComposerJson): void { if ($newComposerJson->getRequireDev() === []) { return; } - $requireDev = $this->mergeAndSort($newComposerJson->getRequireDev(), $mainComposerJson->getRequireDev()); + $requireDev = $this->sortedParameterMerger->mergeAndSort( + $newComposerJson->getRequireDev(), + $mainComposerJson->getRequireDev() + ); $mainComposerJson->setRequireDev($requireDev); } } diff --git a/packages/neon-to-yaml-converter/src/NeonToYamlConverter.php b/packages/neon-to-yaml-converter/src/NeonToYamlConverter.php index 93b8f62e96..f1a81ed311 100644 --- a/packages/neon-to-yaml-converter/src/NeonToYamlConverter.php +++ b/packages/neon-to-yaml-converter/src/NeonToYamlConverter.php @@ -80,6 +80,12 @@ final class NeonToYamlConverter */ private const ENV_GET_REGEX = "#\@env::get\(\'?(.*?)\'?(,.*?)?\)#ms"; + /** + * @see https://regex101.com/r/SnyASO/1 + * @var string + */ + private const RANDOM_DASH_LEFTOVER_REGEX = '#: \|\-#'; + /** * @var ArrayParameterCollector */ @@ -149,6 +155,9 @@ public function convertFileInfo(SmartFileInfo $fileInfo): string $content = $this->yamlOutputFormatter->format($content); + // clear |- + $content = Strings::replace($content, self::RANDOM_DASH_LEFTOVER_REGEX, ': |'); + return $this->replaceOldToNewParameters($content); } diff --git a/packages/phpstan-rules/src/ParentClassMethodNodeResolver.php b/packages/phpstan-rules/src/ParentClassMethodNodeResolver.php index 72f0ebdb5e..5056faa4bd 100644 --- a/packages/phpstan-rules/src/ParentClassMethodNodeResolver.php +++ b/packages/phpstan-rules/src/ParentClassMethodNodeResolver.php @@ -13,6 +13,7 @@ use PhpParser\Parser; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; +use ReflectionMethod; use Symplify\SmartFileSystem\SmartFileSystem; use Throwable; @@ -48,7 +49,12 @@ public function resolveParentClassMethodNodes(Scope $scope, string $methodName): /** @var ClassReflection[] $parentClassReflections */ $parentClassReflections = $this->getParentClassReflections($scope); foreach ($parentClassReflections as $parentClassReflection) { - $fileName = $parentClassReflection->getFileName(); + if (! $parentClassReflection->hasMethod($methodName)) { + continue; + } + + $parentMethodReflection = new ReflectionMethod($parentClassReflection->getName(), $methodName); + $fileName = $parentMethodReflection->getFileName(); if ($fileName === false) { continue; } diff --git a/packages/phpstan-rules/src/Rules/NoDynamicPropertyOnStaticCallRule.php b/packages/phpstan-rules/src/Rules/NoDynamicPropertyOnStaticCallRule.php index 9d394a6dbc..003614eaf0 100644 --- a/packages/phpstan-rules/src/Rules/NoDynamicPropertyOnStaticCallRule.php +++ b/packages/phpstan-rules/src/Rules/NoDynamicPropertyOnStaticCallRule.php @@ -5,9 +5,9 @@ namespace Symplify\PHPStanRules\Rules; use PhpParser\Node; -use PhpParser\Node\Name; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\StaticCall; +use PhpParser\Node\Name; use PHPStan\Analyser\Scope; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/packages/symfony-route-usage/tests/Helper/DatabaseLoaderHelper.php b/packages/symfony-route-usage/tests/Helper/DatabaseLoaderHelper.php index 0d6055bb80..8b2e3c0f5e 100644 --- a/packages/symfony-route-usage/tests/Helper/DatabaseLoaderHelper.php +++ b/packages/symfony-route-usage/tests/Helper/DatabaseLoaderHelper.php @@ -31,7 +31,7 @@ public function createDatabase(): void { /** @var Connection $connection */ $connection = $this->container->get('doctrine.dbal.default_connection'); - $databaseName = $this->container->getParameter('database_name'); + $databaseName = (string) $this->container->getParameter('database_name'); /** @var AbstractSchemaManager $schemaManager */ $schemaManager = $connection->getSchemaManager(); diff --git a/phpstan.neon b/phpstan.neon index a85f3dfad3..de57364a31 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,4 @@ includes: - - vendor/phpstan/phpstan/conf/bleedingEdge.neon - packages/phpstan-extensions/config/config.neon - packages/phpstan-rules/config/symplify-rules.neon # for cognitive rules @@ -425,3 +424,11 @@ parameters: path: packages/coding-standard/src/Php/PhpContentAnalyzer.php - '#Content of method "create\(\)" is duplicated with method "create\(\)" in "Symplify\\MarkdownDiff\\Diff\\Output\\CompleteUnifiedDiffOutputBuilderFactory" class\. Use unique content or abstract service instead#' + - '#Content of method "create\(\)" is duplicated with method "create\(\)" in "Symplify\\ConsoleColorDiff\\Diff\\Output\\CompleteUnifiedDiffOutputBuilderFactory" class\. Use unique content or abstract service instead#' + + # parameters in tests + - + message: '#Cannot cast array\|bool\|float\|int\|string\|null to string#' + paths: + - packages/changelog-linker/src/DependencyInjection/CompilerPass/AddRepositoryUrlAndRepositoryNameParametersCompilerPass.php + - packages/symfony-route-usage/tests/Helper/DatabaseLoaderHelper.php