From 7bf666ff4eeaa08a28670540f35c0ee12123a5e3 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 2 Oct 2020 21:23:54 +0200 Subject: [PATCH 01/25] bump pslam version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 65280ffc..ad07ae8e 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "mikey179/vfsstream": "^1.6.8", "phpstan/phpstan": "^0.12.54", "phpunit/phpunit": "^9.4.3", - "vimeo/psalm": "^3.12.2" + "vimeo/psalm": "^3.16.0" }, "config": { "optimize-autoloader": true, From 0bdb4de8ca26ff2fdefcf41f40a9a8dee64dcb2e Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 2 Oct 2020 21:24:21 +0200 Subject: [PATCH 02/25] increase level from 4 to 3 --- psalm.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index d5025223..222cb9b1 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,6 @@ Date: Fri, 2 Oct 2020 21:24:35 +0200 Subject: [PATCH 03/25] fix level 3 issues --- .../Cli/Application.php | 2 +- .../Cli/CheckCommand.php | 33 ++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/ComposerRequireChecker/Cli/Application.php b/src/ComposerRequireChecker/Cli/Application.php index 7fb8b443..fc3d43b6 100644 --- a/src/ComposerRequireChecker/Cli/Application.php +++ b/src/ComposerRequireChecker/Cli/Application.php @@ -18,6 +18,6 @@ public function __construct() $check = new CheckCommand(); $this->add($check); - $this->setDefaultCommand($check->getName()); + $this->setDefaultCommand(CheckCommand::NAME); } } diff --git a/src/ComposerRequireChecker/Cli/CheckCommand.php b/src/ComposerRequireChecker/Cli/CheckCommand.php index 7f44d27d..fe8ceb21 100644 --- a/src/ComposerRequireChecker/Cli/CheckCommand.php +++ b/src/ComposerRequireChecker/Cli/CheckCommand.php @@ -34,15 +34,20 @@ use function array_merge; use function count; use function dirname; +use function gettype; use function implode; +use function is_string; use function realpath; +use function sprintf; class CheckCommand extends Command { + public const NAME = 'check'; + protected function configure(): void { $this - ->setName('check') + ->setName(self::NAME) ->setDescription('check the defined dependencies against your code') ->addOption( 'config-file', @@ -68,12 +73,23 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { if (! $output->isQuiet()) { - $output->writeln($this->getApplication()->getLongVersion()); + $application = $this->getApplication(); + $output->writeln($application !== null ? $application->getLongVersion() : 'Unknown version'); + } + + $composerJsonArgument = $input->getArgument('composer-json'); + + if (is_string($composerJsonArgument) === false) { + throw new InvalidArgumentException(sprintf( + 'composer-json must be type of string but %s given', + gettype($composerJsonArgument) + )); } - $composerJson = realpath($input->getArgument('composer-json')); + $composerJson = realpath($composerJsonArgument); + if ($composerJson === false) { - throw new InvalidArgumentException('file not found: [' . $input->getArgument('composer-json') . ']'); + throw new InvalidArgumentException(sprintf('file not found: [%s]', $composerJsonArgument)); } $composerData = $this->getComposerData($composerJson); @@ -154,10 +170,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int return (int) (bool) $unknownSymbols; } + /** + * @return array + * + * @throws InvalidJson + * @throws NotReadable + */ private function getCheckOptions(InputInterface $input): Options { $fileName = $input->getOption('config-file'); - if (! $fileName) { + + if (is_string($fileName) === false) { return new Options(); } From 12cf63f183d3ddb44ec45dd5c3437355376633e9 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 2 Oct 2020 22:28:46 +0200 Subject: [PATCH 04/25] increase level from 3 to 2 --- psalm.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index 222cb9b1..8e1e03f6 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,6 @@ Date: Fri, 2 Oct 2020 22:29:04 +0200 Subject: [PATCH 05/25] fix level 2 issues --- src/ComposerRequireChecker/Cli/Options.php | 5 ----- .../FileLocator/LocateComposerPackageSourceFiles.php | 5 ++++- .../NodeVisitor/DefinedSymbolCollector.php | 5 +---- .../NodeVisitor/UsedSymbolCollector.php | 6 ------ 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/ComposerRequireChecker/Cli/Options.php b/src/ComposerRequireChecker/Cli/Options.php index 91b2425c..46e75f6d 100644 --- a/src/ComposerRequireChecker/Cli/Options.php +++ b/src/ComposerRequireChecker/Cli/Options.php @@ -115,11 +115,6 @@ public function setScanFiles(array $scanFiles): void $this->scanFiles = $scanFiles; } - /** - * @param string $string some-string - * - * @return string someString - */ private function getCamelCase(string $string): string { return ucfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $string)))); diff --git a/src/ComposerRequireChecker/FileLocator/LocateComposerPackageSourceFiles.php b/src/ComposerRequireChecker/FileLocator/LocateComposerPackageSourceFiles.php index 7f8628e0..af1a19a8 100644 --- a/src/ComposerRequireChecker/FileLocator/LocateComposerPackageSourceFiles.php +++ b/src/ComposerRequireChecker/FileLocator/LocateComposerPackageSourceFiles.php @@ -56,7 +56,10 @@ private function getFilePaths(array $sourceDirs, string $packageDir): array { $flattened = array_reduce( $sourceDirs, - static function (array $sourceDirs, $sourceDir) { + /** + * @param array|string $sourceDir + */ + static function (array $sourceDirs, $sourceDir): array { return array_merge($sourceDirs, (array) $sourceDir); }, [] diff --git a/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php b/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php index c97a9eff..3cf3c661 100644 --- a/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php +++ b/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php @@ -39,10 +39,7 @@ public function getDefinedSymbols(): array return array_keys($this->definedSymbols); } - /** - * {@inheritDoc} - */ - public function enterNode(Node $node) + public function enterNode(Node $node): Node { $this->recordClassDefinition($node); $this->recordInterfaceDefinition($node); diff --git a/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php b/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php index cafaeab0..8c994154 100644 --- a/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php +++ b/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php @@ -140,12 +140,6 @@ private function recordFunctionParameterTypesUsage(Node $node): void if ($param->type instanceof Node\Identifier) { $this->recordUsageOfByString($param->type->toString()); } - - if (! is_string($param->type)) { - continue; - } - - $this->recordUsageOfByString($param->type); } } From f88ec3081c83f5417843a0dd00d0350c55c47250 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 2 Oct 2020 22:30:10 +0200 Subject: [PATCH 06/25] remove tests due to usgae with wrong types, upstream phpdoc disallows Param::type to be string --- .../NodeVisitor/UsedSymbolCollector.php | 7 ++-- .../NodeVisitor/UsedSymbolCollectorTest.php | 32 ------------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php b/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php index 8c994154..5815f8ab 100644 --- a/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php +++ b/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php @@ -10,7 +10,6 @@ use function array_filter; use function array_keys; use function array_map; -use function is_string; final class UsedSymbolCollector extends NodeVisitorAbstract { @@ -137,9 +136,11 @@ private function recordFunctionParameterTypesUsage(Node $node): void $this->recordUsageOf($param->type); } - if ($param->type instanceof Node\Identifier) { - $this->recordUsageOfByString($param->type->toString()); + if (! ($param->type instanceof Node\Identifier)) { + continue; } + + $this->recordUsageOfByString($param->type->toString()); } } diff --git a/test/ComposerRequireCheckerTest/NodeVisitor/UsedSymbolCollectorTest.php b/test/ComposerRequireCheckerTest/NodeVisitor/UsedSymbolCollectorTest.php index d3de09fc..18e45241 100644 --- a/test/ComposerRequireCheckerTest/NodeVisitor/UsedSymbolCollectorTest.php +++ b/test/ComposerRequireCheckerTest/NodeVisitor/UsedSymbolCollectorTest.php @@ -183,22 +183,6 @@ public function testFunctionParameterType(): void $this->assertContains('Baz', $symbols); } - public function testFunctionParameterTypeAsString(): void - { - $functionName = new Name('foo'); - $node = new Function_($functionName); - $node->name = $functionName; - $param = new Param(new Variable('bar')); - $param->type = 'Baz'; - $node->params = [$param]; - - $this->visitor->enterNode($node); - - $symbols = $this->visitor->getCollectedSymbols(); - $this->assertCount(1, $symbols); - $this->assertContains('Baz', $symbols); - } - public function testMethodParameterType(): void { $functionName = new Name('foo'); @@ -215,22 +199,6 @@ public function testMethodParameterType(): void $this->assertContains('Baz', $symbols); } - public function testMethodParameterTypeAsString(): void - { - $functionName = new Name('foo'); - $node = new ClassMethod($functionName); - $node->name = $functionName; - $param = new Param(new Variable('bar')); - $param->type = 'Baz'; - $node->params = [$param]; - - $this->visitor->enterNode($node); - - $symbols = $this->visitor->getCollectedSymbols(); - $this->assertCount(1, $symbols); - $this->assertContains('Baz', $symbols); - } - public function testFunctionReturnType(): void { $functionName = new Name('foo'); From a39ce2b0f80c9e2949d276a19bb0b3d72ad49ce5 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 2 Oct 2020 22:30:48 +0200 Subject: [PATCH 07/25] add baseline for package version deprecation, cannot bump to composer v2 yet --- baseline.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/baseline.xml b/baseline.xml index 9e572e4c..a39a42a1 100644 --- a/baseline.xml +++ b/baseline.xml @@ -1,8 +1,2 @@ - - - - $node->namespacedName - - - + From 5331a3ab958b043c3efbd30657c886910cebe08a Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 2 Oct 2020 22:34:16 +0200 Subject: [PATCH 08/25] add testcase for new path in check command if argument is not string --- test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php b/test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php index 1e300471..6fe6b10b 100644 --- a/test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php +++ b/test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php @@ -32,6 +32,15 @@ protected function setUp(): void $this->commandTester = new CommandTester($command); } + public function testExceptionIfComposerJsonIsNotAString(): void + { + self::expectException(\InvalidArgumentException::class); + + $this->commandTester->execute([ + 'composer-json' => ['this-is-a-array-as-input'] + ]); + } + public function testExceptionIfComposerJsonNotFound(): void { self::expectException(InvalidArgumentException::class); From 1b30d1ab0702c39579ddd4c1004bff0f41674ede Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 2 Oct 2020 22:34:45 +0200 Subject: [PATCH 09/25] increase level from 2 to 1 --- psalm.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index 8e1e03f6..59b65732 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,6 @@ Date: Fri, 2 Oct 2020 22:45:56 +0200 Subject: [PATCH 10/25] fix baseline --- baseline.xml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/baseline.xml b/baseline.xml index a39a42a1..a6b7de35 100644 --- a/baseline.xml +++ b/baseline.xml @@ -1,2 +1,13 @@ - + + + + Versions::getVersion('maglnet/composer-require-checker') + + + + + $node->namespacedName + + + From 323d1222ebc8ad3e5c48049dfec4d79931e14034 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 2 Oct 2020 22:46:39 +0200 Subject: [PATCH 11/25] add space --- test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php b/test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php index 6fe6b10b..b40bd6fc 100644 --- a/test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php +++ b/test/ComposerRequireCheckerTest/Cli/CheckCommandTest.php @@ -34,10 +34,10 @@ protected function setUp(): void public function testExceptionIfComposerJsonIsNotAString(): void { - self::expectException(\InvalidArgumentException::class); + self::expectException(InvalidArgumentException::class); $this->commandTester->execute([ - 'composer-json' => ['this-is-a-array-as-input'] + 'composer-json' => ['this-is-a-array-as-input'], ]); } From 591b001dd8fa00f7d26951e6f7ce53e8716ebbff Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Sat, 3 Oct 2020 00:07:06 +0200 Subject: [PATCH 12/25] add alot of array types --- .../DefinedExtensionsResolver.php | 13 ++++++++++--- .../DependencyGuesser/DependencyGuesser.php | 3 +++ .../GuessFromLoadedExtensions.php | 3 +++ .../DependencyGuesser/Guesser.php | 3 +++ ...mposerPackageDirectDependenciesSourceFiles.php | 15 ++++++++++++++- .../LocateComposerPackageSourceFiles.php | 1 + src/ComposerRequireChecker/JsonLoader.php | 2 +- .../NodeVisitor/DefinedSymbolCollector.php | 4 ++-- .../NodeVisitor/UsedSymbolCollector.php | 4 ++-- 9 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/ComposerRequireChecker/DefinedExtensionsResolver/DefinedExtensionsResolver.php b/src/ComposerRequireChecker/DefinedExtensionsResolver/DefinedExtensionsResolver.php index 920b01b3..e76dd36f 100644 --- a/src/ComposerRequireChecker/DefinedExtensionsResolver/DefinedExtensionsResolver.php +++ b/src/ComposerRequireChecker/DefinedExtensionsResolver/DefinedExtensionsResolver.php @@ -19,12 +19,15 @@ class DefinedExtensionsResolver */ public function __invoke(string $composerJson, array $phpCoreExtensions = []): array { + /** @var array $requires */ $requires = json_decode(file_get_contents($composerJson), true)['require'] ?? []; - $extensions = []; + $extensions = []; + $addPhpCoreExtensions = false; + foreach ($requires as $require => $version) { if ($require === 'php' || $require === 'php-64bit') { - $extensions = array_merge($extensions, $phpCoreExtensions); + $addPhpCoreExtensions = true; continue; } @@ -32,7 +35,11 @@ public function __invoke(string $composerJson, array $phpCoreExtensions = []): a continue; } - $extensions = array_merge($extensions, [substr($require, 4)]); + $extensions[] = substr($require, 4); + } + + if ($addPhpCoreExtensions) { + $extensions = array_merge($extensions, $phpCoreExtensions); } return $extensions; diff --git a/src/ComposerRequireChecker/DependencyGuesser/DependencyGuesser.php b/src/ComposerRequireChecker/DependencyGuesser/DependencyGuesser.php index dc89a7c0..a083a411 100644 --- a/src/ComposerRequireChecker/DependencyGuesser/DependencyGuesser.php +++ b/src/ComposerRequireChecker/DependencyGuesser/DependencyGuesser.php @@ -17,6 +17,9 @@ public function __construct(?Options $options = null) $this->guessers[] = new GuessFromLoadedExtensions($options); } + /** + * @return Generator + */ public function __invoke(string $symbolName): Generator { foreach ($this->guessers as $guesser) { diff --git a/src/ComposerRequireChecker/DependencyGuesser/GuessFromLoadedExtensions.php b/src/ComposerRequireChecker/DependencyGuesser/GuessFromLoadedExtensions.php index d23f0f86..25236e01 100644 --- a/src/ComposerRequireChecker/DependencyGuesser/GuessFromLoadedExtensions.php +++ b/src/ComposerRequireChecker/DependencyGuesser/GuessFromLoadedExtensions.php @@ -29,6 +29,9 @@ public function __construct(?Options $options = null) $this->coreExtensions = $options->getPhpCoreExtensions(); } + /** + * @return Generator + */ public function __invoke(string $symbolName): Generator { $definedSymbolsFromExtensions = new LocateDefinedSymbolsFromExtensions(); diff --git a/src/ComposerRequireChecker/DependencyGuesser/Guesser.php b/src/ComposerRequireChecker/DependencyGuesser/Guesser.php index 3de4a955..5011ede5 100644 --- a/src/ComposerRequireChecker/DependencyGuesser/Guesser.php +++ b/src/ComposerRequireChecker/DependencyGuesser/Guesser.php @@ -8,5 +8,8 @@ interface Guesser { + /** + * @return Generator + */ public function __invoke(string $symbolName): Generator; } diff --git a/src/ComposerRequireChecker/FileLocator/LocateComposerPackageDirectDependenciesSourceFiles.php b/src/ComposerRequireChecker/FileLocator/LocateComposerPackageDirectDependenciesSourceFiles.php index 4f91e778..45a55492 100644 --- a/src/ComposerRequireChecker/FileLocator/LocateComposerPackageDirectDependenciesSourceFiles.php +++ b/src/ComposerRequireChecker/FileLocator/LocateComposerPackageDirectDependenciesSourceFiles.php @@ -10,8 +10,10 @@ use Generator; use function array_key_exists; +use function assert; use function dirname; use function file_get_contents; +use function is_string; use function json_decode; final class LocateComposerPackageDirectDependenciesSourceFiles @@ -22,8 +24,14 @@ public function __invoke(string $composerJsonPath): Generator $composerJson = json_decode(file_get_contents($composerJsonPath), true); $configVendorDir = $composerJson['config']['vendor-dir'] ?? 'vendor'; - $vendorDirs = []; + assert(is_string($configVendorDir)); + $vendorDirs = []; + + /** + * @var mixed $vendorRequiredVersion + */ foreach ($composerJson['require'] ?? [] as $vendorName => $vendorRequiredVersion) { + assert(is_string($vendorName)); $vendorDirs[$vendorName] = $packageDir . '/' . $configVendorDir . '/' . $vendorName; } @@ -57,7 +65,12 @@ private function getInstalledPackages(string $vendorDir): array $installedPackages = []; + /** @var array $packages */ $packages = $installedData['packages'] ?? $installedData; + + /** + * @var array{name: string} $vendorJson + */ foreach ($packages as $vendorJson) { $vendorName = $vendorJson['name']; $installedPackages[$vendorName] = $vendorJson; diff --git a/src/ComposerRequireChecker/FileLocator/LocateComposerPackageSourceFiles.php b/src/ComposerRequireChecker/FileLocator/LocateComposerPackageSourceFiles.php index af1a19a8..1bca76fc 100644 --- a/src/ComposerRequireChecker/FileLocator/LocateComposerPackageSourceFiles.php +++ b/src/ComposerRequireChecker/FileLocator/LocateComposerPackageSourceFiles.php @@ -24,6 +24,7 @@ final class LocateComposerPackageSourceFiles */ public function __invoke(array $composerData, string $packageDir): Generator { + /** @var array|null $blacklist */ $blacklist = $composerData['autoload']['exclude-from-classmap'] ?? null; yield from $this->locateFilesInClassmapDefinitions( diff --git a/src/ComposerRequireChecker/JsonLoader.php b/src/ComposerRequireChecker/JsonLoader.php index 13c9c95d..fe3499b6 100644 --- a/src/ComposerRequireChecker/JsonLoader.php +++ b/src/ComposerRequireChecker/JsonLoader.php @@ -20,7 +20,7 @@ class JsonLoader { /** - * @return array + * @return array * * @throws InvalidJson * @throws NotReadable diff --git a/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php b/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php index 3cf3c661..d22f648e 100644 --- a/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php +++ b/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php @@ -14,7 +14,7 @@ final class DefinedSymbolCollector extends NodeVisitorAbstract { - /** @var mixed[] */ + /** @var array */ private array $definedSymbols = []; public function __construct() @@ -32,7 +32,7 @@ public function beforeTraverse(array $nodes) } /** - * @return string[] + * @return array */ public function getDefinedSymbols(): array { diff --git a/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php b/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php index 5815f8ab..1214facb 100644 --- a/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php +++ b/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php @@ -13,7 +13,7 @@ final class UsedSymbolCollector extends NodeVisitorAbstract { - /** @var mixed[] */ + /** @var array */ private array $collectedSymbols = []; public function __construct() @@ -21,7 +21,7 @@ public function __construct() } /** - * @return string[] + * @return array */ public function getCollectedSymbols(): array { From 06aac4e684b4fa57c16be7c09d5c9bc59a5d8f54 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Sat, 3 Oct 2020 15:35:19 +0200 Subject: [PATCH 13/25] update baseline with some level 1 errors --- baseline.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/baseline.xml b/baseline.xml index a6b7de35..d4d81e5d 100644 --- a/baseline.xml +++ b/baseline.xml @@ -5,6 +5,23 @@ Versions::getVersion('maglnet/composer-require-checker') + + + + + + $composerData['autoload']['classmap'] ?? [] + $composerData['autoload']['files'] ?? [] + $composerData['autoload']['psr-0'] ?? [] + $composerData['autoload']['psr-4'] ?? [] + + + $this->getFilePaths($composerData['autoload']['classmap'] ?? [], $packageDir) + $this->getFilePaths($composerData['autoload']['files'] ?? [], $packageDir) + $this->getFilePaths($composerData['autoload']['psr-0'] ?? [], $packageDir) + $this->getFilePaths($composerData['autoload']['psr-4'] ?? [], $packageDir) + + $node->namespacedName From e39219c2509108e3e4fa223ee8e35671a9885ef8 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Sat, 3 Oct 2020 16:06:51 +0200 Subject: [PATCH 14/25] remove a superflous return, add a test for JsonLoader --- test/ComposerRequireCheckerTest/JsonLoaderTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/ComposerRequireCheckerTest/JsonLoaderTest.php b/test/ComposerRequireCheckerTest/JsonLoaderTest.php index 76d6afc1..0d16fcb9 100644 --- a/test/ComposerRequireCheckerTest/JsonLoaderTest.php +++ b/test/ComposerRequireCheckerTest/JsonLoaderTest.php @@ -28,6 +28,13 @@ public function testHasErrorWithInvalidFile(): void JsonLoader::getData($path); } + public function testHasDataWithValidFileButNoArrayConteent(): void + { + $path = __DIR__ . '/../fixtures/validJsonNotAnArray.json'; + $this->expectException(InvalidJsonException::class); + new JsonLoader($path); + } + public function testHasDataWithValidFile(): void { $path = __DIR__ . '/../fixtures/validJson.json'; From eed6c018c9ef221309a579a9848951cf478d5a68 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Sat, 3 Oct 2020 16:13:46 +0200 Subject: [PATCH 15/25] fix typos --- test/ComposerRequireCheckerTest/JsonLoaderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ComposerRequireCheckerTest/JsonLoaderTest.php b/test/ComposerRequireCheckerTest/JsonLoaderTest.php index 0d16fcb9..65e4b1a4 100644 --- a/test/ComposerRequireCheckerTest/JsonLoaderTest.php +++ b/test/ComposerRequireCheckerTest/JsonLoaderTest.php @@ -28,7 +28,7 @@ public function testHasErrorWithInvalidFile(): void JsonLoader::getData($path); } - public function testHasDataWithValidFileButNoArrayConteent(): void + public function testHasDataWithValidFileButNoArrayContent(): void { $path = __DIR__ . '/../fixtures/validJsonNotAnArray.json'; $this->expectException(InvalidJsonException::class); From 5626e77eeff95895e7f8018ddc9608c031dc4289 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Sat, 3 Oct 2020 16:17:58 +0200 Subject: [PATCH 16/25] add missing test file --- test/fixtures/validJsonNotAnArray.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/fixtures/validJsonNotAnArray.json diff --git a/test/fixtures/validJsonNotAnArray.json b/test/fixtures/validJsonNotAnArray.json new file mode 100644 index 00000000..7deb8b17 --- /dev/null +++ b/test/fixtures/validJsonNotAnArray.json @@ -0,0 +1 @@ +"just a string" From 9c455716cad715e18d180cf5e6fea4c292310d0e Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Sun, 4 Oct 2020 14:37:09 +0200 Subject: [PATCH 17/25] update psalm to ^3.16.0 in lock --- composer.json | 2 +- composer.lock | 484 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 394 insertions(+), 92 deletions(-) diff --git a/composer.json b/composer.json index ad07ae8e..fc901817 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "mikey179/vfsstream": "^1.6.8", "phpstan/phpstan": "^0.12.54", "phpunit/phpunit": "^9.4.3", - "vimeo/psalm": "^3.16.0" + "vimeo/psalm": "^3.18.2" }, "config": { "optimize-autoloader": true, diff --git a/composer.lock b/composer.lock index 79705c04..ed929488 100644 --- a/composer.lock +++ b/composer.lock @@ -4,120 +4,136 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e98c3377cf6168b3859b7ae1d0f323a2", + "content-hash": "126284961d8fde69b5f5787ea2c81d62", "packages": [ { - "name": "nikic/php-parser", - "version": "v4.10.2", + "name": "composer/package-versions-deprecated", + "version": "1.11.99", "source": { "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "658f1be311a230e0907f5dfe0213742aff0596de" + "url": "https://github.com/composer/package-versions-deprecated.git", + "reference": "c8c9aa8a14cc3d3bec86d0a8c3fa52ea79936855" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/658f1be311a230e0907f5dfe0213742aff0596de", - "reference": "658f1be311a230e0907f5dfe0213742aff0596de", + "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/c8c9aa8a14cc3d3bec86d0a8c3fa52ea79936855", + "reference": "c8c9aa8a14cc3d3bec86d0a8c3fa52ea79936855", "shasum": "" }, "require": { - "ext-tokenizer": "*", - "php": ">=7.0" + "composer-plugin-api": "^1.1.0 || ^2.0", + "php": "^7 || ^8" + }, + "replace": { + "ocramius/package-versions": "1.11.99" }, "require-dev": { - "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "composer/composer": "^1.9.3 || ^2.0@dev", + "ext-zip": "^1.13", + "phpunit/phpunit": "^6.5 || ^7" }, - "bin": [ - "bin/php-parse" - ], - "type": "library", + "type": "composer-plugin", "extra": { + "class": "PackageVersions\\Installer", "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "1.x-dev" } }, "autoload": { "psr-4": { - "PhpParser\\": "lib/PhpParser" + "PackageVersions\\": "src/PackageVersions" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Nikita Popov" + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be" } ], - "description": "A PHP parser written in PHP", - "keywords": [ - "parser", - "php" + "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", + "support": { + "issues": "https://github.com/composer/package-versions-deprecated/issues", + "source": "https://github.com/composer/package-versions-deprecated/tree/master" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } ], - "time": "2020-09-26T10:30:38+00:00" + "time": "2020-08-25T05:50:16+00:00" }, { - "name": "ocramius/package-versions", - "version": "1.9.0", + "name": "nikic/php-parser", + "version": "v4.10.2", "source": { "type": "git", - "url": "https://github.com/Ocramius/PackageVersions.git", - "reference": "94c9d42a466c57f91390cdd49c81313264f49d85" + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "658f1be311a230e0907f5dfe0213742aff0596de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/94c9d42a466c57f91390cdd49c81313264f49d85", - "reference": "94c9d42a466c57f91390cdd49c81313264f49d85", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/658f1be311a230e0907f5dfe0213742aff0596de", + "reference": "658f1be311a230e0907f5dfe0213742aff0596de", "shasum": "" }, "require": { - "composer-plugin-api": "^1.1.0 || ^2.0", - "php": "^7.4.0" + "ext-tokenizer": "*", + "php": ">=7.0" }, "require-dev": { - "composer/composer": "^1.9.3 || ^2.0@dev", - "doctrine/coding-standard": "^7.0.2", - "ext-zip": "^1.15.0", - "infection/infection": "^0.15.3", - "phpunit/phpunit": "^9.1.1", - "vimeo/psalm": "^3.9.3" + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" }, - "type": "composer-plugin", + "bin": [ + "bin/php-parse" + ], + "type": "library", "extra": { - "class": "PackageVersions\\Installer", "branch-alias": { - "dev-master": "1.99.x-dev" + "dev-master": "4.9-dev" } }, "autoload": { "psr-4": { - "PackageVersions\\": "src/PackageVersions" + "PhpParser\\": "lib/PhpParser" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com" + "name": "Nikita Popov" } ], - "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "funding": [ - { - "url": "https://github.com/Ocramius", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/ocramius/package-versions", - "type": "tidelift" - } + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" ], - "time": "2020-06-22T14:15:44+00:00" + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.2" + }, + "time": "2020-09-26T10:30:38+00:00" }, { "name": "psr/container", @@ -166,6 +182,10 @@ "container-interop", "psr" ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/master" + }, "time": "2017-02-14T16:28:37+00:00" }, { @@ -240,6 +260,9 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/console/tree/v5.1.8" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -316,6 +339,9 @@ "polyfill", "portable" ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.20.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -394,6 +420,9 @@ "portable", "shim" ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.20.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -475,6 +504,9 @@ "portable", "shim" ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.20.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -552,6 +584,9 @@ "portable", "shim" ], + "support": { + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.20.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -628,6 +663,9 @@ "portable", "shim" ], + "support": { + "source": "https://github.com/symfony/polyfill-php73/tree/v1.20.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -708,6 +746,9 @@ "portable", "shim" ], + "support": { + "source": "https://github.com/symfony/polyfill-php80/tree/v1.20.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -784,6 +825,9 @@ "interoperability", "standards" ], + "support": { + "source": "https://github.com/symfony/service-contracts/tree/master" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -864,6 +908,9 @@ "utf-8", "utf8" ], + "support": { + "source": "https://github.com/symfony/string/tree/v5.1.8" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -927,6 +974,10 @@ "check", "validate" ], + "support": { + "issues": "https://github.com/webmozart/assert/issues", + "source": "https://github.com/webmozart/assert/tree/master" + }, "time": "2020-07-08T17:02:28+00:00" }, { @@ -974,6 +1025,10 @@ } ], "description": "A PHP implementation of Ant's glob.", + "support": { + "issues": "https://github.com/webmozart/glob/issues", + "source": "https://github.com/webmozart/glob/tree/master" + }, "time": "2015-12-29T11:14:33+00:00" }, { @@ -1020,22 +1075,26 @@ } ], "description": "A robust cross-platform utility for normalizing, comparing and modifying file paths.", + "support": { + "issues": "https://github.com/webmozart/path-util/issues", + "source": "https://github.com/webmozart/path-util/tree/2.3.0" + }, "time": "2015-12-17T08:42:14+00:00" } ], "packages-dev": [ { "name": "amphp/amp", - "version": "v2.5.0", + "version": "v2.5.1", "source": { "type": "git", "url": "https://github.com/amphp/amp.git", - "reference": "f220a51458bf4dd0dedebb171ac3457813c72bbc" + "reference": "ecdc3c476b3ccff02f8e5d5bcc04f7ccfd18751c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/amp/zipball/f220a51458bf4dd0dedebb171ac3457813c72bbc", - "reference": "f220a51458bf4dd0dedebb171ac3457813c72bbc", + "url": "https://api.github.com/repos/amphp/amp/zipball/ecdc3c476b3ccff02f8e5d5bcc04f7ccfd18751c", + "reference": "ecdc3c476b3ccff02f8e5d5bcc04f7ccfd18751c", "shasum": "" }, "require": { @@ -1100,13 +1159,18 @@ "non-blocking", "promise" ], + "support": { + "irc": "irc://irc.freenode.org/amphp", + "issues": "https://github.com/amphp/amp/issues", + "source": "https://github.com/amphp/amp/tree/v2.5.1" + }, "funding": [ { "url": "https://github.com/amphp", "type": "github" } ], - "time": "2020-07-14T21:47:18+00:00" + "time": "2020-11-03T16:23:45+00:00" }, { "name": "amphp/byte-stream", @@ -1172,20 +1236,25 @@ "non-blocking", "stream" ], + "support": { + "irc": "irc://irc.freenode.org/amphp", + "issues": "https://github.com/amphp/byte-stream/issues", + "source": "https://github.com/amphp/byte-stream/tree/master" + }, "time": "2020-06-29T18:35:05+00:00" }, { "name": "composer/semver", - "version": "3.2.1", + "version": "3.2.2", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "ebb714493b3a54f1dbbec6b15ab7bc9b3440e17b" + "reference": "4089fddb67bcf6bf860d91b979e95be303835002" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/ebb714493b3a54f1dbbec6b15ab7bc9b3440e17b", - "reference": "ebb714493b3a54f1dbbec6b15ab7bc9b3440e17b", + "url": "https://api.github.com/repos/composer/semver/zipball/4089fddb67bcf6bf860d91b979e95be303835002", + "reference": "4089fddb67bcf6bf860d91b979e95be303835002", "shasum": "" }, "require": { @@ -1234,6 +1303,11 @@ "validation", "versioning" ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/3.2.2" + }, "funding": [ { "url": "https://packagist.com", @@ -1248,20 +1322,20 @@ "type": "tidelift" } ], - "time": "2020-09-27T13:14:03+00:00" + "time": "2020-10-14T08:51:15+00:00" }, { "name": "composer/xdebug-handler", - "version": "1.4.3", + "version": "1.4.4", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "ebd27a9866ae8254e873866f795491f02418c5a5" + "reference": "6e076a124f7ee146f2487554a94b6a19a74887ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ebd27a9866ae8254e873866f795491f02418c5a5", - "reference": "ebd27a9866ae8254e873866f795491f02418c5a5", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/6e076a124f7ee146f2487554a94b6a19a74887ba", + "reference": "6e076a124f7ee146f2487554a94b6a19a74887ba", "shasum": "" }, "require": { @@ -1292,6 +1366,11 @@ "Xdebug", "performance" ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/xdebug-handler/issues", + "source": "https://github.com/composer/xdebug-handler/tree/1.4.4" + }, "funding": [ { "url": "https://packagist.com", @@ -1306,7 +1385,7 @@ "type": "tidelift" } ], - "time": "2020-08-19T10:27:58+00:00" + "time": "2020-10-24T12:39:10+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -1372,8 +1451,49 @@ "stylecheck", "tests" ], + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, "time": "2020-06-25T14:57:39+00:00" }, + { + "name": "dnoegel/php-xdg-base-dir", + "version": "v0.1.1", + "source": { + "type": "git", + "url": "https://github.com/dnoegel/php-xdg-base-dir.git", + "reference": "8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dnoegel/php-xdg-base-dir/zipball/8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd", + "reference": "8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~7.0|~6.0|~5.0|~4.8.35" + }, + "type": "library", + "autoload": { + "psr-4": { + "XdgBaseDir\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "implementation of xdg base directory specification for php", + "support": { + "issues": "https://github.com/dnoegel/php-xdg-base-dir/issues", + "source": "https://github.com/dnoegel/php-xdg-base-dir/tree/v0.1.1" + }, + "time": "2019-12-04T15:06:13+00:00" + }, { "name": "doctrine/coding-standard", "version": "8.1.0", @@ -1428,6 +1548,10 @@ "standard", "style" ], + "support": { + "issues": "https://github.com/doctrine/coding-standard/issues", + "source": "https://github.com/doctrine/coding-standard/tree/8.1.x" + }, "time": "2020-07-05T20:35:22+00:00" }, { @@ -1479,6 +1603,10 @@ "constructor", "instantiate" ], + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/1.4.0" + }, "funding": [ { "url": "https://www.doctrine-project.org/sponsorship.html", @@ -1534,31 +1662,40 @@ } ], "description": "A more advanced JSONRPC implementation", + "support": { + "issues": "https://github.com/felixfbecker/php-advanced-json-rpc/issues", + "source": "https://github.com/felixfbecker/php-advanced-json-rpc/tree/master" + }, "time": "2020-03-11T15:21:41+00:00" }, { "name": "felixfbecker/language-server-protocol", - "version": "v1.4.0", + "version": "v1.5.0", "source": { "type": "git", "url": "https://github.com/felixfbecker/php-language-server-protocol.git", - "reference": "378801f6139bb74ac215d81cca1272af61df9a9f" + "reference": "85e83cacd2ed573238678c6875f8f0d7ec699541" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/378801f6139bb74ac215d81cca1272af61df9a9f", - "reference": "378801f6139bb74ac215d81cca1272af61df9a9f", + "url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/85e83cacd2ed573238678c6875f8f0d7ec699541", + "reference": "85e83cacd2ed573238678c6875f8f0d7ec699541", "shasum": "" }, "require": { - "php": "^7.0" + "php": ">=7.1" }, "require-dev": { "phpstan/phpstan": "*", - "phpunit/phpunit": "^6.3", - "squizlabs/php_codesniffer": "^3.1" + "squizlabs/php_codesniffer": "^3.1", + "vimeo/psalm": "^4.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, "autoload": { "psr-4": { "LanguageServerProtocol\\": "src/" @@ -1581,7 +1718,11 @@ "php", "server" ], - "time": "2019-06-23T21:03:50+00:00" + "support": { + "issues": "https://github.com/felixfbecker/php-language-server-protocol/issues", + "source": "https://github.com/felixfbecker/php-language-server-protocol/tree/v1.5.0" + }, + "time": "2020-10-23T13:55:30+00:00" }, { "name": "mikey179/vfsstream", @@ -1627,6 +1768,11 @@ ], "description": "Virtual file system to mock the real file system in unit tests.", "homepage": "http://vfs.bovigo.org/", + "support": { + "issues": "https://github.com/bovigo/vfsStream/issues", + "source": "https://github.com/bovigo/vfsStream/tree/master", + "wiki": "https://github.com/bovigo/vfsStream/wiki" + }, "time": "2019-10-30T15:31:00+00:00" }, { @@ -1675,6 +1821,10 @@ "object", "object graph" ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.x" + }, "funding": [ { "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", @@ -1727,6 +1877,11 @@ } ], "description": "Map nested JSON structures onto PHP classes", + "support": { + "email": "cweiske@cweiske.de", + "issues": "https://github.com/cweiske/jsonmapper/issues", + "source": "https://github.com/cweiske/jsonmapper/tree/master" + }, "time": "2020-04-16T18:48:43+00:00" }, { @@ -1776,6 +1931,10 @@ "xml", "xml conversion" ], + "support": { + "issues": "https://github.com/nullivex/lib-array2xml/issues", + "source": "https://github.com/nullivex/lib-array2xml/tree/master" + }, "time": "2019-03-29T20:06:56+00:00" }, { @@ -1832,6 +1991,10 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/master" + }, "time": "2020-06-27T14:33:11+00:00" }, { @@ -1879,6 +2042,10 @@ } ], "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/master" + }, "time": "2020-06-27T14:39:04+00:00" }, { @@ -1928,6 +2095,10 @@ "reflection", "static analysis" ], + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" + }, "time": "2020-06-27T09:03:43+00:00" }, { @@ -1980,6 +2151,10 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/master" + }, "time": "2020-09-03T19:13:55+00:00" }, { @@ -2025,6 +2200,10 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "support": { + "issues": "https://github.com/phpDocumentor/TypeResolver/issues", + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.4.0" + }, "time": "2020-09-17T18:55:26+00:00" }, { @@ -2088,6 +2267,10 @@ "spy", "stub" ], + "support": { + "issues": "https://github.com/phpspec/prophecy/issues", + "source": "https://github.com/phpspec/prophecy/tree/1.12.1" + }, "time": "2020-09-29T09:10:42+00:00" }, { @@ -2137,6 +2320,10 @@ "MIT" ], "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/master" + }, "time": "2020-08-03T20:32:43+00:00" }, { @@ -2179,6 +2366,10 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/0.12.54" + }, "funding": [ { "url": "https://github.com/ondrejmirtes", @@ -2260,6 +2451,10 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2316,6 +2511,10 @@ "filesystem", "iterator" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2375,6 +2574,10 @@ "keywords": [ "process" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2430,6 +2633,10 @@ "keywords": [ "template" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2485,6 +2692,10 @@ "keywords": [ "timer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2580,6 +2791,10 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.4.3" + }, "funding": [ { "url": "https://phpunit.de/donate.html", @@ -2637,6 +2852,9 @@ "psr", "psr-3" ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.3" + }, "time": "2020-03-23T09:12:05+00:00" }, { @@ -2683,6 +2901,10 @@ ], "description": "Library for parsing CLI options", "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2735,6 +2957,10 @@ ], "description": "Collection of value objects that represent the PHP code units", "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2786,6 +3012,10 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2856,6 +3086,10 @@ "compare", "equality" ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.6" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2909,6 +3143,10 @@ ], "description": "Library for calculating the complexity of PHP code units", "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2971,6 +3209,10 @@ "unidiff", "unified diff" ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3030,6 +3272,10 @@ "environment", "hhvm" ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3103,6 +3349,10 @@ "export", "exporter" ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3163,6 +3413,10 @@ "keywords": [ "global state" ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3216,6 +3470,10 @@ ], "description": "Library for counting the lines of code in PHP source code", "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3269,6 +3527,10 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3320,6 +3582,10 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3379,6 +3645,10 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3430,6 +3700,10 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "support": { + "issues": "https://github.com/sebastianbergmann/resource-operations/issues", + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3482,6 +3756,10 @@ ], "description": "Collection of value objects that represent the types of the PHP type system", "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/2.3.1" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3531,6 +3809,10 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -3584,6 +3866,10 @@ "MIT" ], "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/6.4.1" + }, "funding": [ { "url": "https://github.com/kukulich", @@ -3645,6 +3931,11 @@ "phpcs", "standards" ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, "time": "2020-08-10T04:50:15+00:00" }, { @@ -3685,6 +3976,10 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/master" + }, "funding": [ { "url": "https://github.com/theseer", @@ -3695,33 +3990,35 @@ }, { "name": "vimeo/psalm", - "version": "3.12.2", + "version": "3.18.2", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "7c7ebd068f8acaba211d4a2c707c4ba90874fa26" + "reference": "19aa905f7c3c7350569999a93c40ae91ae4e1626" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/7c7ebd068f8acaba211d4a2c707c4ba90874fa26", - "reference": "7c7ebd068f8acaba211d4a2c707c4ba90874fa26", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/19aa905f7c3c7350569999a93c40ae91ae4e1626", + "reference": "19aa905f7c3c7350569999a93c40ae91ae4e1626", "shasum": "" }, "require": { "amphp/amp": "^2.1", "amphp/byte-stream": "^1.5", + "composer/package-versions-deprecated": "^1.8.0", "composer/semver": "^1.4 || ^2.0 || ^3.0", "composer/xdebug-handler": "^1.1", + "dnoegel/php-xdg-base-dir": "^0.1.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", + "ext-mbstring": "*", "ext-simplexml": "*", "ext-tokenizer": "*", "felixfbecker/advanced-json-rpc": "^3.0.3", "felixfbecker/language-server-protocol": "^1.4", - "netresearch/jsonmapper": "^1.0 || ^2.0", - "nikic/php-parser": "^4.3", - "ocramius/package-versions": "^1.2", + "netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0", + "nikic/php-parser": "4.3.* || 4.4.* || 4.5.* || 4.6.* || ^4.8", "openlss/lib-array2xml": "^1.0", "php": "^7.1.3|^8", "sebastian/diff": "^3.0 || ^4.0", @@ -3737,14 +4034,15 @@ "bamarni/composer-bin-plugin": "^1.2", "brianium/paratest": "^4.0.0", "ext-curl": "*", - "php-coveralls/php-coveralls": "^2.2", + "phpdocumentor/reflection-docblock": "^4.3.4 || ^5", "phpmyadmin/sql-parser": "5.1.0", "phpspec/prophecy": ">=1.9.0", "phpunit/phpunit": "^7.5.16 || ^8.5 || ^9.0", - "psalm/plugin-phpunit": "^0.10", + "psalm/plugin-phpunit": "^0.11", "slevomat/coding-standard": "^5.0", "squizlabs/php_codesniffer": "^3.5", - "symfony/process": "^4.3" + "symfony/process": "^4.3", + "weirdan/prophecy-shim": "^1.0 || ^2.0" }, "suggest": { "ext-igbinary": "^2.0.5" @@ -3788,7 +4086,11 @@ "inspection", "php" ], - "time": "2020-07-03T16:59:07+00:00" + "support": { + "issues": "https://github.com/vimeo/psalm/issues", + "source": "https://github.com/vimeo/psalm/tree/3.18.2" + }, + "time": "2020-10-20T13:48:22+00:00" } ], "aliases": [], @@ -3804,5 +4106,5 @@ "platform-dev": { "ext-zend-opcache": "*" }, - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.0.0" } From 7cda74ec61b1d681fd8c1d25152b073cfeb0a9af Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Sun, 4 Oct 2020 17:30:16 +0200 Subject: [PATCH 18/25] add webmozart/assert as dependecy --- composer.json | 3 ++- composer.lock | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index fc901817..40b763f0 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "nikic/php-parser": "^4.10.2", "ocramius/package-versions": "^1.9.0", "symfony/console": "^5.1.8", - "webmozart/glob": "^4.1.0" + "webmozart/glob": "^4.1.0", + "webmozart/assert": "^1.9.1" }, "require-dev": { "ext-zend-opcache": "*", diff --git a/composer.lock b/composer.lock index ed929488..e740e27f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "126284961d8fde69b5f5787ea2c81d62", + "content-hash": "09199155ef64dd89c3cbf3b1ad8b7e8a", "packages": [ { "name": "composer/package-versions-deprecated", From 82117c7bdce3e8c62263a1becdd447ffd7356161 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Sun, 4 Oct 2020 17:31:05 +0200 Subject: [PATCH 19/25] use assert to check if file exists and is readable --- src/ComposerRequireChecker/JsonLoader.php | 29 +++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/ComposerRequireChecker/JsonLoader.php b/src/ComposerRequireChecker/JsonLoader.php index fe3499b6..66426c10 100644 --- a/src/ComposerRequireChecker/JsonLoader.php +++ b/src/ComposerRequireChecker/JsonLoader.php @@ -6,10 +6,11 @@ use ComposerRequireChecker\Exception\InvalidJson; use ComposerRequireChecker\Exception\NotReadable; +use InvalidArgumentException; use Throwable; +use Webmozart\Assert\Assert; use function file_get_contents; -use function is_readable; use function json_decode; use const JSON_THROW_ON_ERROR; @@ -27,8 +28,22 @@ class JsonLoader */ public static function getData(string $path): array { - if (! is_readable($path)) { - throw new NotReadable('unable to read ' . $path); + try { + $decodedData = json_decode(self::getFileContentFromPath($path), true, 512, JSON_THROW_ON_ERROR); + } catch (Throwable $exception) { + throw new InvalidJson('error parsing ' . $path . ': ' . $exception->getMessage(), 0, $exception); + } + + return $decodedData; + } + + private static function getFileContentFromPath(string $path): string + { + try { + Assert::file($path); + Assert::readable($path); + } catch (InvalidArgumentException $exception) { + throw new NotReadable('unable to read ' . $path, 0, $exception); } $content = file_get_contents($path); @@ -37,12 +52,6 @@ public static function getData(string $path): array throw new NotReadable('unable to read ' . $path); } - try { - $decodedData = json_decode($content, true, 512, JSON_THROW_ON_ERROR); - } catch (Throwable $exception) { - throw new InvalidJson('error parsing ' . $path . ': ' . $exception->getMessage(), 0, $exception); - } - - return $decodedData; + return $content; } } From 135d620815f99862dde0e07b1ddf9b3031818b01 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Tue, 10 Nov 2020 19:21:38 +0100 Subject: [PATCH 20/25] fixed psalm issues after rebasing --- src/ComposerRequireChecker/Cli/CheckCommand.php | 8 +++++--- src/ComposerRequireChecker/Cli/Options.php | 3 +++ .../FileLocator/LocateAllFilesByExtension.php | 2 -- ...eComposerPackageDirectDependenciesSourceFiles.php | 4 +--- src/ComposerRequireChecker/JsonLoader.php | 5 ++++- .../NodeVisitor/DefinedSymbolCollector.php | 12 ++++++------ test/ComposerRequireCheckerTest/JsonLoaderTest.php | 4 ++-- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/ComposerRequireChecker/Cli/CheckCommand.php b/src/ComposerRequireChecker/Cli/CheckCommand.php index fe8ceb21..bd98e481 100644 --- a/src/ComposerRequireChecker/Cli/CheckCommand.php +++ b/src/ComposerRequireChecker/Cli/CheckCommand.php @@ -29,6 +29,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Webmozart\Assert\Assert; use function array_diff; use function array_merge; @@ -171,8 +172,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int } /** - * @return array - * * @throws InvalidJson * @throws NotReadable */ @@ -184,7 +183,10 @@ private function getCheckOptions(InputInterface $input): Options return new Options(); } - return new Options(JsonLoader::getData($fileName)); + $config = JsonLoader::getData($fileName); + Assert::isMap($config); + + return new Options($config); } /** diff --git a/src/ComposerRequireChecker/Cli/Options.php b/src/ComposerRequireChecker/Cli/Options.php index 46e75f6d..b1e47350 100644 --- a/src/ComposerRequireChecker/Cli/Options.php +++ b/src/ComposerRequireChecker/Cli/Options.php @@ -55,6 +55,9 @@ class Options */ public function __construct(array $options = []) { + /** + * @var mixed $option + */ foreach ($options as $key => $option) { $methodName = 'set' . $this->getCamelCase($key); if (! method_exists($this, $methodName)) { diff --git a/src/ComposerRequireChecker/FileLocator/LocateAllFilesByExtension.php b/src/ComposerRequireChecker/FileLocator/LocateAllFilesByExtension.php index dc48a258..216903c7 100644 --- a/src/ComposerRequireChecker/FileLocator/LocateAllFilesByExtension.php +++ b/src/ComposerRequireChecker/FileLocator/LocateAllFilesByExtension.php @@ -9,7 +9,6 @@ use SplFileInfo; use Traversable; -use function assert; use function implode; use function preg_match; use function preg_quote; @@ -54,7 +53,6 @@ private function filterFilesByExtension(Traversable $files, string $fileExtensio $blacklistMatcher = '{(' . implode('|', $this->prepareBlacklistPatterns($blacklist)) . ')}'; foreach ($files as $file) { - assert($file instanceof SplFileInfo); if ($blacklist && preg_match($blacklistMatcher, $file->getPathname())) { continue; } diff --git a/src/ComposerRequireChecker/FileLocator/LocateComposerPackageDirectDependenciesSourceFiles.php b/src/ComposerRequireChecker/FileLocator/LocateComposerPackageDirectDependenciesSourceFiles.php index 45a55492..3ca69575 100644 --- a/src/ComposerRequireChecker/FileLocator/LocateComposerPackageDirectDependenciesSourceFiles.php +++ b/src/ComposerRequireChecker/FileLocator/LocateComposerPackageDirectDependenciesSourceFiles.php @@ -12,9 +12,7 @@ use function array_key_exists; use function assert; use function dirname; -use function file_get_contents; use function is_string; -use function json_decode; final class LocateComposerPackageDirectDependenciesSourceFiles { @@ -22,7 +20,7 @@ public function __invoke(string $composerJsonPath): Generator { $packageDir = dirname($composerJsonPath); - $composerJson = json_decode(file_get_contents($composerJsonPath), true); + $composerJson = JsonLoader::getData($composerJsonPath); $configVendorDir = $composerJson['config']['vendor-dir'] ?? 'vendor'; assert(is_string($configVendorDir)); $vendorDirs = []; diff --git a/src/ComposerRequireChecker/JsonLoader.php b/src/ComposerRequireChecker/JsonLoader.php index 66426c10..c998052b 100644 --- a/src/ComposerRequireChecker/JsonLoader.php +++ b/src/ComposerRequireChecker/JsonLoader.php @@ -28,8 +28,11 @@ class JsonLoader */ public static function getData(string $path): array { + $content = self::getFileContentFromPath($path); + try { - $decodedData = json_decode(self::getFileContentFromPath($path), true, 512, JSON_THROW_ON_ERROR); + $decodedData = json_decode($content, true, 512, JSON_THROW_ON_ERROR); + Assert::isArray($decodedData); } catch (Throwable $exception) { throw new InvalidJson('error parsing ' . $path . ': ' . $exception->getMessage(), 0, $exception); } diff --git a/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php b/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php index d22f648e..f8a4c45e 100644 --- a/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php +++ b/src/ComposerRequireChecker/NodeVisitor/DefinedSymbolCollector.php @@ -108,12 +108,12 @@ private function recordDefinedConstDefinition(Node $node): void return; } - if ( - $node->name->hasAttribute('namespacedName') - && $node->name->getAttribute('namespacedName') instanceof Node\Name\FullyQualified - && $node->name->getAttribute('namespacedName')->toString() !== 'define' - ) { - return; + if ($node->name->hasAttribute('namespacedName')) { + /** @var mixed $namespacedName */ + $namespacedName = $node->name->getAttribute('namespacedName'); + if ($namespacedName instanceof Node\Name\FullyQualified && $namespacedName->toString() !== 'define') { + return; + } } if (! ($node->args[0]->value instanceof Node\Scalar\String_)) { diff --git a/test/ComposerRequireCheckerTest/JsonLoaderTest.php b/test/ComposerRequireCheckerTest/JsonLoaderTest.php index 65e4b1a4..688f4a5b 100644 --- a/test/ComposerRequireCheckerTest/JsonLoaderTest.php +++ b/test/ComposerRequireCheckerTest/JsonLoaderTest.php @@ -31,8 +31,8 @@ public function testHasErrorWithInvalidFile(): void public function testHasDataWithValidFileButNoArrayContent(): void { $path = __DIR__ . '/../fixtures/validJsonNotAnArray.json'; - $this->expectException(InvalidJsonException::class); - new JsonLoader($path); + $this->expectException(InvalidJson::class); + JsonLoader::getData($path); } public function testHasDataWithValidFile(): void From 08f80539e0cc5844efda87435415f763ebccbb4e Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Tue, 10 Nov 2020 19:29:31 +0100 Subject: [PATCH 21/25] cast NodeName to string like it should be done before --- src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php b/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php index 1214facb..5c608338 100644 --- a/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php +++ b/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php @@ -198,7 +198,7 @@ private function recordTraitUsage(Node $node): void private function recordUsageOf(Node\Name $symbol): void { - $this->collectedSymbols[(string) $symbol] = $symbol; + $this->collectedSymbols[(string) $symbol] = (string)$symbol; } private function recordUsageOfByString(string $symbol): void From 2eb843123f25825f7dd6012c4cc3419f61b74930 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Tue, 10 Nov 2020 19:30:47 +0100 Subject: [PATCH 22/25] try to resolve the PackageVersion problem but because of the replacement the tool itself says its not installed which is true --- composer.json | 6 +++--- composer.lock | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 40b763f0..85b6c9c6 100644 --- a/composer.json +++ b/composer.json @@ -30,10 +30,10 @@ "ext-json": "*", "ext-phar": "*", "nikic/php-parser": "^4.10.2", - "ocramius/package-versions": "^1.9.0", + "ocramius/package-versions": "^1.11.0", "symfony/console": "^5.1.8", - "webmozart/glob": "^4.1.0", - "webmozart/assert": "^1.9.1" + "webmozart/assert": "^1.9.1", + "webmozart/glob": "^4.1.0" }, "require-dev": { "ext-zend-opcache": "*", diff --git a/composer.lock b/composer.lock index e740e27f..84e1584d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "09199155ef64dd89c3cbf3b1ad8b7e8a", + "content-hash": "7cd31934ea90adaf4c62aa8a00067dfc", "packages": [ { "name": "composer/package-versions-deprecated", From c81fef850ee81ff9de50707a58c71684005ec69e Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Tue, 10 Nov 2020 19:33:58 +0100 Subject: [PATCH 23/25] cs fix --- src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php b/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php index 5c608338..3028e04d 100644 --- a/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php +++ b/src/ComposerRequireChecker/NodeVisitor/UsedSymbolCollector.php @@ -198,7 +198,7 @@ private function recordTraitUsage(Node $node): void private function recordUsageOf(Node\Name $symbol): void { - $this->collectedSymbols[(string) $symbol] = (string)$symbol; + $this->collectedSymbols[(string) $symbol] = (string) $symbol; } private function recordUsageOfByString(string $symbol): void From cc302ed5155ccfc7547abbf6d1a580bab0e901f2 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 27 Nov 2020 15:36:40 +0100 Subject: [PATCH 24/25] fix psalm issues according to the array --- ...teDefinedSymbolsFromComposerRuntimeApi.php | 26 +++++++++++++------ ...finedSymbolsFromComposerRuntimeApiTest.php | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/ComposerRequireChecker/DefinedSymbolsLocator/LocateDefinedSymbolsFromComposerRuntimeApi.php b/src/ComposerRequireChecker/DefinedSymbolsLocator/LocateDefinedSymbolsFromComposerRuntimeApi.php index 510cb6be..31714c67 100644 --- a/src/ComposerRequireChecker/DefinedSymbolsLocator/LocateDefinedSymbolsFromComposerRuntimeApi.php +++ b/src/ComposerRequireChecker/DefinedSymbolsLocator/LocateDefinedSymbolsFromComposerRuntimeApi.php @@ -5,26 +5,36 @@ namespace ComposerRequireChecker\DefinedSymbolsLocator; use function array_key_exists; +use function is_array; +use function is_string; use function preg_match; final class LocateDefinedSymbolsFromComposerRuntimeApi { /** - * @param mixed[] $composerData The contents of composer.json for a package + * @param array $composerData The contents of composer.json for a package * * @return string[] */ public function __invoke(array $composerData): array { - $definedSymbols = []; + if (! array_key_exists('require', $composerData)) { + return []; + } + + if (! is_array($composerData['require'])) { + return []; + } + + $requireSection = $composerData['require']; + if (! array_key_exists('composer-runtime-api', $requireSection)) { + return []; + } - if ( - array_key_exists('composer-runtime-api', $composerData['require'] ?? []) - && preg_match('/^(\^|~|>|>=|=)2/', $composerData['require']['composer-runtime-api']) - ) { - $definedSymbols[] = 'Composer\InstalledVersions'; + if (! is_string($requireSection['composer-runtime-api']) || ! preg_match('/^(\^|~|>|>=|=)2/', $requireSection['composer-runtime-api'])) { + return []; } - return $definedSymbols; + return ['Composer\InstalledVersions']; } } diff --git a/test/ComposerRequireCheckerTest/DefinedSymbolsLocator/LocateDefinedSymbolsFromComposerRuntimeApiTest.php b/test/ComposerRequireCheckerTest/DefinedSymbolsLocator/LocateDefinedSymbolsFromComposerRuntimeApiTest.php index 24269056..90267495 100644 --- a/test/ComposerRequireCheckerTest/DefinedSymbolsLocator/LocateDefinedSymbolsFromComposerRuntimeApiTest.php +++ b/test/ComposerRequireCheckerTest/DefinedSymbolsLocator/LocateDefinedSymbolsFromComposerRuntimeApiTest.php @@ -60,7 +60,7 @@ public function provideComposerJsonWithSuitableComposerRuntimeApi(): Generator } /** - * @param mixed[] $composerData + * @param array $composerData * * @return string[] */ From 11f7a505e6c424149c7e27ed3b30d709ba35f837 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 27 Nov 2020 15:39:32 +0100 Subject: [PATCH 25/25] add composer-runtime-api as a dependency and remove Ocramius/PackageVersions: with this composer 1 support is dropped, replace the usage of version --- composer.json | 2 +- composer.lock | 151 +++++++++--------- .../Cli/Application.php | 10 +- 3 files changed, 85 insertions(+), 78 deletions(-) diff --git a/composer.json b/composer.json index 85b6c9c6..ffe929c1 100644 --- a/composer.json +++ b/composer.json @@ -29,8 +29,8 @@ "php": "7.4.*", "ext-json": "*", "ext-phar": "*", + "composer-runtime-api": "^2.0.0", "nikic/php-parser": "^4.10.2", - "ocramius/package-versions": "^1.11.0", "symfony/console": "^5.1.8", "webmozart/assert": "^1.9.1", "webmozart/glob": "^4.1.0" diff --git a/composer.lock b/composer.lock index 84e1584d..f2680734 100644 --- a/composer.lock +++ b/composer.lock @@ -4,81 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7cd31934ea90adaf4c62aa8a00067dfc", + "content-hash": "a39205e4338c18f7749c2d589fb49f6a", "packages": [ - { - "name": "composer/package-versions-deprecated", - "version": "1.11.99", - "source": { - "type": "git", - "url": "https://github.com/composer/package-versions-deprecated.git", - "reference": "c8c9aa8a14cc3d3bec86d0a8c3fa52ea79936855" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/c8c9aa8a14cc3d3bec86d0a8c3fa52ea79936855", - "reference": "c8c9aa8a14cc3d3bec86d0a8c3fa52ea79936855", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.1.0 || ^2.0", - "php": "^7 || ^8" - }, - "replace": { - "ocramius/package-versions": "1.11.99" - }, - "require-dev": { - "composer/composer": "^1.9.3 || ^2.0@dev", - "ext-zip": "^1.13", - "phpunit/phpunit": "^6.5 || ^7" - }, - "type": "composer-plugin", - "extra": { - "class": "PackageVersions\\Installer", - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "PackageVersions\\": "src/PackageVersions" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com" - }, - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be" - } - ], - "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "support": { - "issues": "https://github.com/composer/package-versions-deprecated/issues", - "source": "https://github.com/composer/package-versions-deprecated/tree/master" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2020-08-25T05:50:16+00:00" - }, { "name": "nikic/php-parser", "version": "v4.10.2", @@ -1243,6 +1170,79 @@ }, "time": "2020-06-29T18:35:05+00:00" }, + { + "name": "composer/package-versions-deprecated", + "version": "1.11.99", + "source": { + "type": "git", + "url": "https://github.com/composer/package-versions-deprecated.git", + "reference": "c8c9aa8a14cc3d3bec86d0a8c3fa52ea79936855" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/c8c9aa8a14cc3d3bec86d0a8c3fa52ea79936855", + "reference": "c8c9aa8a14cc3d3bec86d0a8c3fa52ea79936855", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.1.0 || ^2.0", + "php": "^7 || ^8" + }, + "replace": { + "ocramius/package-versions": "1.11.99" + }, + "require-dev": { + "composer/composer": "^1.9.3 || ^2.0@dev", + "ext-zip": "^1.13", + "phpunit/phpunit": "^6.5 || ^7" + }, + "type": "composer-plugin", + "extra": { + "class": "PackageVersions\\Installer", + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "PackageVersions\\": "src/PackageVersions" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be" + } + ], + "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", + "support": { + "issues": "https://github.com/composer/package-versions-deprecated/issues", + "source": "https://github.com/composer/package-versions-deprecated/tree/master" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2020-08-25T05:50:16+00:00" + }, { "name": "composer/semver", "version": "3.2.2", @@ -4101,7 +4101,8 @@ "platform": { "php": "7.4.*", "ext-json": "*", - "ext-phar": "*" + "ext-phar": "*", + "composer-runtime-api": "^2.0.0" }, "platform-dev": { "ext-zend-opcache": "*" diff --git a/src/ComposerRequireChecker/Cli/Application.php b/src/ComposerRequireChecker/Cli/Application.php index fc3d43b6..bec82af6 100644 --- a/src/ComposerRequireChecker/Cli/Application.php +++ b/src/ComposerRequireChecker/Cli/Application.php @@ -4,16 +4,22 @@ namespace ComposerRequireChecker\Cli; -use PackageVersions\Versions; +use Composer\InstalledVersions; use Symfony\Component\Console\Application as AbstractApplication; +use function sprintf; + class Application extends AbstractApplication { public function __construct() { parent::__construct( 'ComposerRequireChecker', - Versions::getVersion('maglnet/composer-require-checker') + sprintf( + '%s@%s', + (string) InstalledVersions::getPrettyVersion('maglnet/composer-require-checker'), + (string) InstalledVersions::getReference('maglnet/composer-require-checker') + ) ); $check = new CheckCommand();