Skip to content

Commit

Permalink
Merge branch 'master' of github.com:yireo/Yireo_ExtensionChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Sep 17, 2024
2 parents d8ecdfe + ea2bba1 commit a8d04a4
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 17 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 12 additions & 6 deletions Composer/ComposerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '"');
}
Expand Down Expand Up @@ -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;
}
}
30 changes: 25 additions & 5 deletions Console/Command/ListModulesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)');
}

/**
Expand All @@ -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',
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion PhpClass/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion Scan/ScanComposerRequirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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": {
Expand Down

0 comments on commit a8d04a4

Please sign in to comment.