diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fecab7..bee59b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +# [2.4.4] = 29 August 2024 +### Fixed +- Prevent exception when require and/or require-dev is empty + +# [2.4.3] = 23 August 2024 +### Fixed +- Fixes for dev requirements + +# [2.4.2] = 12 August 2024 +### Fixed +- Changed call in Nikic parser + + +# [2.4.1] = 24 June 2024 +### Fixed +- Added JSON format to module list output + # [2.4.0] = 21 June 2024 ### Added - New CLI `yireo_extensionchecker:list:modules` (module name, enabled/disabled, composer version) diff --git a/Composer/ComposerFile.php b/Composer/ComposerFile.php index d791d02..2b606ba 100644 --- a/Composer/ComposerFile.php +++ b/Composer/ComposerFile.php @@ -38,13 +38,13 @@ public function getData(): array { $read = $this->readFactory->create($this->composerFile, 'file'); $composerContents = $read->readAll(); - + try { $extensionData = $this->serializer->unserialize($composerContents); } catch (InvalidArgumentException $invalidArgumentException) { throw new RuntimeException('Unserialize of file "' . $this->composerFile . '" failed: '.$invalidArgumentException->getMessage()); } - + if (empty($extensionData)) { throw new RuntimeException('Empty contents after decoding file "' . $this->composerFile . '"'); } @@ -78,12 +78,18 @@ public function getName(): string /** * @return array - * @throws NotFoundException - * @throws RuntimeException */ public function getRequirements(): array { - // @todo: Merge this with require-dev? - return $this->get('require'); + $requirements = []; + try { + $requirements = array_merge($requirements, $this->get('require')); + } catch (RuntimeException $runtimeException) {} + + try { + $requirements = array_merge($requirements, $this->get('require-dev')); + } catch (RuntimeException $runtimeException) {} + + return $requirements; } } diff --git a/Console/Command/ListModulesCommand.php b/Console/Command/ListModulesCommand.php index 2c6a818..b07e4b4 100644 --- a/Console/Command/ListModulesCommand.php +++ b/Console/Command/ListModulesCommand.php @@ -9,6 +9,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface as Input; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface as Output; use Yireo\ExtensionChecker\Composer\ComposerFileFactory; use Yireo\ExtensionChecker\Composer\ComposerProvider; @@ -41,6 +42,7 @@ protected function configure() { $this->setName('yireo_extensionchecker:list:modules'); $this->setDescription('List all Magento modules'); + $this->addOption('format', null, InputOption::VALUE_OPTIONAL, 'Format (json, default)'); } /** @@ -51,6 +53,14 @@ protected function configure() */ protected function execute(Input $input, Output $output): int { + $moduleRows = $this->getModuleRows(); + $format = $input->getOption('format'); + + if ($format === 'json') { + $output->writeln(json_encode($moduleRows)); + return Command::SUCCESS; + } + $table = new Table($output); $table->setHeaders([ 'Module', @@ -59,25 +69,35 @@ protected function execute(Input $input, Output $output): int 'Composer Version' ]); + foreach ($moduleRows as $moduleRow) { + $table->addRow($moduleRow); + } + + $table->render(); + + return Command::SUCCESS; + } + + private function getModuleRows(): array + { $componentPaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE); $moduleNames = array_keys($componentPaths); + $moduleRows = []; foreach ($moduleNames as $moduleName) { $moduleInfo = $this->moduleList->getOne($moduleName); $status = $moduleInfo ? 'enabled' : 'disabled'; $setupVersion = isset($moduleInfo['setup_version']) ? $moduleInfo['setup_version'] : '-'; - $table->addRow([ + $moduleRows[] = [ $moduleName, $status, $setupVersion, $this->getComposerVersion($moduleName) - ]); + ]; } - $table->render(); - - return Command::SUCCESS; + return $moduleRows; } private function getComposerVersion(string $moduleName): string diff --git a/PhpClass/Tokenizer.php b/PhpClass/Tokenizer.php index 1ad4b36..f1015f7 100644 --- a/PhpClass/Tokenizer.php +++ b/PhpClass/Tokenizer.php @@ -64,7 +64,7 @@ public function getImportedClassnamesFromFile(string $filename): array */ public function getImportedClassnamesFromSource(string $source): array { - $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); + $parser = (new ParserFactory())->createForNewestSupportedVersion(); $traverser = new NodeTraverser; $traverser->addVisitor(new NameResolver); $stmts = $parser->parse($source); diff --git a/Scan/ScanComposerRequirements.php b/Scan/ScanComposerRequirements.php index 831262f..567442b 100644 --- a/Scan/ScanComposerRequirements.php +++ b/Scan/ScanComposerRequirements.php @@ -172,7 +172,10 @@ private function isComposerDependencyNeeded(string $dependency, array $component $validDependencies = [ 'php', - 'magento/magento-composer-installer' + 'magento/magento-composer-installer', + 'phpstan/phpstan', + 'bitexpert/phpstan-magento', + 'yireo/magento2-integration-test-helper', ]; if (\in_array($dependency, $validDependencies)) { diff --git a/composer.json b/composer.json index 72e4fa2..555ce0e 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "yireo/magento2-extensionchecker", "license": "OSL-3.0", "type": "magento2-module", - "version": "2.4.0", + "version": "2.4.4", "homepage": "https://github.com/yireo/Yireo_ExtensionChecker", "description": "Scan the code of a Magento module", "keywords": [ @@ -17,16 +17,16 @@ ], "require": { "magento/framework": "^102.0|^103.0", - "symfony/finder": "^3.0|^4.0|^5.0|^6.0", + "symfony/finder": "^3.0|^4.0|^5.0|^6.0|^7.0", "composer/semver": "^1.0|^2.0|^3.0", - "nikic/php-parser": "^3.0|^4.0", + "nikic/php-parser": "^3.0|^4.0|^5.0", "php": "^7.4|^8.1", "ext-json": "*", "ext-pcre": "*", "ext-xml": "*" }, "require-dev": { - "yireo/magento2-integration-test-helper": "*" + "yireo/magento2-integration-test-helper": "~0.0.13" }, "autoload": { "psr-4": {