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
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
"Rector\\DoctrineGedmoToKnplabs\\": "rules/doctrine-gedmo-to-knplabs/src",
"Rector\\MinimalScope\\": "rules/minimal-scope/src",
"Rector\\Polyfill\\": "packages/polyfill/src",
"Rector\\CakePHPToSymfony\\": "rules/cakephp-to-symfony/src"
"Rector\\CakePHPToSymfony\\": "rules/cakephp-to-symfony/src",
"Rector\\JMS\\": "rules/jms/src"
},
"files": [
"src/functions/rector_dump_function.php"
Expand Down Expand Up @@ -187,7 +188,8 @@
"Rector\\DoctrineGedmoToKnplabs\\Tests\\": "rules/doctrine-gedmo-to-knplabs/tests",
"Rector\\MinimalScope\\Tests\\": "rules/minimal-scope/tests",
"Rector\\Polyfill\\Tests\\": "packages/polyfill/tests",
"Rector\\CakePHPToSymfony\\Tests\\": "rules/cakephp-to-symfony/tests"
"Rector\\CakePHPToSymfony\\Tests\\": "rules/cakephp-to-symfony/tests",
"Rector\\JMS\\Tests\\": "rules/jms/tests"
},
"classmap": [
"tests/Source",
Expand Down
52 changes: 51 additions & 1 deletion docs/AllRectorsOverview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# All 457 Rectors Overview
# All 459 Rectors Overview

- [Projects](#projects)
- [General](#general)
Expand All @@ -20,6 +20,7 @@
- [ElasticSearchDSL](#elasticsearchdsl)
- [FileSystemRector](#filesystemrector)
- [Guzzle](#guzzle)
- [JMS](#jms)
- [Laravel](#laravel)
- [Legacy](#legacy)
- [MinimalScope](#minimalscope)
Expand Down Expand Up @@ -3985,6 +3986,55 @@ Changes getMessage(..., true) to getMessageAsArray()

<br>

## JMS

### `RemoveJmsInjectParamsAnnotationRector`

- class: [`Rector\JMS\Rector\ClassMethod\RemoveJmsInjectParamsAnnotationRector`](/../master/rules/jms/src/Rector/ClassMethod/RemoveJmsInjectParamsAnnotationRector.php)
- [test fixtures](/../master/rules/jms/tests/Rector/ClassMethod/RemoveJmsInjectParamsAnnotationRector/Fixture)

Removes JMS\DiExtraBundle\Annotation\InjectParams annotation

```diff
use JMS\DiExtraBundle\Annotation as DI;

class SomeClass
{
- /**
- * @DI\InjectParams({
- * "subscribeService" = @DI\Inject("app.email.service.subscribe"),
- * "ipService" = @DI\Inject("app.util.service.ip")
- * })
- */
public function __construct()
{
}
-}
+}
```

<br>

### `RemoveJmsInjectServiceAnnotationRector`

- class: [`Rector\JMS\Rector\Class_\RemoveJmsInjectServiceAnnotationRector`](/../master/rules/jms/src/Rector/Class_/RemoveJmsInjectServiceAnnotationRector.php)
- [test fixtures](/../master/rules/jms/tests/Rector/Class_/RemoveJmsInjectServiceAnnotationRector/Fixture)

Removes JMS\DiExtraBundle\Annotation\Services annotation

```diff
use JMS\DiExtraBundle\Annotation as DI;

-/**
- * @DI\Service("email.web.services.subscribe_token", public=true)
- */
class SomeClass
{
}
```

<br>

## Laravel

### `FacadeStaticCallToConstructorInjectionRector`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNode\JMS;

use JMS\DiExtraBundle\Annotation\InjectParams;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;

final class JMSInjectParamsTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface
{
/**
* @var string
*/
public const CLASS_NAME = InjectParams::class;

public function __construct(string $originalContent)
{
$this->originalContent = $originalContent;
}

public function __toString(): string
{
return $this->originalContent;
}

public function getShortName(): string
{
return '@DI\InjectParams';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNode\JMS;

use JMS\DiExtraBundle\Annotation\Service;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface;
use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;

final class JMSServiceValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface
{
/**
* @var string
*/
public const CLASS_NAME = Service::class;

public function __construct(string $originalContent)
{
$this->originalContent = $originalContent;
}

public function __toString(): string
{
return $this->originalContent;
}

public function getShortName(): string
{
return '@DI\Service';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\JMS;

use JMS\DiExtraBundle\Annotation\InjectParams;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use Rector\BetterPhpDocParser\PhpDocNode\JMS\JMSInjectParamsTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;

final class JMSInjectParamsPhpDocNodeFactory extends AbstractPhpDocNodeFactory
{
public function getClass(): string
{
return InjectParams::class;
}

/**
* @return JMSInjectParamsTagValueNode|null
*/
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
{
if (! $node instanceof ClassMethod) {
return null;
}

/** @var InjectParams|null $injectParams */
$injectParams = $this->nodeAnnotationReader->readMethodAnnotation($node, $this->getClass());
if ($injectParams === null) {
return null;
}

$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);

return new JMSInjectParamsTagValueNode($annotationContent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocNodeFactory\JMS;

use JMS\DiExtraBundle\Annotation\Service;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use Rector\BetterPhpDocParser\PhpDocNode\JMS\JMSServiceValueNode;
use Rector\BetterPhpDocParser\PhpDocNodeFactory\AbstractPhpDocNodeFactory;

final class JMSServicePhpDocNodeFactory extends AbstractPhpDocNodeFactory
{
public function getClass(): string
{
return Service::class;
}

/**
* @return JMSServiceValueNode|null
*/
public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator): ?PhpDocTagValueNode
{
if (! $node instanceof ClassMethod && ! $node instanceof Class_) {
return null;
}

if ($node instanceof ClassMethod) {
/** @var Service|null $service */
$service = $this->nodeAnnotationReader->readMethodAnnotation($node, $this->getClass());
if ($service === null) {
return null;
}
}

if ($node instanceof Class_) {
/** @var Service|null $service */
$service = $this->nodeAnnotationReader->readClassAnnotation($node, $this->getClass());
if ($service === null) {
return null;
}
}

$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);

return new JMSServiceValueNode($annotationContent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ private function resolvePackage(Configuration $configuration): Package
return new Package(
'Rector\\' . $configuration->getPackage() . '\\',
'Rector\\' . $configuration->getPackage() . '\\Tests\\',
'packages/' . $configuration->getPackage() . '/src',
'packages/' . $configuration->getPackage() . '/tests'
'rules/' . $configuration->getPackageDirectory() . '/src',
'rules/' . $configuration->getPackageDirectory() . '/tests'
);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/rector-generator/src/ValueObject/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\RectorGenerator\ValueObject;

use Nette\Utils\Strings;
use Rector\Core\Util\RectorStrings;

final class Configuration
{
Expand Down Expand Up @@ -110,6 +111,11 @@ public function getPackage(): string
return $this->package;
}

public function getPackageDirectory(): string
{
return RectorStrings::camelCaseToDashes($this->package);
}

public function getName(): string
{
return $this->name;
Expand Down
7 changes: 4 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ parameters:
- stubs
- compiler/src

autoload_files:
- ci/check_services_in_yaml_configs.php

paths:
- ci
- bin
Expand All @@ -28,6 +25,7 @@ parameters:
- compiler/src

excludes_analyse:
- ci/check_services_in_yaml_configs.php
- "*/Expected/*"
# complex printer
- "packages/ContributorTools/src/Command/DumpNodesCommand.php"
Expand Down Expand Up @@ -247,3 +245,6 @@ parameters:

- '#Right side of && is always true#'
- '#Parameter \#(.*?) (.*?) of class PhpParser\\Node\\Expr\\BinaryOp\\(.*?) constructor expects PhpParser\\Node\\Expr, PhpParser\\Node given#'

- '#Method Rector\\BetterPhpDocParser\\PhpDocNode\\JMS\\JMSInjectParamsTagValueNode\:\:__toString\(\) should return string but returns string\|null#'
- '#Method Rector\\BetterPhpDocParser\\PhpDocNode\\JMS\\JMSServiceValueNode\:\:__toString\(\) should return string but returns string\|null#'
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

namespace Rector\JMS\Rector\ClassMethod;

use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocNode\JMS\JMSInjectParamsTagValueNode;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\NodeTypeResolver\Node\AttributeKey;

/**
* @see https://github.com/rectorphp/rector/issues/2864
*
* @see \Rector\JMS\Tests\Rector\ClassMethod\RemoveJmsInjectParamsAnnotationRector\RemoveJmsInjectParamsAnnotationRectorTest
*/
final class RemoveJmsInjectParamsAnnotationRector extends AbstractRector
{
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Removes JMS\DiExtraBundle\Annotation\InjectParams annotation', [
new CodeSample(
<<<'PHP'
use JMS\DiExtraBundle\Annotation as DI;

class SomeClass
{
/**
* @DI\InjectParams({
* "subscribeService" = @DI\Inject("app.email.service.subscribe"),
* "ipService" = @DI\Inject("app.util.service.ip")
* })
*/
public function __construct()
{
}
}

PHP
,
<<<'PHP'
use JMS\DiExtraBundle\Annotation as DI;

class SomeClass
{
public function __construct()
{
}
}
PHP
),
]);
}

/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [ClassMethod::class];
}

/**
* @param ClassMethod $node
*/
public function refactor(Node $node): ?Node
{
if (! $this->isName($node, '__construct')) {
return null;
}

/** @var PhpDocInfo $phpDocInfo */
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
if (! $phpDocInfo->hasByType(JMSInjectParamsTagValueNode::class)) {
return null;
}

$phpDocInfo->removeByType(JMSInjectParamsTagValueNode::class);

return $node;
}
}
Loading