Skip to content

Commit 4e3a1f3

Browse files
committed
Fix potential issues reported by PHPStan and PHPCS
1 parent 06c2ec2 commit 4e3a1f3

File tree

11 files changed

+27
-26
lines changed

11 files changed

+27
-26
lines changed

.module.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ EXTENSION_VENDOR="Yireo"
22
EXTENSION_NAME="ExtensionChecker"
33
COMPOSER_NAME="yireo/magento2-extensionchecker"
44
PHP_VERSIONS=("8.1", "8.2", "8.3","8.4")
5+
PHPSTAN_LEVEL=1
6+
PHPCS_SEVERITY=9

ComponentCollector/AbstractComponentCollector.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Yireo\ExtensionChecker\ComponentCollector;
44

5-
use Magento\Framework\Exception\FileSystemException;
6-
use Magento\Framework\Exception\NotFoundException;
75
use Yireo\ExtensionChecker\Component\Component;
86
use Yireo\ExtensionChecker\Component\ComponentFactory;
97
use Yireo\ExtensionChecker\PhpClass\ComponentCollector;
@@ -26,9 +24,8 @@ public function __construct(
2624

2725
/**
2826
* @param string $content
27+
* @param bool $hardRequirement
2928
* @return Component[]
30-
* @throws FileSystemException
31-
* @throws NotFoundException
3229
*/
3330
protected function findComponentsByModuleName(string $content, bool $hardRequirement = false): array
3431
{
@@ -47,9 +44,8 @@ protected function findComponentsByModuleName(string $content, bool $hardRequire
4744

4845
/**
4946
* @param string $content
47+
* @param bool $hardRequirement
5048
* @return Component[]
51-
* @throws FileSystemException
52-
* @throws NotFoundException
5349
*/
5450
protected function findComponentsByClassName(string $content, bool $hardRequirement = false): array
5551
{
@@ -79,9 +75,8 @@ protected function findComponentsByClassName(string $content, bool $hardRequirem
7975
/**
8076
* @param string $contents
8177
* @param array $patterns
78+
* @param bool $hardRequirement
8279
* @return Component[]
83-
* @throws FileSystemException
84-
* @throws NotFoundException
8580
*/
8681
protected function findComponentsByPattern(string $contents, array $patterns, bool $hardRequirement = false): array
8782
{

ComponentCollector/TemplateComponentCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424

2525
/**
2626
* @param string $file
27-
* @return Component
27+
* @return Component[]
2828
* @throws FileSystemException
2929
* @throws NotFoundException
3030
*/

ComponentDetector/ComponentDetectorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface ComponentDetectorInterface
88
{
99
/**
1010
* @param string $moduleName
11-
* @return Component
11+
* @return Component[]
1212
*/
1313
public function getComponentsByModuleName(string $moduleName): array;
1414
}

ComponentDetector/ComponentDetectorList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getComponentsByModuleName(string $moduleName): array
4848

4949
/**
5050
* @param Component[] $components
51-
* @return void
51+
* @return Component[]
5252
*/
5353
private function filterSoftAndHardDuplicates(array $components): array
5454
{

ComponentDetector/JsComponentDetector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class JsComponentDetector implements ComponentDetectorInterface
1111
{
1212
/**
1313
* @param string $moduleName
14-
* @return Component
14+
* @return Component[]
1515
*/
1616
public function getComponentsByModuleName(string $moduleName): array
1717
{

ComponentDetector/TemplateComponentDetector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Yireo\ExtensionChecker\ComponentDetector;
44

5+
use Magento\Framework\Exception\FileSystemException;
6+
use Magento\Framework\Exception\NotFoundException;
57
use Yireo\ExtensionChecker\Component\Component;
68
use Yireo\ExtensionChecker\File\FileCollectorInterface;
79
use Yireo\ExtensionChecker\Util\ModuleInfo;
@@ -29,6 +31,8 @@ public function __construct(
2931
/**
3032
* @param string $moduleName
3133
* @return Component[]
34+
* @throws FileSystemException
35+
* @throws NotFoundException
3236
*/
3337
public function getComponentsByModuleName(string $moduleName): array
3438
{

Console/Command/InspectClassCommand.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,29 @@
1111

1212
namespace Yireo\ExtensionChecker\Console\Command;
1313

14-
use InvalidArgumentException;
15-
use Magento\Framework\Serialize\SerializerInterface;
1614
use ReflectionException;
1715
use Symfony\Component\Console\Command\Command;
1816
use Symfony\Component\Console\Helper\Table;
1917
use Symfony\Component\Console\Input\InputArgument;
2018
use Symfony\Component\Console\Input\InputInterface as Input;
21-
use Symfony\Component\Console\Input\InputOption;
2219
use Symfony\Component\Console\Output\OutputInterface as Output;
2320
use Yireo\ExtensionChecker\PhpClass\ClassInspector;
2421

2522
class InspectClassCommand extends Command
2623
{
27-
private SerializerInterface $serializer;
2824
private ClassInspector $classInspector;
2925

3026
/**
3127
* DeleteRuleCommand constructor.
3228
*
33-
* @param SerializerInterface $serializer
34-
* @param ModuleCollector $moduleCollector
29+
* @param ClassInspector $classInspector
3530
* @param null $name
3631
*/
3732
public function __construct(
38-
SerializerInterface $serializer,
3933
ClassInspector $classInspector,
4034
$name = null
4135
) {
4236
parent::__construct($name);
43-
$this->serializer = $serializer;
4437
$this->classInspector = $classInspector;
4538
}
4639

File/FileCollector.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Yireo\ExtensionChecker\File;
44

5+
use Magento\Framework\Exception\FileSystemException;
6+
use Magento\Framework\Exception\ValidatorException;
57
use Magento\Framework\Filesystem\Directory\ReadFactory as DirectoryReadFactory;
68
use Symfony\Component\Finder\FinderFactory;
79
use Yireo\ExtensionChecker\Exception\NoFilesFoundException;
@@ -33,9 +35,10 @@ public function __construct(
3335
}
3436

3537
/**
36-
* @param string $folder
38+
* @param string $moduleFolder
3739
* @return array
38-
* @throws NoFilesFoundException
40+
* @throws FileSystemException
41+
* @throws ValidatorException
3942
*/
4043
public function getFilesFromModuleFolder(string $moduleFolder): array
4144
{

PhpClass/ClassInspector.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Magento\Framework\ObjectManager\ConfigInterface;
88
use ReflectionClass;
99
use ReflectionException;
10+
use ReflectionNamedType;
1011
use Throwable;
1112
use Yireo\ExtensionChecker\Component\Component;
1213
use Yireo\ExtensionChecker\Component\ComponentFactory;
@@ -137,7 +138,12 @@ public function getDependenciesFromConstructor(): array
137138
continue;
138139
}
139140

140-
$dependency = $this->normalizeClassName($parameter->getType()->getName());
141+
$parameterType = $parameter->getType();
142+
if (false === $parameterType instanceof ReflectionNamedType) {
143+
continue;
144+
}
145+
146+
$dependency = $this->normalizeClassName($parameterType->getName());
141147
if (!$this->isClassExists($dependency)) {
142148
continue;
143149
}
@@ -150,7 +156,7 @@ public function getDependenciesFromConstructor(): array
150156
continue;
151157
}
152158

153-
$dependencies[] = $this->normalizeClassName($parameter->getType()->getName());
159+
$dependencies[] = $this->normalizeClassName($parameterType->getName());
154160
}
155161

156162
return $dependencies;

0 commit comments

Comments
 (0)