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
14 changes: 7 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ jobs:
with:
php: "8.5"

test83:
test84:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.3"
php: "8.4"

test82:
test83:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.2"
php: "8.3"

test81:
test82:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.1"
php: "8.2"

testlower:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.1"
php: "8.2"
composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest"
40 changes: 20 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"nette/di": "^3.1.8",
"nette/php-generator": "^3.6.9|^4.1.2",
"php": ">=8.2",
"nette/di": "^3.2.5",
"nette/php-generator": "^4.1.6",
"nette/tokenizer": "^3.1.1",
"symfony/property-access": "^6.4.0|^7.0.0"
},
"require-dev": {
"nette/application": "^3.1.14",
"nette/bootstrap": "^3.2.1",
"nette/caching": "^3.2.3",
"nette/component-model": "^3.0.3",
"nette/database": "^3.1.9",
"nette/finder": "^2.6.0",
"nette/forms": "^3.1.14",
"nette/http": "^3.2.3",
"nette/mail": "^3.1.11",
"nette/neon": "^3.4.1",
"nette/robot-loader": "^3.4.2",
"nette/safe-stream": "^2.5.1",
"nette/security": "^3.1.8",
"nette/utils": "^3.2.10",
"latte/latte": "^2.10|^3.0",
"tracy/tracy": "^2.10.5",
"doctrine/collections": "^1.8.0",
"nette/application": "^3.2.9",
"nette/bootstrap": "^3.2.4",
"nette/caching": "^3.3",
"nette/component-model": "^3.1",
"nette/database": "^3.2",
"nette/finder": "^3.0",
"nette/forms": "^3.2",
"nette/http": "^3.3",
"nette/mail": "^4.0",
"nette/neon": "^3.4",
"nette/robot-loader": "^4.0",
"nette/safe-stream": "^3.0",
"nette/security": "^3.2",
"nette/utils": "^4.0",
"latte/latte": "^3.0",
"tracy/tracy": "^2.10",
"doctrine/collections": "^2.0",
"contributte/qa": "^0.4.0",
"contributte/phpstan": "^0.2.0",
"contributte/phpunit": "^0.2.0"
Expand Down
3 changes: 1 addition & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ includes:

parameters:
level: 7
phpVersion: 80100
phpVersion: 80200

scanDirectories:
- src
Expand All @@ -20,7 +20,6 @@ parameters:
- .docs

treatPhpDocTypesAsCertain: false
checkGenericClassInNonGenericObjectType: false

ignoreErrors:
- '#^Property Contributte\\Aop\\Pointcut\\Matcher\\FilterMatcher\:\:\$filter \(Contributte\\Aop\\Pointcut\\Filter\) does not accept object\.$#'
Expand Down
2 changes: 1 addition & 1 deletion ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Contributte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<!-- Rulesets -->
<rule ref="./vendor/contributte/qa/ruleset-8.0.xml">
<rule ref="./vendor/contributte/qa/ruleset-8.2.xml">
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.PartialUse"/>
</rule>

Expand Down
3 changes: 3 additions & 0 deletions src/JoinPoint/MethodInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public function getArguments(): array
return $this->arguments;
}

/**
* @return ReflectionClass<object>
*/
public function getTargetObjectReflection(): ReflectionClass
{
return new ReflectionClass($this->targetObject);
Expand Down
11 changes: 6 additions & 5 deletions src/PhpGenerator/AdvisedClassType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AdvisedClassType
public static function setMethodInstance(Code\ClassType $class, Code\Method $method): Code\Method
{
$methods = [$method->getName() => $method] + $class->getMethods();
$class->setMethods($methods);
$class->setMethods(array_values($methods));

return $method;
}
Expand All @@ -32,23 +32,24 @@ public static function generatePublicProxyMethod(Code\ClassType $class, Code\Met
$argumentsPass = [];
$args = [];
foreach ($originalMethod->getParameters() as $parameter) {
if($parameter instanceof Code\PromotedParameter) {
if ($parameter instanceof Code\PromotedParameter) {
$promotedParameter = $parameter;
$parameter = new Code\Parameter($promotedParameter->getName());
$parameter->setType($promotedParameter->getType());
if($promotedParameter->hasDefaultValue()) {
if ($promotedParameter->hasDefaultValue()) {
$parameter->setDefaultValue($promotedParameter->getDefaultValue());
}

$parameter->setNullable($promotedParameter->isNullable());
}
/** @var Code\Parameter $parameter */

$argumentsPass[] = '$' . $parameter->getName();
$args[$parameter->getName()] = $parameter;
}

$proxyMethod->addBody('return parent::?(?);', [$originalMethod->getName(), new Code\PhpLiteral(implode(', ', $argumentsPass))]);

$proxyMethod->setParameters($args);
$proxyMethod->setParameters(array_values($args));
self::setMethodInstance($class, $proxyMethod);
}

Expand Down
12 changes: 5 additions & 7 deletions src/PhpGenerator/PointcutMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ public static function from(ReflectionMethod $from): PointcutMethod
$params[$param->getName()] = $factory->fromParameterReflection($param);
}

$method->method->setParameters($params);
if ($from instanceof ReflectionMethod) {
$isInterface = $from->getDeclaringClass()->isInterface();
$method->method->setParameters(array_values($params));
$isInterface = $from->getDeclaringClass()->isInterface();
$method->method->setStatic($from->isStatic());
$method->method->setVisibility($from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : ($isInterface ? null : 'public')));
$method->method->setFinal($from->isFinal());
$method->method->setAbstract($from->isAbstract() && !$isInterface);
$method->method->setBody($from->isAbstract() ? null : '');
}
$method->method->setAbstract($from->isAbstract() && !$isInterface);
$method->method->setBody($from->isAbstract() ? null : '');

$method->method->setReturnReference($from->returnsReference());
$method->method->setVariadic($from->isVariadic());
Expand Down Expand Up @@ -114,7 +112,7 @@ public static function expandTypeHints(ReflectionMethod $from, PointcutMethod $m
}
}

$method->method->setParameters($parameters);
$method->method->setParameters(array_values($parameters));

if (!$method->method->getVisibility()) {
$method->method->setVisibility('public');
Expand Down
2 changes: 1 addition & 1 deletion src/Pointcut/AspectAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function analyze(ServiceDefinition $service): array
}

/**
* @param ReflectionAttribute[] $attributes
* @param array<ReflectionAttribute<object>> $attributes
* @return AdviceAttribute[]
*/
private function getAopAdviceAttributes(array $attributes): array
Expand Down
2 changes: 1 addition & 1 deletion src/Pointcut/Matcher/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private static function resolveExpression(Code\Literal $expression): mixed
}

/**
* @return array<string, string>|NULL
* @return array<int|string, string>|null
*/
private static function shiftAccessPath(string $path): ?array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Pointcut/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public function getTypesWithin(): array
}

/**
* @return ReflectionAttribute[]
* @return array<ReflectionAttribute<object>>
*/
public function getAttributes(): array
{
return $this->method->getAttributes();
}

/**
* @return ReflectionAttribute[]
* @return array<ReflectionAttribute<object>>
*/
public function getClassAttributes(): array
{
Expand Down
18 changes: 8 additions & 10 deletions src/Pointcut/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,18 @@ public function __construct(array $rules = [], string $operator = self::OP_AND)
*/
public static function unwrap(array $filter, string $operator = self::OP_AND): Filter
{
if (is_array($filter)) {
if (count($filter) > 1) {
return new Rules($filter, $operator);
}

/** @var Filter $filter */
$filter = reset($filter);
if (count($filter) > 1) {
return new Rules($filter, $operator);
}

if ($filter instanceof Rules && count($filter->rules) === 1) {
return self::unwrap($filter->rules);
/** @var Filter $unwrapped */
$unwrapped = reset($filter);

if ($unwrapped instanceof Rules && count($unwrapped->rules) === 1) {
return self::unwrap($unwrapped->rules);
}

return $filter;
return $unwrapped;
}

public function addRule(Filter $rule): void
Expand Down
4 changes: 4 additions & 0 deletions src/Pointcut/ServiceDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ServiceDefinition

protected Definition $serviceDefinition;

/** @var ReflectionClass<object> */
private ReflectionClass $originalType;

/** @var Method[]|null */
Expand Down Expand Up @@ -50,6 +51,9 @@ public function getServiceId(): string
return $this->serviceId;
}

/**
* @return ReflectionClass<object>
*/
public function getTypeReflection(): ReflectionClass
{
return $this->originalType;
Expand Down
3 changes: 2 additions & 1 deletion tests/Cases/AspectAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Contributte\Aop\Pointcut;
use Contributte\Aop\Pointcut\ServiceDefinition;
use Nette;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Tests\Files\Aspects\AfterAspect;
use Tests\Files\Aspects\AfterReturningAspect;
Expand Down Expand Up @@ -93,8 +94,8 @@ public static function dataAnalyze(): array

/**
* @param array<string, Pointcut\Rules[]> $pointcuts
* @dataProvider dataAnalyze
*/
#[DataProvider('dataAnalyze')]
public function testAnalyze(array $pointcuts, ServiceDefinition $service): void
{
$builder = new Nette\DI\ContainerBuilder();
Expand Down
7 changes: 3 additions & 4 deletions tests/Cases/PointcutParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Contributte\Aop\Pointcut\Parser;
use Nette;
use Nette\PhpGenerator\PhpLiteral;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Tests\Files\Pointcut\CommonClass;
use Tests\Files\Pointcut\FeedAggregator;
Expand All @@ -30,7 +31,7 @@ public static function getMatcherFactory(): Pointcut\MatcherFactory
return self::$matcherFactory;
}

protected function tearDown(): void
public static function tearDownAfterClass(): void
{
self::$matcherFactory = null;
}
Expand Down Expand Up @@ -251,9 +252,7 @@ public static function dataParse(): array
return $data;
}

/**
* @dataProvider dataParse
*/
#[DataProvider('dataParse')]
public function testParse(Filter $expected, string $input): void
{
$parser = new Parser($this->getMatcherFactory());
Expand Down
21 changes: 6 additions & 15 deletions tests/Cases/PointcutRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Nette\DI\Definitions\ServiceDefinition;
use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\PhpLiteral;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Tests\Files\Pointcut\Cat;
use Tests\Files\Pointcut\CustomTemplate;
Expand Down Expand Up @@ -47,9 +48,7 @@ public static function dataMatchWithin(): array
return $data;
}

/**
* @dataProvider dataMatchWithin
*/
#[DataProvider('dataMatchWithin')]
public function testMatchWithin(bool $expected, Pointcut\Filter $rules, Pointcut\ServiceDefinition $def): void
{
$this->assertSame($expected, (bool) $def->match($rules));
Expand Down Expand Up @@ -79,9 +78,7 @@ public static function dataMatchMethod(): array
return $data;
}

/**
* @dataProvider dataMatchMethod
*/
#[DataProvider('dataMatchMethod')]
public function testMatchMethod(bool $expected, Filter $rules, Pointcut\ServiceDefinition $def): void
{
$this->assertSame($expected, (bool) $def->match($rules));
Expand All @@ -105,9 +102,7 @@ public static function dataMatchFilter(): array
$data[] = [false, new Rules([new FilterMatcher(MyPointcutFilter::class)]), self::createDefinition(SmegHead::class)];
return $data;
}
/**
* @dataProvider dataMatchFilter
*/
#[DataProvider('dataMatchFilter')]
public function testMatchFilter(bool $expected, Filter $rules, Pointcut\ServiceDefinition $def): void
{
$this->assertSame($expected, (bool) $def->match($rules));
Expand All @@ -123,9 +118,7 @@ public static function dataMatchClassAttributedWith(): array
$data[] = [false, new Rules([new ClassAttributedWithMatcher(Test::class)]), self::createDefinition(Legie::class)];
return $data;
}
/**
* @dataProvider dataMatchClassAttributedWith
*/
#[DataProvider('dataMatchClassAttributedWith')]
public function testMatchClassAttributedWith(bool $expected, Filter $rules, Pointcut\ServiceDefinition $def): void
{
$this->assertSame($expected, (bool) $def->match($rules));
Expand All @@ -141,9 +134,7 @@ public static function dataMatchMethodAttributedWith(): array
$data[] = [false, new Rules([new MethodAttributedWithMatcher(Test::class)]), self::createDefinition(SmegHead::class)];
return $data;
}
/**
* @dataProvider dataMatchMethodAttributedWith
*/
#[DataProvider('dataMatchMethodAttributedWith')]
public function testMatchMethodAttributedWith(bool $expected, Filter $rules, Pointcut\ServiceDefinition $def): void
{
$this->assertSame($expected, (bool) $def->match($rules));
Expand Down
3 changes: 2 additions & 1 deletion tests/Files/Pointcut/CustomTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public function render(): void
}


public function setFile(string $file): void
public function setFile(string $file): static
{
return $this;
}


Expand Down