Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStan Level 9 #16

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TRAEFIK_DOMAIN=depends.test
TRAEFIK_SUBDOMAIN=app

WARDEN_PHP=1
PHP_VERSION=8.0
PHP_VERSION=8.2
PHP_XDEBUG_3=1

COMPOSER_VERSION=2
Expand Down
29 changes: 21 additions & 8 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.3
coverage: xdebug
tools: composer:v2

Expand All @@ -32,29 +32,42 @@ jobs:
phpstan:
name: Static Analysis Check
runs-on: ubuntu-latest
container:
image: davidalger/php:8.0
strategy:
matrix:
php: [8.1, 8.2, 8.3]
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
tools: composer:v2

- name: Checkout Repository
uses: actions/checkout@v2

- name: Install Dependencies
run: composer2 install
run: composer install

- name: Run PHPStan
run: vendor/bin/phpstan

phpcs:
name: Code Style (PSR-12)
runs-on: ubuntu-latest
container:
image: davidalger/php:8.0
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: xdebug
tools: composer:v2

- name: Checkout Repository
uses: actions/checkout@v2

- name: Install Dependencies
run: composer2 install
run: composer install

- name: PHP Code Sniffer
run: vendor/bin/phpcs
Expand All @@ -67,7 +80,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.3
coverage: xdebug
tools: composer:v2

Expand Down
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"type": "composer-plugin",
"license": "MIT",
"require": {
"php": "^7.1|^8",
"php": "^7.1|^8.1",
"composer-plugin-api": "^2",
"composer/composer": "^2",
"composer/semver": "^1|^2|^3",
"symfony/console": "^5",
"nikic/php-parser": "^4",
"navarr/attribute-dependency": "^1.0.1",
"php-di/php-di": "^6"
"php-di/php-di": "^7"
},
"suggest": {
"ext-fileinfo": "Use MIME types for PHP file detection",
Expand All @@ -21,9 +21,9 @@
"require-dev": {
"php": "^8",
"roave/security-advisories": "dev-master",
"phpstan/phpstan": "^0.12.32",
"phpstan/phpstan": "^1",
"phpunit/phpunit": "^9.5",
"infection/infection": "^0.23.0",
"infection/infection": "^0.27.0",
"squizlabs/php_codesniffer": "^3.6",
"jetbrains/phpstorm-attributes": "^1.0"
},
Expand Down Expand Up @@ -56,5 +56,10 @@
".gitattributes",
".env"
]
},
"config": {
"allow-plugins": {
"infection/extension-installer": true
}
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
parameters:
level: 8
level: 9
paths:
- src
2 changes: 1 addition & 1 deletion src/Controller/CliApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public static function execute(): int
{
$application = new Application('DepAnno', static::VERSION);
$application = new Application('DepAnno', self::VERSION);

Check warning on line 21 in src/Controller/CliApplication.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/CliApplication.php#L21

Added line #L21 was not covered by tests
$application->add(new WhyBlockCommandController());
return $application->run();
}
Expand Down
24 changes: 16 additions & 8 deletions src/Controller/Composer/ComposerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Navarr\Depends\ScopeDeterminer\ComposerScopeDeterminer;
use Navarr\Depends\ScopeDeterminer\ScopeDeterminerInterface;
use Psr\Container\ContainerInterface;
use RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -72,37 +73,37 @@
// phpcs:enable Generic.Files.LineLength.TooLong
protected function configure(): void
{
$this->setName('why-block')

Check warning on line 76 in src/Controller/Composer/ComposerCommand.php

View workflow job for this annotation

GitHub Actions / Infection Check

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ #[Dependency('php-di/php-di', '^6', 'DI\\ContainerBuilder::addDefinitions and the existence of the DI\\autowire function')] protected function configure() : void { - $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, ['f'], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, ['e'], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, ['l'], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, ['r'], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, ['a'], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); + } #[Dependency('symfony/console', '^5', 'InputInterface::getOption and OutputInterface::writeln')] protected function execute(InputInterface $input, OutputInterface $output) : int
->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')
->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')
->addOption(
self::OUTPUT_FORMAT,
['f'],

Check warning on line 81 in src/Controller/Composer/ComposerCommand.php

View workflow job for this annotation

GitHub Actions / Infection Check

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ #[Dependency('php-di/php-di', '^6', 'DI\\ContainerBuilder::addDefinitions and the existence of the DI\\autowire function')] protected function configure() : void { - $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, ['f'], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, ['e'], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, ['l'], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, ['r'], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, ['a'], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); + $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, [], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, ['e'], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, ['l'], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, ['r'], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, ['a'], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); } #[Dependency('symfony/console', '^5', 'InputInterface::getOption and OutputInterface::writeln')] protected function execute(InputInterface $input, OutputInterface $output) : int
InputOption::VALUE_OPTIONAL,
'Format to output results in. Accepted values: text, csv, json, xml',
'text'
)
->addOption(
self::FAIL_ON_ERROR,
['e'],

Check warning on line 88 in src/Controller/Composer/ComposerCommand.php

View workflow job for this annotation

GitHub Actions / Infection Check

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ #[Dependency('php-di/php-di', '^6', 'DI\\ContainerBuilder::addDefinitions and the existence of the DI\\autowire function')] protected function configure() : void { - $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, ['f'], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, ['e'], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, ['l'], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, ['r'], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, ['a'], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); + $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, ['f'], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, [], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, ['l'], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, ['r'], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, ['a'], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); } #[Dependency('symfony/console', '^5', 'InputInterface::getOption and OutputInterface::writeln')] protected function execute(InputInterface $input, OutputInterface $output) : int
InputOption::VALUE_NONE,
'Immediately fail on parsing errors'
)
->addOption(
self::LEGACY_ANNOTATION,
['l'],

Check warning on line 94 in src/Controller/Composer/ComposerCommand.php

View workflow job for this annotation

GitHub Actions / Infection Check

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ #[Dependency('php-di/php-di', '^6', 'DI\\ContainerBuilder::addDefinitions and the existence of the DI\\autowire function')] protected function configure() : void { - $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, ['f'], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, ['e'], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, ['l'], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, ['r'], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, ['a'], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); + $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, ['f'], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, ['e'], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, [], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, ['r'], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, ['a'], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); } #[Dependency('symfony/console', '^5', 'InputInterface::getOption and OutputInterface::writeln')] protected function execute(InputInterface $input, OutputInterface $output) : int
InputOption::VALUE_NONE,
'Include old @dependency/@composerDependency annotations in search'
)
->addOption(
self::ROOT_DEPS,
['r'],

Check warning on line 100 in src/Controller/Composer/ComposerCommand.php

View workflow job for this annotation

GitHub Actions / Infection Check

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ #[Dependency('php-di/php-di', '^6', 'DI\\ContainerBuilder::addDefinitions and the existence of the DI\\autowire function')] protected function configure() : void { - $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, ['f'], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, ['e'], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, ['l'], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, ['r'], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, ['a'], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); + $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, ['f'], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, ['e'], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, ['l'], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, [], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, ['a'], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); } #[Dependency('symfony/console', '^5', 'InputInterface::getOption and OutputInterface::writeln')] protected function execute(InputInterface $input, OutputInterface $output) : int
InputOption::VALUE_NONE,
'Search root dependencies for the @dependency annotation'
)
->addOption(
self::ALL_DEPS,
['a'],

Check warning on line 106 in src/Controller/Composer/ComposerCommand.php

View workflow job for this annotation

GitHub Actions / Infection Check

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ #[Dependency('php-di/php-di', '^6', 'DI\\ContainerBuilder::addDefinitions and the existence of the DI\\autowire function')] protected function configure() : void { - $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, ['f'], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, ['e'], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, ['l'], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, ['r'], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, ['a'], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); + $this->setName('why-block')->addArgument('package', InputArgument::REQUIRED, 'Package to inspect')->addArgument('version', InputArgument::REQUIRED, 'Version you want to update it to')->addOption(self::OUTPUT_FORMAT, ['f'], InputOption::VALUE_OPTIONAL, 'Format to output results in. Accepted values: text, csv, json, xml', 'text')->addOption(self::FAIL_ON_ERROR, ['e'], InputOption::VALUE_NONE, 'Immediately fail on parsing errors')->addOption(self::LEGACY_ANNOTATION, ['l'], InputOption::VALUE_NONE, 'Include old @dependency/@composerDependency annotations in search')->addOption(self::ROOT_DEPS, ['r'], InputOption::VALUE_NONE, 'Search root dependencies for the @dependency annotation')->addOption(self::ALL_DEPS, [], InputOption::VALUE_NONE, 'Search all dependencies for the @dependency annotation'); } #[Dependency('symfony/console', '^5', 'InputInterface::getOption and OutputInterface::writeln')] protected function execute(InputInterface $input, OutputInterface $output) : int
InputOption::VALUE_NONE,
'Search all dependencies for the @dependency annotation'
);
Expand All @@ -128,13 +129,13 @@
}

$outputFormat = strtolower($outputFormat);
if (!in_array($outputFormat, static::ACCEPTABLE_FORMATS)) {
if (!in_array($outputFormat, self::ACCEPTABLE_FORMATS)) {

Check warning on line 132 in src/Controller/Composer/ComposerCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/Composer/ComposerCommand.php#L132

Added line #L132 was not covered by tests
$outputFormat = 'text';
}

if ($input->getOption(static::ALL_DEPS)) {
if ($input->getOption(self::ALL_DEPS)) {

Check warning on line 136 in src/Controller/Composer/ComposerCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/Composer/ComposerCommand.php#L136

Added line #L136 was not covered by tests
$composerScope = ComposerScopeDeterminer::SCOPE_ALL_DEPENDENCIES;
} elseif ($input->getOption(static::ROOT_DEPS)) {
} elseif ($input->getOption(self::ROOT_DEPS)) {

Check warning on line 138 in src/Controller/Composer/ComposerCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/Composer/ComposerCommand.php#L138

Added line #L138 was not covered by tests
$composerScope = ComposerScopeDeterminer::SCOPE_ROOT_DEPENDENCIES;
} else {
$composerScope = ComposerScopeDeterminer::SCOPE_PROJECT_ONLY;
Expand All @@ -145,22 +146,29 @@
[
InputInterface::class => $input,
OutputInterface::class => $output,
IssueHandlerInterface::class => $input->getOption(static::FAIL_ON_ERROR)
IssueHandlerInterface::class => $input->getOption(self::FAIL_ON_ERROR)

Check warning on line 149 in src/Controller/Composer/ComposerCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/Composer/ComposerCommand.php#L149

Added line #L149 was not covered by tests
? FailOnIssueHandler::class
: NotifyOnIssueHandler::class,
Composer::class => $this->getComposer(true),
ParserInterface::class => static function (ContainerInterface $container) use ($input) {
$parsers = [$container->get(AstParser::class)];
if ($input->getOption(static::LEGACY_ANNOTATION)) {
$parsers[] = $container->get(LegacyParser::class);
$parser = $container->get(AstParser::class);
if (!$parser instanceof ParserInterface) {
throw new RuntimeException('AstParser not found');

Check warning on line 156 in src/Controller/Composer/ComposerCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/Composer/ComposerCommand.php#L154-L156

Added lines #L154 - L156 were not covered by tests
}
$parsers = [$parser];
if ($input->getOption(self::LEGACY_ANNOTATION)) {
$legacyParser = $container->get(LegacyParser::class);
if ($legacyParser instanceof ParserInterface) {
$parsers[] = $legacyParser;

Check warning on line 162 in src/Controller/Composer/ComposerCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/Composer/ComposerCommand.php#L158-L162

Added lines #L158 - L162 were not covered by tests
}
}
return new ParserPool($parsers);
},
WriterInterface::class => autowire(StdOutWriter::class),
ComposerScopeDeterminer::class => autowire(ComposerScopeDeterminer::class)
->property('scope', $composerScope),
ScopeDeterminerInterface::class => autowire(ComposerScopeDeterminer::class),
OutputHandlerInterface::class => autowire(static::FORMAT_MAPPER[$outputFormat]),
OutputHandlerInterface::class => autowire(self::FORMAT_MAPPER[$outputFormat]),

Check warning on line 171 in src/Controller/Composer/ComposerCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/Composer/ComposerCommand.php#L171

Added line #L171 was not covered by tests
]
);
$container = $containerBuilder->build();
Expand Down
26 changes: 19 additions & 7 deletions src/Controller/WhyBlockCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Navarr\Depends\ScopeDeterminer\PhpFileFinder;
use Navarr\Depends\ScopeDeterminer\ScopeDeterminerInterface;
use Psr\Container\ContainerInterface;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -120,7 +121,7 @@
}

$outputFormat = strtolower($outputFormat);
if (!in_array($outputFormat, static::ACCEPTABLE_FORMATS)) {
if (!in_array($outputFormat, self::ACCEPTABLE_FORMATS)) {

Check warning on line 124 in src/Controller/WhyBlockCommandController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/WhyBlockCommandController.php#L124

Added line #L124 was not covered by tests
$outputFormat = 'text';
}

Expand All @@ -129,24 +130,35 @@
[
InputInterface::class => $input,
OutputInterface::class => $output,
IssueHandlerInterface::class => $input->getOption(static::FAIL_ON_ERROR)
IssueHandlerInterface::class => $input->getOption(self::FAIL_ON_ERROR)

Check warning on line 133 in src/Controller/WhyBlockCommandController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/WhyBlockCommandController.php#L133

Added line #L133 was not covered by tests
? FailOnIssueHandler::class
: NotifyOnIssueHandler::class,
ParserInterface::class => static function (ContainerInterface $container) use ($input) {
$parsers = [$container->get(AstParser::class)];
if ($input->getOption(static::LEGACY_ANNOTATION)) {
$parsers[] = $container->get(LegacyParser::class);
$parser = $container->get(AstParser::class);
if (!$parser instanceof ParserInterface) {
throw new RuntimeException('AstParser not found');

Check warning on line 139 in src/Controller/WhyBlockCommandController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/WhyBlockCommandController.php#L137-L139

Added lines #L137 - L139 were not covered by tests
}
$parsers = [$parser];
if ($input->getOption(self::LEGACY_ANNOTATION)) {
$legacyParser = $container->get(LegacyParser::class);
if ($legacyParser instanceof ParserInterface) {
$parsers[] = $legacyParser;

Check warning on line 145 in src/Controller/WhyBlockCommandController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/WhyBlockCommandController.php#L141-L145

Added lines #L141 - L145 were not covered by tests
}
}
return new ParserPool($parsers);
},
WriterInterface::class => autowire(StdOutWriter::class),
ScopeDeterminerInterface::class => static function (ContainerInterface $container) use ($directory) {
$phpFileFinder = $container->get(PhpFileFinder::class);
if (!$phpFileFinder instanceof PhpFileFinder) {
throw new RuntimeException('PhpFileFinder not found');

Check warning on line 154 in src/Controller/WhyBlockCommandController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/WhyBlockCommandController.php#L152-L154

Added lines #L152 - L154 were not covered by tests
}
return new DirectoryScopeDeterminer(
$container->get(PhpFileFinder::class),
$phpFileFinder,

Check warning on line 157 in src/Controller/WhyBlockCommandController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/WhyBlockCommandController.php#L157

Added line #L157 was not covered by tests
$directory
);
},
OutputHandlerInterface::class => autowire(static::FORMAT_MAPPER[$outputFormat]),
OutputHandlerInterface::class => autowire(self::FORMAT_MAPPER[$outputFormat]),

Check warning on line 161 in src/Controller/WhyBlockCommandController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/WhyBlockCommandController.php#L161

Added line #L161 was not covered by tests
]
);
$container = $containerBuilder->build();
Expand Down
7 changes: 6 additions & 1 deletion src/Factory/CollectingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use DI\NotFoundException;
use Navarr\Attribute\Dependency;
use PhpParser\ErrorHandler\Collecting;
use RuntimeException;

#[Dependency('php-di/php-di', '^6', 'Container::make')]
#[Dependency('nikic/php-parser', '^4', 'Existence of Collecting error handler')]
Expand All @@ -32,6 +33,10 @@
*/
public function create(): Collecting
{
return $this->container->make(Collecting::class);
$result = $this->container->make(Collecting::class);
if (!$result instanceof Collecting) {

Check warning on line 37 in src/Factory/CollectingFactory.php

View workflow job for this annotation

GitHub Actions / Infection Check

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ public function create() : Collecting { $result = $this->container->make(Collecting::class); - if (!$result instanceof Collecting) { + if (!true) { throw new RuntimeException('Container did not return a Collecting'); } return $result; } }
throw new RuntimeException('Container did not return a Collecting');
}

Check warning on line 39 in src/Factory/CollectingFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factory/CollectingFactory.php#L38-L39

Added lines #L38 - L39 were not covered by tests
return $result;
}
}
7 changes: 6 additions & 1 deletion src/Factory/FindingVisitorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use DI\NotFoundException;
use Navarr\Attribute\Dependency;
use PhpParser\NodeVisitor\FindingVisitor;
use RuntimeException;

#[Dependency('php-di/php-di', '^6', 'Container::make')]
#[Dependency('nikic/php-parser', '^4', 'Existence of FindingVisitor')]
Expand All @@ -33,6 +34,10 @@
*/
public function create(array $args = []): FindingVisitor
{
return $this->container->make(FindingVisitor::class, $args);
$result = $this->container->make(FindingVisitor::class, $args);
if (!$result instanceof FindingVisitor) {

Check warning on line 38 in src/Factory/FindingVisitorFactory.php

View workflow job for this annotation

GitHub Actions / Infection Check

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ public function create(array $args = []) : FindingVisitor { $result = $this->container->make(FindingVisitor::class, $args); - if (!$result instanceof FindingVisitor) { + if (!true) { throw new RuntimeException('Container did not return a FindingVisitor'); } return $result; } }
throw new RuntimeException('Container did not return a FindingVisitor');
}
return $result;
}
}
7 changes: 6 additions & 1 deletion src/Factory/NodeTraverserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use DI\NotFoundException;
use Navarr\Attribute\Dependency;
use PhpParser\NodeTraverser;
use RuntimeException;

#[Dependency('php-di/php-di', '^6', 'Container::make')]
#[Dependency('nikic/php-parser', '^4', 'Existence of NodeTraverser')]
Expand All @@ -33,6 +34,10 @@
*/
public function create(array $args = []): NodeTraverser
{
return $this->container->make(NodeTraverser::class, $args);
$result = $this->container->make(NodeTraverser::class, $args);
if (!$result instanceof NodeTraverser) {
throw new RuntimeException('Container did not return a NodeTraverser');

Check warning on line 39 in src/Factory/NodeTraverserFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factory/NodeTraverserFactory.php#L39

Added line #L39 was not covered by tests
}
return $result;
}
}
1 change: 1 addition & 0 deletions src/Parser/AstParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function parse(

$traverser->traverse($ast);

/** @var Attribute[] $attributes Since we have a filter callback, this will always be an Attribute */
$attributes = $finder->getFoundNodes();

$argIndex = [
Expand Down
12 changes: 6 additions & 6 deletions src/Parser/LegacyParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ public function parse(string $contents): array
}

/**
* @param string[][] $matches
* @param array<array<int, array<int, int|string>>> $matches
* @param string $contents
* @return DeclaredDependency[]
*/
private function processMatches(array $matches, string $contents): array
{
$results = [];

$matchCount = count($matches[0]) ?? 0;
$matchCount = count($matches[0]) ?: 0;
for ($match = 0; $match < $matchCount; ++$match) {
$package = strtolower($matches[static::INLINE_MATCH_PACKAGE][$match][0]);
$version = $matches[static::INLINE_MATCH_VERSION][$match][0];
$package = strtolower((string)$matches[self::INLINE_MATCH_PACKAGE][$match][0]);
$version = (string)$matches[self::INLINE_MATCH_VERSION][$match][0] ?: null;

$line = substr_count(mb_substr($contents, 0, (int)$matches[0][$match][1]), "\n") + 1;

$reason = trim($matches[static::INLINE_MATCH_REASON][$match][0]) ?? 'No reason provided';
if (substr($reason, -2) === '*/') {
$reason = trim((string)$matches[self::INLINE_MATCH_REASON][$match][0]) ?: 'No reason provided';
if (str_ends_with($reason, '*/')) {
$reason = trim(substr($reason, 0, -2));
}

Expand Down
28 changes: 17 additions & 11 deletions src/ScopeDeterminer/ComposerScopeDeterminer.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
* Retrieve all PHP files out of the directories and files listed in the autoload directive
*
* @param string $basePath Base directory of the package who's autoload we're processing
* @param array<array> $autoload Result of {@see PackageInterface::getAutoload()}
* @param array<string, array<int|string, array<string>|string>> $autoload
* Result of {@see PackageInterface::getAutoload()}
* @param string[] $results Array of file paths to merge with
* @return string[] File paths
*/
Expand All @@ -123,17 +124,22 @@
array $results = []
): array {
foreach ($autoload as $map) {
foreach ($map as $dir) {
$realDir = realpath($basePath . DIRECTORY_SEPARATOR . $dir);
if ($realDir === false) {
continue;
foreach ($map as $dirs) {
if (is_string($dirs)) {
$dirs = [$dirs];

Check warning on line 129 in src/ScopeDeterminer/ComposerScopeDeterminer.php

View check run for this annotation

Codecov / codecov/patch

src/ScopeDeterminer/ComposerScopeDeterminer.php#L127-L129

Added lines #L127 - L129 were not covered by tests
}
if (is_file($realDir)) {
$results[] = $realDir;
continue;
}
if (is_dir($realDir)) {
$results = $this->phpFileFinder->findAll($dir, $results);
foreach ($dirs as $dir) {
$realDir = realpath($basePath . DIRECTORY_SEPARATOR . $dir);
if ($realDir === false) {
continue;

Check warning on line 134 in src/ScopeDeterminer/ComposerScopeDeterminer.php

View check run for this annotation

Codecov / codecov/patch

src/ScopeDeterminer/ComposerScopeDeterminer.php#L131-L134

Added lines #L131 - L134 were not covered by tests
}
if (is_file($realDir)) {
$results[] = $realDir;
continue;

Check warning on line 138 in src/ScopeDeterminer/ComposerScopeDeterminer.php

View check run for this annotation

Codecov / codecov/patch

src/ScopeDeterminer/ComposerScopeDeterminer.php#L136-L138

Added lines #L136 - L138 were not covered by tests
}
if (is_dir($realDir)) {
$results = $this->phpFileFinder->findAll($dir, $results);

Check warning on line 141 in src/ScopeDeterminer/ComposerScopeDeterminer.php

View check run for this annotation

Codecov / codecov/patch

src/ScopeDeterminer/ComposerScopeDeterminer.php#L140-L141

Added lines #L140 - L141 were not covered by tests
}
}
}
}
Expand Down
Loading
Loading