Skip to content

Commit

Permalink
Merge pull request #9 from saschanowak/feature/flow-annotations-to-at…
Browse files Browse the repository at this point in the history
…tributes

FEATURE: Add flow annotations to attribute set
  • Loading branch information
dlubitz authored Sep 30, 2023
2 parents a58461c + cfe0e07 commit 24d8ffc
Show file tree
Hide file tree
Showing 25 changed files with 730 additions and 0 deletions.
39 changes: 39 additions & 0 deletions config/set/flow-annotations-to-attributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare (strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\ValueObject\AnnotationToAttribute;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
new AnnotationToAttribute('Neos\\Flow\\Annotations\\After'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\AfterReturning'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\AfterThrowing'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Around'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Aspect'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Autowiring'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Before'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\CompileStatic'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Entity'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\FlushesCaches'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Identity'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\IgnoreValidation'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Inject'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\InjectConfiguration'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Internal'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Introduce'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Lazy'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\MapRequestBody'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Pointcut'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Proxy'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Scope'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Session'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Signal'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\SkipCsrfProtection'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Transient'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\Validate'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\ValidationGroups'),
new AnnotationToAttribute('Neos\\Flow\\Annotations\\ValueObject'),
]);
};
2 changes: 2 additions & 0 deletions src/NeosRectorSets.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
class NeosRectorSets implements SetListInterface
{
public const CONTENTREPOSITORY_9_0 = __DIR__ . '/../config/set/contentrepository-90.php';

public const ANNOTATIONS_TO_ATTRIBUTES = __DIR__ . '/../config/set/flow-annotations-to-attributes.php';
}
31 changes: 31 additions & 0 deletions tests/Rules/AnnotationToAttribute/AnnotationToAttributeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Neos\Rector\Tests\Rules\AnnotationToAttribute;

use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class AnnotationToAttributeTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $fileInfo): void
{
$this->doTestFile($fileInfo);
}

/**
* @return \Iterator<string>
*/
public function provideData(): \Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
87 changes: 87 additions & 0 deletions tests/Rules/AnnotationToAttribute/Fixture/aspect.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Flow\Aop\PointcutFilterInterface;

/**
* @Flow\Aspect
*/
class SomeAspect
{
/**
* @Flow\Around("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())")
*/
public function around(JoinPointInterface $joinPoint)
{
}
/**
* @Flow\Before("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())")
*/
public function before(JoinPointInterface $joinPoint)
{
}
/**
* @Flow\AfterReturning("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())")
*/
public function afterReturning(JoinPointInterface $joinPoint)
{
}
/**
* @Flow\AfterThrowing("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())")
*/
public function afterThrowing(JoinPointInterface $joinPoint)
{
}
/**
* @Flow\After("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())")
*/
public function after(JoinPointInterface $joinPoint)
{
}
/**
* @Flow\Pointcut("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())")
*/
public function pointcut(PointcutFilterInterface $joinPoint)
{
}
}

?>
-----
<?php

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Flow\Aop\PointcutFilterInterface;

#[Flow\Aspect]
class SomeAspect
{
#[Flow\Around('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')]
public function around(JoinPointInterface $joinPoint)
{
}
#[Flow\Before('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')]
public function before(JoinPointInterface $joinPoint)
{
}
#[Flow\AfterReturning('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')]
public function afterReturning(JoinPointInterface $joinPoint)
{
}
#[Flow\AfterThrowing('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')]
public function afterThrowing(JoinPointInterface $joinPoint)
{
}
#[Flow\After('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')]
public function after(JoinPointInterface $joinPoint)
{
}
#[Flow\Pointcut('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')]
public function pointcut(PointcutFilterInterface $joinPoint)
{
}
}

?>
33 changes: 33 additions & 0 deletions tests/Rules/AnnotationToAttribute/Fixture/autowiring.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Neos\Flow\Annotations as Flow;

/**
* @Flow\Autowiring(false)
*/
class SomeClass
{
/**
* @Flow\Autowiring(enabled=false)
*/
public function someAction(Resource $resource, string $resourceType = ''): void
{
}
}

?>
-----
<?php

use Neos\Flow\Annotations as Flow;

#[Flow\Autowiring(false)]
class SomeClass
{
#[Flow\Autowiring(enabled: false)]
public function someAction(Resource $resource, string $resourceType = ''): void
{
}
}

?>
29 changes: 29 additions & 0 deletions tests/Rules/AnnotationToAttribute/Fixture/compilestatic.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Neos\Flow\Annotations as Flow;

class SomeClass
{
/**
* @Flow\CompileStatic
*/
public function someAction(): void
{
}
}

?>
-----
<?php

use Neos\Flow\Annotations as Flow;

class SomeClass
{
#[Flow\CompileStatic]
public function someAction(): void
{
}
}

?>
23 changes: 23 additions & 0 deletions tests/Rules/AnnotationToAttribute/Fixture/entity.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Neos\Flow\Annotations as Flow;

/**
* @Flow\Entity()
*/
class SomeClass
{
}

?>
-----
<?php

use Neos\Flow\Annotations as Flow;

#[Flow\Entity]
class SomeClass
{
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Neos\Flow\Annotations as Flow;

/**
* @Flow\Entity(repositoryClass=FooRepository::class, readOnly=true)
*/
class SomeClass
{
}

?>
-----
<?php

use Neos\Flow\Annotations as Flow;

#[Flow\Entity(repositoryClass: FooRepository::class, readOnly: true)]
class SomeClass
{
}

?>
29 changes: 29 additions & 0 deletions tests/Rules/AnnotationToAttribute/Fixture/flushescaches.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Neos\Flow\Annotations as Flow;

class SomeClass
{
/**
* @Flow\FlushesCaches
*/
public function someCommand(): void
{
}
}

?>
-----
<?php

use Neos\Flow\Annotations as Flow;

class SomeClass
{
#[Flow\FlushesCaches]
public function someCommand(): void
{
}
}

?>
25 changes: 25 additions & 0 deletions tests/Rules/AnnotationToAttribute/Fixture/identity.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Neos\Flow\Annotations as Flow;

class SomeClass
{
/**
* @Flow\Identity
*/
protected string $foo;
}

?>
-----
<?php

use Neos\Flow\Annotations as Flow;

class SomeClass
{
#[Flow\Identity]
protected string $foo;
}

?>
39 changes: 39 additions & 0 deletions tests/Rules/AnnotationToAttribute/Fixture/ignorevalidation.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Neos\Flow\Annotations as Flow;

class SomeClass
{
/**
* @Flow\IgnoreValidation
*/
protected $foo;

/**
* @Flow\IgnoreValidation(argumentName="resource")
* @Flow\IgnoreValidation(argumentName="resourceType")
*/
public function someAction(Resource $resource, string $resourceType = ''): void
{
}
}

?>
-----
<?php

use Neos\Flow\Annotations as Flow;

class SomeClass
{
#[Flow\IgnoreValidation]
protected $foo;

#[Flow\IgnoreValidation(argumentName: 'resource')]
#[Flow\IgnoreValidation(argumentName: 'resourceType')]
public function someAction(Resource $resource, string $resourceType = ''): void
{
}
}

?>
Loading

0 comments on commit 24d8ffc

Please sign in to comment.