Skip to content
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
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
"sebastian/diff": "^5.1.1|^6.0.2|^7.0.0",
"slevomat/coding-standard": "^8.22.1",
"squizlabs/php_codesniffer": "^3.13.4",
"symfony/cache": "^6.4.20|^7.3.4",
"symfony/console": "^6.4.20|^7.3.4",
"symfony/finder": "^6.4.17|^7.3.2",
"symfony/http-client": "^6.4.19|^7.3.4",
"symfony/process": "^6.4.20|^7.3.4"
"symfony/cache": "^6.4.20|^7.3.4|^8.0",
"symfony/console": "^6.4.20|^7.3.4|^8.0",
"symfony/finder": "^6.4.17|^7.3.2|^8.0",
"symfony/http-client": "^6.4.19|^7.3.4|^8.0",
"symfony/process": "^6.4.20|^7.3.4|^8.0"
},
"require-dev": {
"illuminate/console": "^10.48.28|^11.44.2|^12.33",
"illuminate/support": "^10.48.28|^11.44.2|^12.33",
"mockery/mockery": "^1.6.12",
"phpstan/phpstan": "^2.1.31",
"phpunit/phpunit": "^10.5.45|^11.5.42",
"symfony/var-dumper": "^6.4.18|^7.3.4"
"symfony/var-dumper": "^6.4.18|^7.3.4|^8.0"
},
"suggest": {
"ext-simplexml": "It is needed for the checkstyle formatter"
Expand Down
49 changes: 32 additions & 17 deletions src/Domain/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ final class Analyser
public function __call(string $method, array $args): mixed
{
$method = new ReflectionMethod(BaseAnalyser::class, $method);
$method->setAccessible(true);

return $method->invoke(new BaseAnalyser(), ...$args);
}
Expand Down Expand Up @@ -175,8 +174,10 @@ private function analyseFile(Collector $collector, string $filename): void
$collector->incrementTraits();
} elseif ($token === \T_INTERFACE) {
$collector->incrementInterfaces();
} elseif (isset($tokens[$i - 2]) &&
\is_array($tokens[$i - 2])) {
} elseif (
isset($tokens[$i - 2]) &&
\is_array($tokens[$i - 2])
) {
if ($tokens[$i - 2][0] === \T_ABSTRACT || $tokens[$i - 2][0] === \T_READONLY && $tokens[$i - 4][0] === \T_ABSTRACT) {
$collector->addAbstractClass($filename);
} elseif ($tokens[$i - 2][0] === \T_FINAL || $tokens[$i - 2][0] === \T_READONLY && $tokens[$i - 4][0] === \T_FINAL) {
Expand Down Expand Up @@ -205,8 +206,10 @@ private function analyseFile(Collector $collector, string $filename): void
$next = $this->getNextNonWhitespaceTokenPos($tokens, $next);
}

if (\is_array($tokens[$next]) &&
$tokens[$next][0] === \T_STRING) {
if (
\is_array($tokens[$next]) &&
$tokens[$next][0] === \T_STRING
) {
$functionName = $tokens[$next][1];
} else {
$currentBlock = 'anonymous function';
Expand All @@ -215,18 +218,22 @@ private function analyseFile(Collector $collector, string $filename): void
}

if ($currentBlock === \T_FUNCTION) {
if ($className === null &&
$functionName !== 'anonymous function') {
if (
$className === null &&
$functionName !== 'anonymous function'
) {
$collector->addNamedFunctions($functionName);
} else {
$static = false;
$visibility = \T_PUBLIC;

for ($j = $i; $j > 0; $j--) {
if (\is_string($tokens[$j])) {
if ($tokens[$j] === '{' ||
if (
$tokens[$j] === '{' ||
$tokens[$j] === '}' ||
$tokens[$j] === ';') {
$tokens[$j] === ';'
) {
break;
}

Expand Down Expand Up @@ -317,15 +324,19 @@ private function analyseFile(Collector $collector, string $filename): void
break;

case \T_STRING:
if ($value === 'define'
if (
$value === 'define'
&& $tokens[$i - 1][1] !== '::'
&& $tokens[$i - 1][1] !== '->'
&& (! isset($tokens[$i - 2][1]) || $tokens[$i - 2][1] !== 'function')) {
&& (! isset($tokens[$i - 2][1]) || $tokens[$i - 2][1] !== 'function')
) {
$j = $i + 1;

while (isset($tokens[$j]) && $tokens[$j] !== ';') {
if (\is_array($tokens[$j]) &&
$tokens[$j][0] === \T_CONSTANT_ENCAPSED_STRING) {
if (
\is_array($tokens[$j]) &&
$tokens[$j][0] === \T_CONSTANT_ENCAPSED_STRING
) {
$collector->addGlobalConstant(\str_replace('\'', '', $tokens[$j][1]));

break;
Expand All @@ -344,18 +355,22 @@ private function analyseFile(Collector $collector, string $filename): void
$n = $this->getNextNonWhitespaceTokenPos($tokens, $i);
$nn = $this->getNextNonWhitespaceTokenPos($tokens, $n);

if ((bool) $n && (bool) $nn &&
if (
(bool) $n && (bool) $nn &&
isset($tokens[$n][0]) &&
($tokens[$n][0] === \T_STRING ||
$tokens[$n][0] === \T_VARIABLE) &&
$tokens[$nn] === '(') {
$tokens[$nn] === '('
) {
if ($token === \T_DOUBLE_COLON) {
$collector->incrementStaticMethodCalls();
} else {
$collector->incrementNonStaticMethodCalls();
}
} elseif ($token === \T_DOUBLE_COLON &&
$tokens[$n][0] === \T_VARIABLE) {
} elseif (
$token === \T_DOUBLE_COLON &&
$tokens[$n][0] === \T_VARIABLE
) {
$collector->incrementStaticAttributeAccesses();
} elseif ($token === \T_OBJECT_OPERATOR) {
$collector->incrementNonStaticAttributeAccesses();
Expand Down
13 changes: 7 additions & 6 deletions src/Domain/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,17 @@ private function resolveConfig(array $config): void
$resolver->setDefined('timeout');
$resolver->setAllowedValues(
'preset',
array_map(static fn (string $presetClass) => $presetClass::getName(), self::PRESETS)
array_map(static fn(string $presetClass) => $presetClass::getName(), self::PRESETS)
);

$resolver->setAllowedValues('add', $this->validateAddedInsight());
$resolver->setAllowedValues('config', $this->validateConfigInsights());
$resolver->setAllowedValues('requirements', $this->validateRequirements());
$resolver->setAllowedTypes('threads', ['null', 'int']);
$resolver->setAllowedTypes('diff_context', 'int');
$resolver->setAllowedValues('diff_context', static fn ($value) => $value >= 0);
$resolver->setAllowedValues('threads', static fn ($value) => $value === null || $value >= 1);
$resolver->setAllowedValues('timeout', static fn ($value) => $value >= 0);
$resolver->setAllowedValues('diff_context', static fn($value) => $value >= 0);
$resolver->setAllowedValues('threads', static fn($value) => $value === null || $value >= 1);
$resolver->setAllowedValues('timeout', static fn($value) => $value >= 0);

try {
$config = $resolver->resolve($config);
Expand Down Expand Up @@ -328,10 +328,11 @@ private function validateAddedInsight(): Closure
{
return static function ($values): bool {
foreach ($values as $metric => $insights) {
$interfaces = class_implements($metric);
if (
! class_exists($metric) ||
class_implements($metric) === false ||
! in_array(Metric::class, class_implements($metric), true)
!is_array($interfaces) ||
! in_array(Metric::class, $interfaces, true)
) {
throw new InvalidConfiguration(sprintf(
'Unable to use "%s" class as metric in section add.',
Expand Down
5 changes: 3 additions & 2 deletions src/Domain/InsightLoader/FixerLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ final class FixerLoader implements InsightLoader
{
public function support(string $insightClass): bool
{
if (class_implements($insightClass) === false) {
$interfaces = class_implements($insightClass);
if (!is_array($interfaces)) {
return false;
}
return array_key_exists(FixerInterface::class, class_implements($insightClass));
return array_key_exists(FixerInterface::class, $interfaces);
}

public function load(string $insightClass, string $dir, array $config, Collector $collector): Insight
Expand Down
5 changes: 3 additions & 2 deletions src/Domain/InsightLoader/InsightLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ final class InsightLoader implements LoaderContract
{
public function support(string $insightClass): bool
{
if (class_implements($insightClass) === false) {
$interfaces = class_implements($insightClass);
if (!is_array($interfaces)) {
return false;
}
return array_key_exists(Insight::class, class_implements($insightClass));
return array_key_exists(Insight::class, $interfaces);
}

public function load(string $insightClass, string $dir, array $config, Collector $collector): Insight
Expand Down
11 changes: 7 additions & 4 deletions src/Domain/InsightLoader/SniffLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ final class SniffLoader implements InsightLoader
{
public function support(string $insightClass): bool
{
if (class_implements($insightClass) === false) {
$interfaces = class_implements($insightClass);
if (!is_array($interfaces)) {
return false;
}
return array_key_exists(SniffContract::class, class_implements($insightClass));
return array_key_exists(SniffContract::class, $interfaces);
}

public function load(string $insightClass, string $dir, array $config, Collector $collector): Insight
Expand All @@ -37,9 +38,11 @@ public function load(string $insightClass, string $dir, array $config, Collector
}

foreach ($config as $property => $value) {
$sniff->{$property} = $value;
if (property_exists($sniff, $property)) {
$sniff->{$property} = $value;
}
}

return new SniffDecorator($sniff, $dir, $excludeConfig);
}
}
}