This commit is contained in:
TomasVotruba 2017-09-09 00:58:29 +02:00
parent 0d8fb213c0
commit ea88254312
11 changed files with 14 additions and 18 deletions

View File

@ -9,6 +9,7 @@ $possibleAutoloadPaths = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../..
foreach ($possibleAutoloadPaths as $possibleAutoloadPath) { foreach ($possibleAutoloadPaths as $possibleAutoloadPath) {
if (is_file($possibleAutoloadPath)) { if (is_file($possibleAutoloadPath)) {
require_once $possibleAutoloadPath; require_once $possibleAutoloadPath;
break; break;
} }
} }

View File

@ -8,9 +8,9 @@ use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Scalar\MagicConst\Method; use PhpParser\Node\Scalar\MagicConst\Method;
use PhpParser\Node\Scalar\String_; use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\ClassMethod;
use Rector\DeprecationExtractor\Contract\Deprecation\DeprecationInterface;
use Rector\Exception\NotImplementedException; use Rector\Exception\NotImplementedException;
use Rector\Node\Attribute; use Rector\Node\Attribute;
use Rector\DeprecationExtractor\Contract\Deprecation\DeprecationInterface;
final class DeprecationFactory final class DeprecationFactory
{ {
@ -26,9 +26,6 @@ final class DeprecationFactory
*/ */
public function createFromNode(Node $node, string $scope): DeprecationInterface public function createFromNode(Node $node, string $scope): DeprecationInterface
{ {
dump($node->getAttribute(Attribute::SCOPE));
die;
$message = ''; $message = '';
if ($node instanceof Concat) { if ($node instanceof Concat) {
$message .= $this->processConcatNode($node->left); $message .= $this->processConcatNode($node->left);

View File

@ -3,9 +3,9 @@
namespace Rector\DeprecationExtractor; namespace Rector\DeprecationExtractor;
use Rector\Contract\Parser\ParserInterface; use Rector\Contract\Parser\ParserInterface;
use Rector\DeprecationExtractor\NodeVisitor\DeprecationDetector;
use Rector\NodeTraverser\MainNodeTraverser; use Rector\NodeTraverser\MainNodeTraverser;
use Rector\NodeTraverser\StandaloneTraverseNodeTraverser; use Rector\NodeTraverser\StandaloneTraverseNodeTraverser;
use Rector\DeprecationExtractor\NodeVisitor\DeprecationDetector;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\Finder\SplFileInfo;

View File

@ -4,11 +4,10 @@ namespace Rector\DeprecationExtractor\NodeVisitor;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\NodeVisitorAbstract; use PhpParser\NodeVisitorAbstract;
use PhpParser\PrettyPrinter\Standard; use Rector\DeprecationExtractor\Deprecation\DeprecationCollector;
use Rector\DeprecationExtractor\NodeAnalyzer\TriggerErrorAnalyzer; use Rector\DeprecationExtractor\NodeAnalyzer\TriggerErrorAnalyzer;
use Rector\Node\Attribute; use Rector\Node\Attribute;
use Rector\NodeAnalyzer\DocBlockAnalyzer; use Rector\NodeAnalyzer\DocBlockAnalyzer;
use Rector\DeprecationExtractor\Deprecation\DeprecationCollector;
/** /**
* Inspired by https://github.com/sensiolabs-de/deprecation-detector/blob/master/src/Visitor/Deprecation/FindDeprecatedTagsVisitor.php * Inspired by https://github.com/sensiolabs-de/deprecation-detector/blob/master/src/Visitor/Deprecation/FindDeprecatedTagsVisitor.php
@ -25,10 +24,6 @@ final class DeprecationDetector extends NodeVisitorAbstract
*/ */
private $docBlockAnalyzer; private $docBlockAnalyzer;
/**
* @var Standard
*/
private $prettyPrinter;
/** /**
* @var TriggerErrorAnalyzer * @var TriggerErrorAnalyzer
*/ */
@ -37,12 +32,10 @@ final class DeprecationDetector extends NodeVisitorAbstract
public function __construct( public function __construct(
DeprecationCollector $deprecationCollector, DeprecationCollector $deprecationCollector,
DocBlockAnalyzer $docBlockAnalyzer, DocBlockAnalyzer $docBlockAnalyzer,
Standard $prettyPrinter,
TriggerErrorAnalyzer $triggerErrorAnalyzer TriggerErrorAnalyzer $triggerErrorAnalyzer
) { ) {
$this->deprecationCollector = $deprecationCollector; $this->deprecationCollector = $deprecationCollector;
$this->docBlockAnalyzer = $docBlockAnalyzer; $this->docBlockAnalyzer = $docBlockAnalyzer;
$this->prettyPrinter = $prettyPrinter;
$this->triggerErrorAnalyzer = $triggerErrorAnalyzer; $this->triggerErrorAnalyzer = $triggerErrorAnalyzer;
} }
@ -50,13 +43,13 @@ final class DeprecationDetector extends NodeVisitorAbstract
{ {
if ($this->docBlockAnalyzer->hasAnnotation($node, 'deprecated')) { if ($this->docBlockAnalyzer->hasAnnotation($node, 'deprecated')) {
$this->processDocBlockDeprecation($node); $this->processDocBlockDeprecation($node);
return; return;
} }
// @todo detect the elments it's realted to // @todo detect the elments it's realted to
if ($this->triggerErrorAnalyzer->isUserDeprecation($node)) { if ($this->triggerErrorAnalyzer->isUserDeprecation($node)) {
dump($node->getAttribute(Attribute::SCOPE)); dump($node->getAttribute(Attribute::SCOPE));
// dump($node);
die; die;
$scope = $node->getAttribute(Attribute::SCOPE); $scope = $node->getAttribute(Attribute::SCOPE);

View File

@ -3,10 +3,10 @@
namespace Rector\DeprecationExtractor\Rector; namespace Rector\DeprecationExtractor\Rector;
use Rector\Contract\Rector\RectorInterface; use Rector\Contract\Rector\RectorInterface;
use Rector\Exception\NotImplementedException;
use Rector\DeprecationExtractor\Contract\Deprecation\DeprecationInterface; use Rector\DeprecationExtractor\Contract\Deprecation\DeprecationInterface;
use Rector\DeprecationExtractor\Deprecation\ClassMethodDeprecation; use Rector\DeprecationExtractor\Deprecation\ClassMethodDeprecation;
use Rector\DeprecationExtractor\Deprecation\DeprecationCollector; use Rector\DeprecationExtractor\Deprecation\DeprecationCollector;
use Rector\Exception\NotImplementedException;
/** /**
* Creates rectors with propper setup based on found deprecations. * Creates rectors with propper setup based on found deprecations.

View File

@ -2,9 +2,9 @@
namespace Rector\DeprecationExtractor\Tests; namespace Rector\DeprecationExtractor\Tests;
use Rector\Tests\AbstractContainerAwareTestCase;
use Rector\DeprecationExtractor\Deprecation\DeprecationCollector; use Rector\DeprecationExtractor\Deprecation\DeprecationCollector;
use Rector\DeprecationExtractor\DeprecationExtractor; use Rector\DeprecationExtractor\DeprecationExtractor;
use Rector\Tests\AbstractContainerAwareTestCase;
final class DeprecationExtractorTest extends AbstractContainerAwareTestCase final class DeprecationExtractorTest extends AbstractContainerAwareTestCase
{ {

View File

@ -3,10 +3,10 @@
namespace Rector\DeprecationExtractor\Tests\Rector; namespace Rector\DeprecationExtractor\Tests\Rector;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use Rector\Tests\AbstractContainerAwareTestCase; use Rector\DeprecationExtractor\DeprecationExtractor;
use Rector\DeprecationExtractor\Rector\ConfigurableChangeMethodNameRector; use Rector\DeprecationExtractor\Rector\ConfigurableChangeMethodNameRector;
use Rector\DeprecationExtractor\Rector\RectorFactory; use Rector\DeprecationExtractor\Rector\RectorFactory;
use Rector\DeprecationExtractor\DeprecationExtractor; use Rector\Tests\AbstractContainerAwareTestCase;
final class RectorFactoryTest extends AbstractContainerAwareTestCase final class RectorFactoryTest extends AbstractContainerAwareTestCase
{ {

View File

@ -70,10 +70,12 @@ final class ScopeResolver extends NodeVisitorAbstract
} }
$this->currentScope = null; $this->currentScope = null;
$this->currentScopeNode = null;
} }
if ($node instanceof ClassMethod || $node instanceof Function_) { if ($node instanceof ClassMethod || $node instanceof Function_) {
$this->currentScope = null; $this->currentScope = null;
$this->currentScopeNode = null;
} }
} }

View File

@ -55,6 +55,7 @@ final class Attribute
* @var string * @var string
*/ */
public const PREVIOUS_NODE = 'prev_node'; public const PREVIOUS_NODE = 'prev_node';
/** /**
* @var string * @var string
*/ */

View File

@ -45,6 +45,7 @@ final class DocBlockAnalyzer
if ($type === 'deprecated') { if ($type === 'deprecated') {
$content = $annotationTags[0]->getContent(); $content = $annotationTags[0]->getContent();
return ltrim($content, '* @deprecated '); return ltrim($content, '* @deprecated ');
} }
} }

View File

@ -48,6 +48,7 @@ final class PropertyToClassAdder extends NodeVisitorAbstract
foreach ($nodes as $key => $node) { foreach ($nodes as $key => $node) {
if ($node instanceof Class_ && ! $node->isAnonymous()) { if ($node instanceof Class_ && ! $node->isAnonymous()) {
$nodes[$key] = $this->processClass($node, (string) $node->name); $nodes[$key] = $this->processClass($node, (string) $node->name);
break; break;
} }
} }