Skip to content
Merged
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"require": {
"php": ">=8.1",
"nette/php-generator": "^4.0",
"okapi/code-transformer": "1.3.7",
"okapi/code-transformer": "1.3.8",
"okapi/wildcards": "^1.0",
"okapi/singleton": "^1.0",
"php-di/php-di": "^7.0"
Expand Down
5 changes: 5 additions & 0 deletions mago-tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ excludes = ["tests/cache", "tests/coverage"]
[linter]
integrations = ["phpunit"]

[linter.rules.disallowed-functions]
enabled = true
level = "error"
functions = ["assert"]

# Preserve the library's coercion contract and existing public call signatures.
[linter.rules.strict-types]
enabled = false
Expand Down
5 changes: 5 additions & 0 deletions mago.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ excludes = ["tests/cache", "tests/coverage"]
[linter]
integrations = ["phpunit"]

[linter.rules.disallowed-functions]
enabled = true
level = "error"
functions = ["assert"]

# Preserve the library's coercion contract and existing public call signatures.
[linter.rules.strict-types]
enabled = false
Expand Down
2 changes: 1 addition & 1 deletion src/AopKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ abstract class AopKernel extends CodeTransformerKernel
/**
* The exclude paths. Paths/directories in this array will be excluded
*
* @var array
* @var string[]
*/
protected array $excludePaths = [];

Expand Down
10 changes: 3 additions & 7 deletions src/Core/AutoloadInterceptor/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ class ClassLoader extends CodeTransformerClassLoader
/**
* Find the path to the file and match and apply the aspects.
*
* @param class-string $namespacedClass
* @param string $class
*
* @return false|string
*
* @noinspection PhpStatementHasEmptyBodyInspection
*/
// CodeTransformer uses $namespacedClass; its Composer parent uses $class.
// Keep our immediate parent's existing named-argument contract until that dependency is aligned.
public function findFile($namespacedClass): false|string
public function findFile($class): false|string
{
$namespacedClass = $class;
$filePath = $this->originalClassLoader->findFile($namespacedClass);

// @codeCoverageIgnoreStart
Expand All @@ -63,7 +60,6 @@ public function findFile($namespacedClass): false|string
return false;
}

/** @var string[] $excludePaths */
$excludePaths = $this->options->getExcludePaths();
foreach ($excludePaths as $path) {
$resolvedPath = Path::resolve($path);
Expand Down
9 changes: 7 additions & 2 deletions src/Core/Transform/ProxiedClassModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Okapi\Aop\Core\Transform;

use DI\Attribute\Inject;
use LogicException;
use Microsoft\PhpParser\Node;
use Microsoft\PhpParser\Token;
use Microsoft\PhpParser\TokenKind;
Expand Down Expand Up @@ -142,7 +143,9 @@ private function convertToProxy(): void
{
// Find the class declaration
$node = $this->sourceFileNode->getFirstDescendantNode(Node\Statement\ClassDeclaration::class);
assert($node instanceof Node\Statement\ClassDeclaration, 'The transformed source must declare a class.');
if (!$node instanceof Node\Statement\ClassDeclaration) {
throw new LogicException('The transformed source must declare a class.');
}

// Replace the class name
$this->edit($node->name, $this->proxiedClassName);
Expand Down Expand Up @@ -312,7 +315,9 @@ private function replaceMagicConstants(): void
if (!$methodNode) {
break;
}
assert($methodNode instanceof Node\MethodDeclaration, 'The enclosing node must be a method.');
if (!$methodNode instanceof Node\MethodDeclaration) {
throw new LogicException('The enclosing node must be a method.');
}

$originalNamespacedClassName = $this->code->getNamespacedClass();
$originalMethodName = $methodNode->getName();
Expand Down
4 changes: 2 additions & 2 deletions tests/ClassLoaderMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private function findClassMock(string $class): string
$this->findClassLoader();
}

assert($this->classLoader instanceof ClassLoader, 'The invocation must match the configured test fixture.');
Assert::assertInstanceOf(ClassLoader::class, $this->classLoader);
/** @var mixed $file */
$file = $this->classLoader->findFile($class);
Assert::assertIsString($file);
Expand All @@ -33,7 +33,7 @@ private function findOriginalClassMock(string $class): string
$this->findClassLoader();
}

assert($this->classLoader instanceof ClassLoader, 'The invocation must match the configured test fixture.');
Assert::assertInstanceOf(ClassLoader::class, $this->classLoader);
$original = new ReflectionProperty(ClassLoader::class, 'originalClassLoader');
/** @var mixed $loader */
$loader = $original->getValue($this->classLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Okapi\Aop\Invocation\MethodInvocation;
use Okapi\Aop\Tests\Functional\AdviceBehavior\BeforeAroundAfterAdviceOnSameAdviceMethod\Target\Calculator;
use Okapi\Aop\Tests\Stubs\Etc\Logger;
use PHPUnit\Framework\Assert;

#[Aspect]
class CalculatorLoggerAspect
Expand All @@ -30,8 +31,9 @@ public function logCalculation(MethodInvocation $invocation): void
}

if ($adviceType === AdviceType::Around) {
assert(
$invocation instanceof AroundMethodInvocation,
Assert::assertInstanceOf(
AroundMethodInvocation::class,
$invocation,
'The invocation must match the configured test fixture.',
);

Expand All @@ -45,8 +47,9 @@ public function logCalculation(MethodInvocation $invocation): void
}

if ($adviceType === AdviceType::After) {
assert(
$invocation instanceof \Okapi\Aop\Invocation\AfterMethodInvocation,
Assert::assertInstanceOf(
\Okapi\Aop\Invocation\AfterMethodInvocation::class,
$invocation,
'The invocation must match the configured test fixture.',
);
/** @var int $result */
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/TransformerAndAspect/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Kernel extends AopKernel
{
protected ?string $cacheDir = Util::CACHE_DIR;

/** @var array<array-key, class-string<\Okapi\CodeTransformer\Transformer>> */
/** @var array<array-key, mixed> */
protected array $transformers = [
FixIncorrectFunctionTransformer::class,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function dependencyInjectionHandler(): ?Closure
Aspect::class,
];

/** @var array<array-key, class-string<\Okapi\CodeTransformer\Transformer>> */
/** @var array<array-key, mixed> */
protected array $transformers = [
Transformer::class,
];
Expand Down
Loading