mirror of https://github.com/rectorphp/rector.git
fix namespaces, fixtures, add getThrowsTypes()
This commit is contained in:
parent
3bb87fcc1c
commit
401d0aeaf6
|
@ -1,4 +1,4 @@
|
|||
# All 451 Rectors Overview
|
||||
# All 452 Rectors Overview
|
||||
|
||||
- [Projects](#projects)
|
||||
- [General](#general)
|
||||
|
|
|
@ -12,6 +12,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode;
|
|||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\Constant\ConstantArrayType;
|
||||
|
@ -188,6 +189,29 @@ final class PhpDocInfo
|
|||
return $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType($paramTagValue, $this->node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Type[]
|
||||
*/
|
||||
public function getThrowsTypes(): array
|
||||
{
|
||||
$throwsPhpDocNodes = $this->getTagsByName('throws');
|
||||
|
||||
$throwsTypes = [];
|
||||
|
||||
foreach ($throwsPhpDocNodes as $throwsPhpDocNode) {
|
||||
if (! $throwsPhpDocNode->value instanceof ThrowsTagValueNode) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$throwsTypes[] = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType(
|
||||
$throwsPhpDocNode->value,
|
||||
$this->node
|
||||
);
|
||||
}
|
||||
|
||||
return $throwsTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Type[]
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace Rector\StaticTypeMapper\PhpParser;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
|
||||
use Rector\StaticTypeMapper\Mapper\ScalarStringToTypeMapper;
|
||||
|
@ -34,10 +33,6 @@ final class IdentifierNodeMapper implements PhpParserNodeMapperInterface
|
|||
*/
|
||||
public function mapToPHPStan(Node $node): Type
|
||||
{
|
||||
if ($node->name === 'string') {
|
||||
return new StringType();
|
||||
}
|
||||
|
||||
$type = $this->scalarStringToTypeMapper->mapScalarStringToType($node->name);
|
||||
if ($type !== null) {
|
||||
return $type;
|
||||
|
|
|
@ -12,6 +12,7 @@ use PhpParser\Node\UnionType as PhpParserUnionType;
|
|||
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\Type;
|
||||
|
@ -93,7 +94,8 @@ final class StaticTypeMapper
|
|||
{
|
||||
if ($phpDocTagValueNode instanceof ReturnTagValueNode ||
|
||||
$phpDocTagValueNode instanceof ParamTagValueNode ||
|
||||
$phpDocTagValueNode instanceof VarTagValueNode
|
||||
$phpDocTagValueNode instanceof VarTagValueNode ||
|
||||
$phpDocTagValueNode instanceof ThrowsTagValueNode
|
||||
) {
|
||||
return $this->mapPHPStanPhpDocTypeNodeToPHPStanType($phpDocTagValueNode->type, $node);
|
||||
}
|
||||
|
|
|
@ -4,28 +4,23 @@ declare(strict_types=1);
|
|||
|
||||
namespace Rector\CodingStyle\Rector\Throw_;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Throw_;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use PhpParser\Node\Stmt\UseUse;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocTagNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\Core\Exception\NotImplementedException;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
|
||||
/**
|
||||
* Adds "throws" DocBlock to methods.
|
||||
*/
|
||||
final class AnnotateThrowablesRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
|
@ -95,71 +90,46 @@ PHP
|
|||
return $node;
|
||||
}
|
||||
|
||||
private function isThrowableAnnotated(Throw_ $node): bool
|
||||
private function isThrowableAnnotated(Throw_ $throw): bool
|
||||
{
|
||||
$identifiedThrownThrowables = $this->identifyThrownThrowables($node);
|
||||
$phpDocInfo = $this->getThrowingStmtDocblock($node);
|
||||
$alreadyAnnotatedThrowTags = $phpDocInfo->getTagsByName('throws');
|
||||
$phpDocInfo = $this->getThrowingStmtPhpDocInfo($throw);
|
||||
$identifiedThrownThrowables = $this->identifyThrownThrowables($throw);
|
||||
|
||||
if ($alreadyAnnotatedThrowTags === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$alreadyAnnotatedThrowClassNames = array_map(
|
||||
static function (AttributeAwarePhpDocTagNode $alreadyAnnotatedThrowTag): string {
|
||||
return $alreadyAnnotatedThrowTag->value->type->name;
|
||||
},
|
||||
$alreadyAnnotatedThrowTags
|
||||
);
|
||||
|
||||
$notAnnotatedThrowables = [];
|
||||
|
||||
foreach ($identifiedThrownThrowables as $identifiedThrownThrowable) {
|
||||
if ($this->isIdentifiedThrownThrowableInAlreadyAnnotatedOnes(
|
||||
$node,
|
||||
$alreadyAnnotatedThrowClassNames,
|
||||
$identifiedThrownThrowable
|
||||
) === false) {
|
||||
$notAnnotatedThrowables[] = $identifiedThrownThrowable;
|
||||
}
|
||||
}
|
||||
|
||||
return empty($notAnnotatedThrowables);
|
||||
}
|
||||
|
||||
private function isIdentifiedThrownThrowableInAlreadyAnnotatedOnes(
|
||||
Throw_ $node,
|
||||
array $alreadyAnnotatedThrowClassNames,
|
||||
string $identifiedThrownThrowable
|
||||
): bool {
|
||||
foreach ($alreadyAnnotatedThrowClassNames as $alreadyAnnotatedThrowClassName) {
|
||||
if ($alreadyAnnotatedThrowClassName === $identifiedThrownThrowable) {
|
||||
return true;
|
||||
foreach ($phpDocInfo->getThrowsTypes() as $throwsType) {
|
||||
if (! $throwsType instanceof ObjectType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
! Strings::contains($alreadyAnnotatedThrowClassName, '\\') &&
|
||||
Strings::contains($identifiedThrownThrowable, $alreadyAnnotatedThrowClassName) &&
|
||||
$this->isThrowableImported($node)
|
||||
) {
|
||||
return true;
|
||||
if ($throwsType instanceof ShortenedObjectType) {
|
||||
$className = $throwsType->getFullyQualifiedName();
|
||||
} else {
|
||||
$className = $throwsType->getClassName();
|
||||
}
|
||||
|
||||
if (! in_array($className, $identifiedThrownThrowables, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function identifyThrownThrowables(Throw_ $node): array
|
||||
private function identifyThrownThrowables(Throw_ $throw): array
|
||||
{
|
||||
switch (get_class($node->expr)) {
|
||||
case New_::class:
|
||||
return [$this->buildFQN($node)];
|
||||
case StaticCall::class:
|
||||
return $this->identifyThrownThrowablesInStaticCall($node);
|
||||
default:
|
||||
// throw new ShouldNotHappenException(sprintf('The \Throwable %s is not supported. Please, open an issue.', get_class($node->expr)));
|
||||
return [];
|
||||
if ($throw->expr instanceof New_) {
|
||||
return [$this->getName($throw->expr->class)];
|
||||
}
|
||||
|
||||
if ($throw->expr instanceof StaticCall) {
|
||||
return $this->identifyThrownThrowablesInStaticCall($throw);
|
||||
}
|
||||
|
||||
throw new NotImplementedException(sprintf(
|
||||
'The \Throwable "%s" is not supported yet. Please, open an issue.',
|
||||
get_class($throw->expr)
|
||||
));
|
||||
}
|
||||
|
||||
private function identifyThrownThrowablesInStaticCall(Throw_ $node): array
|
||||
|
@ -167,41 +137,24 @@ PHP
|
|||
return [];
|
||||
}
|
||||
|
||||
private function isThrowableImported(Throw_ $node): bool
|
||||
{
|
||||
$throwClassName = $this->getName($node->expr->class);
|
||||
$useNodes = $node->getAttribute(AttributeKey::USE_NODES);
|
||||
|
||||
if ($useNodes === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var Use_ $useNode */
|
||||
foreach ($useNodes as $useNode) {
|
||||
/** @var UseUse $useStmt */
|
||||
foreach ($useNode->uses as $useStmt) {
|
||||
if ($this->getName($useStmt) === $throwClassName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function annotateThrowable(Throw_ $node): void
|
||||
{
|
||||
$throwClass = $this->buildFQN($node);
|
||||
if ($throwClass === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$docComment = $this->buildThrowsDocComment($throwClass);
|
||||
|
||||
$throwingStmtDocblock = $this->getThrowingStmtDocblock($node);
|
||||
$throwingStmtDocblock->addPhpDocTagNode($docComment);
|
||||
$throwingStmtPhpDocInfo = $this->getThrowingStmtPhpDocInfo($node);
|
||||
$throwingStmtPhpDocInfo->addPhpDocTagNode($docComment);
|
||||
}
|
||||
|
||||
private function buildThrowsDocComment(string $FQNOrThrowableName): AttributeAwarePhpDocTagNode
|
||||
private function buildThrowsDocComment(string $throwableClass): AttributeAwarePhpDocTagNode
|
||||
{
|
||||
$value = new AttributeAwareGenericTagValueNode($FQNOrThrowableName);
|
||||
return new AttributeAwarePhpDocTagNode('@throws', $value);
|
||||
$genericTagValueNode = new ThrowsTagValueNode(new IdentifierTypeNode('\\' . $throwableClass), '');
|
||||
|
||||
return new AttributeAwarePhpDocTagNode('@throws', $genericTagValueNode);
|
||||
}
|
||||
|
||||
private function buildFQN(Throw_ $throw): ?string
|
||||
|
@ -213,25 +166,17 @@ PHP
|
|||
return $this->getName($throw->expr->class);
|
||||
}
|
||||
|
||||
private function getThrowingStmtDocblock(Throw_ $throw): PhpDocInfo
|
||||
private function getThrowingStmtPhpDocInfo(Throw_ $throw): PhpDocInfo
|
||||
{
|
||||
$stmt = $this->getThrowingStmt($throw);
|
||||
return $stmt->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
}
|
||||
$method = $throw->getAttribute(AttributeKey::METHOD_NODE);
|
||||
$function = $throw->getAttribute(AttributeKey::FUNCTION_NODE);
|
||||
|
||||
/**
|
||||
* @return ClassMethod|Function_
|
||||
*/
|
||||
private function getThrowingStmt(Throw_ $node): FunctionLike
|
||||
{
|
||||
$method = $node->getAttribute(AttributeKey::METHOD_NODE);
|
||||
$function = $node->getAttribute(AttributeKey::FUNCTION_NODE);
|
||||
/** @var Node|null $stmt */
|
||||
$stmt = $method ?? $function ?? null;
|
||||
|
||||
if ($stmt === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
return $stmt;
|
||||
return $stmt->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
function throwCustomExceptionAlreadyAnnotatedInFunction()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -17,11 +17,11 @@ function throwCustomExceptionAlreadyAnnotatedInFunction()
|
|||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
function throwCustomExceptionAlreadyAnnotatedInFunction()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -4,12 +4,9 @@ namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
|||
|
||||
class CustomExceptionAlreadyAnnotatedInMethod
|
||||
{
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
*/
|
||||
public function throwException()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,11 +19,11 @@ namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
|||
class CustomExceptionAlreadyAnnotatedInMethod
|
||||
{
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
public function throwException()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
|||
*/
|
||||
function throwCustomExceptionInFunctionWithDockblock(int $code)
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException('', $code);
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException('', $code);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -22,11 +22,11 @@ namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
|||
* This is a comment.
|
||||
*
|
||||
* @param int $code
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
function throwCustomExceptionInFunctionWithDockblock(int $code)
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException('', $code);
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException('', $code);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
|||
|
||||
function throwCustomExceptionInFunctionWithoutDockblock()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -14,11 +14,11 @@ function throwCustomExceptionInFunctionWithoutDockblock()
|
|||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
function throwCustomExceptionInFunctionWithoutDockblock()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -11,7 +11,7 @@ class CustomExceptionInMethodWithDocblock
|
|||
*/
|
||||
public function throwException(int $code)
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException('', $code);
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException('', $code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,11 +27,11 @@ class CustomExceptionInMethodWithDocblock
|
|||
* This is a comment.
|
||||
*
|
||||
* @param int $code
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
public function throwException(int $code)
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException('', $code);
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException('', $code);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class CustomExceptionInMethodWithoutDocblock
|
|||
{
|
||||
public function throwException()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,11 @@ namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
|||
class CustomExceptionInMethodWithoutDocblock
|
||||
{
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
public function throwException()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,16 +3,16 @@
|
|||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
function throwCustomExceptionThrownInTwoFunctionsFirst()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
|
||||
function throwCustomExceptionThrownInTwoFunctionsSecond()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -22,19 +22,19 @@ function throwCustomExceptionThrownInTwoFunctionsSecond()
|
|||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
function throwCustomExceptionThrownInTwoFunctionsFirst()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
function throwCustomExceptionThrownInTwoFunctionsSecond()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -5,16 +5,16 @@ namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
|||
class CustomExceptionThrownInTwoMethods
|
||||
{
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
public function throwException()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
|
||||
public function anotherThrowException()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,19 +27,19 @@ namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
|||
class CustomExceptionThrownInTwoMethods
|
||||
{
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
public function throwException()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException
|
||||
* @throws \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException
|
||||
*/
|
||||
public function anotherThrowException()
|
||||
{
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException();
|
||||
throw new \Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
|
||||
/**
|
||||
* @throws TheException
|
||||
*/
|
||||
function throwCustomImportedExceptionAlreadyAnnotatedInFunction()
|
||||
{
|
||||
throw new TheException();
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
|
||||
/**
|
||||
* @throws TheException
|
||||
*/
|
||||
function throwCustomImportedExceptionAlreadyAnnotatedInFunction()
|
||||
{
|
||||
throw new TheException();
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
|
||||
class CustomImportedExceptionAlreadyAnnotatedInMethod
|
||||
{
|
||||
/**
|
||||
* @throws TheException
|
||||
*/
|
||||
public function throwException()
|
||||
{
|
||||
throw new TheException();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
|
||||
class CustomImportedExceptionAlreadyAnnotatedInMethod
|
||||
{
|
||||
/**
|
||||
* @throws TheException
|
||||
*/
|
||||
public function throwException()
|
||||
{
|
||||
throw new TheException();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException;
|
||||
|
||||
/**
|
||||
* @throws TheException
|
||||
*/
|
||||
function skipCustomImportedExceptionAlreadyAnnotatedInFunction()
|
||||
{
|
||||
throw new TheException();
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException;
|
||||
|
||||
class SkipCustomImportedExceptionAlreadyAnnotatedInMethod
|
||||
{
|
||||
/**
|
||||
* @throws TheException
|
||||
*/
|
||||
public function throwException()
|
||||
{
|
||||
throw new TheException();
|
||||
}
|
||||
}
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheThird;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheThird;
|
||||
|
||||
class ExceptionsFactoryNoReturnTypeHingting
|
||||
{
|
||||
|
@ -25,9 +25,9 @@ function throwWithFactoryMethodNoReturnTypeHinting()
|
|||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheThird;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheThird;
|
||||
|
||||
class ExceptionsFactoryNoReturnTypeHingting
|
||||
{
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheThird;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheThird;
|
||||
|
||||
class ExceptionsFactoryMethodNothingAnnotated
|
||||
{
|
||||
|
@ -35,9 +35,9 @@ function throwWithFactoryMethodNotAnnotated()
|
|||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheThird;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheThird;
|
||||
|
||||
class ExceptionsFactoryMethodNothingAnnotated
|
||||
{
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheThird;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheThird;
|
||||
|
||||
class ExceptionsFactoryStaticMethodNothingAnnotated
|
||||
{
|
||||
|
@ -34,9 +34,9 @@ function throwWithFactoryStaticMethodNotAnnotated()
|
|||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheThird;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheThird;
|
||||
|
||||
class ExceptionsFactoryStaticMethodNothingAnnotated
|
||||
{
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheThird;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheThird;
|
||||
|
||||
class ExceptionsFactoryStaticMethodWithReturnDockblock
|
||||
{
|
||||
|
@ -39,9 +39,9 @@ function throwWithFactoryStaticMethodWithReturnDockblock()
|
|||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source\TheExceptionTheThird;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheException;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheSecond;
|
||||
use Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source\TheExceptionTheThird;
|
||||
|
||||
class ExceptionsFactoryStaticMethodWithReturnDockblock
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source;
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source;
|
||||
|
||||
class TheException extends \RuntimeException {}
|
||||
class TheException extends \RuntimeException {
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source;
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source;
|
||||
|
||||
class TheExceptionTheSecond extends \RuntimeException {}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowables\Source;
|
||||
namespace Rector\CodingStyle\Tests\Rector\Throw_\AnnotateThrowablesRector\Source;
|
||||
|
||||
class TheExceptionTheThird extends \RuntimeException {}
|
||||
|
|
|
@ -15,6 +15,7 @@ use Rector\Core\RectorDefinition\RectorDefinition;
|
|||
* Covers:
|
||||
* - https://github.com/symfony/symfony/pull/22441/files
|
||||
* - https://github.com/symfony/symfony/blob/master/UPGRADE-3.3.md#console
|
||||
*
|
||||
* @see \Rector\Symfony\Tests\Rector\Console\ConsoleExceptionToErrorEventConstantRector\ConsoleExceptionToErrorEventConstantRectorTest
|
||||
*/
|
||||
final class ConsoleExceptionToErrorEventConstantRector extends AbstractRector
|
||||
|
|
Loading…
Reference in New Issue