mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-22 02:36:52 +01:00
apply on packages
This commit is contained in:
parent
d687bf7dba
commit
b86f4afdaf
@ -12,9 +12,19 @@ final class EntityTagValueNode extends AbstractDoctrineTagValueNode implements P
|
||||
{
|
||||
use PhpAttributePhpDocNodePrintTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const REPOSITORY_CLASS = 'repositoryClass';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const READ_ONLY = 'readOnly';
|
||||
|
||||
public function removeRepositoryClass(): void
|
||||
{
|
||||
$this->items['repositoryClass'] = null;
|
||||
$this->items[self::REPOSITORY_CLASS] = null;
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
@ -32,12 +42,12 @@ final class EntityTagValueNode extends AbstractDoctrineTagValueNode implements P
|
||||
{
|
||||
$items = $this->items;
|
||||
|
||||
if ($items['repositoryClass'] !== null) {
|
||||
$items['repositoryClass'] .= '::class';
|
||||
if ($items[self::REPOSITORY_CLASS] !== null) {
|
||||
$items[self::REPOSITORY_CLASS] .= '::class';
|
||||
}
|
||||
|
||||
if ($items['readOnly'] !== null) {
|
||||
$items['readOnly'] = $items['readOnly'] ? 'ORM\Entity::READ_ONLY' : '';
|
||||
if ($items[self::READ_ONLY] !== null) {
|
||||
$items[self::READ_ONLY] = $items[self::READ_ONLY] ? 'ORM\Entity::READ_ONLY' : '';
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
@ -15,6 +15,11 @@ final class ManyToManyTagValueNode extends AbstractDoctrineTagValueNode implemen
|
||||
{
|
||||
use PhpAttributePhpDocNodePrintTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const TARGET_ENTITY = 'targetEntity';
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
@ -32,7 +37,7 @@ final class ManyToManyTagValueNode extends AbstractDoctrineTagValueNode implemen
|
||||
|
||||
public function getTargetEntity(): string
|
||||
{
|
||||
return $this->items['targetEntity'];
|
||||
return $this->items[self::TARGET_ENTITY];
|
||||
}
|
||||
|
||||
public function getFullyQualifiedTargetEntity(): ?string
|
||||
@ -62,7 +67,7 @@ final class ManyToManyTagValueNode extends AbstractDoctrineTagValueNode implemen
|
||||
|
||||
public function changeTargetEntity(string $targetEntity): void
|
||||
{
|
||||
$this->items['targetEntity'] = $targetEntity;
|
||||
$this->items[self::TARGET_ENTITY] = $targetEntity;
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
@ -78,7 +83,7 @@ final class ManyToManyTagValueNode extends AbstractDoctrineTagValueNode implemen
|
||||
private function createAttributeItems(): array
|
||||
{
|
||||
$items = $this->items;
|
||||
$items['targetEntity'] .= '::class';
|
||||
$items[self::TARGET_ENTITY] .= '::class';
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
@ -12,6 +12,11 @@ use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode;
|
||||
|
||||
final class SerializerTypeTagValueNode extends AbstractTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface, SilentKeyNodeInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const NAME = 'name';
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return '@Serializer\Type';
|
||||
@ -19,20 +24,20 @@ final class SerializerTypeTagValueNode extends AbstractTagValueNode implements T
|
||||
|
||||
public function changeName(string $newName): void
|
||||
{
|
||||
$this->items['name'] = $newName;
|
||||
$this->items[self::NAME] = $newName;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->items['name'];
|
||||
return $this->items[self::NAME];
|
||||
}
|
||||
|
||||
public function replaceName(string $oldName, string $newName): bool
|
||||
{
|
||||
$oldNamePattern = '#\b' . preg_quote($oldName, '#') . '\b#';
|
||||
|
||||
$newNameValue = Strings::replace($this->items['name'], $oldNamePattern, $newName);
|
||||
if ($newNameValue !== $this->items['name']) {
|
||||
$newNameValue = Strings::replace($this->items[self::NAME], $oldNamePattern, $newName);
|
||||
if ($newNameValue !== $this->items[self::NAME]) {
|
||||
$this->changeName($newNameValue);
|
||||
return true;
|
||||
}
|
||||
@ -42,6 +47,6 @@ final class SerializerTypeTagValueNode extends AbstractTagValueNode implements T
|
||||
|
||||
public function getSilentKey(): string
|
||||
{
|
||||
return 'name';
|
||||
return self::NAME;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,11 @@ use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
|
||||
final class TypeNodeAnalyzerTest extends AbstractKernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const INT = 'int';
|
||||
|
||||
/**
|
||||
* @var TypeNodeAnalyzer
|
||||
*/
|
||||
@ -38,9 +43,9 @@ final class TypeNodeAnalyzerTest extends AbstractKernelTestCase
|
||||
|
||||
public function provideDataForArrayType(): Iterator
|
||||
{
|
||||
$arrayTypeNode = new ArrayTypeNode(new IdentifierTypeNode('int'));
|
||||
$arrayTypeNode = new ArrayTypeNode(new IdentifierTypeNode(self::INT));
|
||||
|
||||
yield [new IdentifierTypeNode('int'), false];
|
||||
yield [new IdentifierTypeNode(self::INT), false];
|
||||
yield [$arrayTypeNode, true];
|
||||
yield [new UnionTypeNode([$arrayTypeNode]), true];
|
||||
}
|
||||
@ -55,7 +60,7 @@ final class TypeNodeAnalyzerTest extends AbstractKernelTestCase
|
||||
|
||||
public function provideDataForIntersectionAndNotNullable(): Iterator
|
||||
{
|
||||
yield [new IntersectionTypeNode([new IdentifierTypeNode('int')]), true];
|
||||
yield [new IntersectionTypeNode([new NullableTypeNode(new IdentifierTypeNode('int'))]), false];
|
||||
yield [new IntersectionTypeNode([new IdentifierTypeNode(self::INT)]), true];
|
||||
yield [new IntersectionTypeNode([new NullableTypeNode(new IdentifierTypeNode(self::INT))]), false];
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,11 @@ use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
||||
|
||||
final class VoidTypeMapper implements TypeMapperInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const VOID = 'void';
|
||||
|
||||
/**
|
||||
* @var PhpVersionProvider
|
||||
*/
|
||||
@ -36,7 +41,7 @@ final class VoidTypeMapper implements TypeMapperInterface
|
||||
*/
|
||||
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
|
||||
{
|
||||
return new IdentifierTypeNode('void');
|
||||
return new IdentifierTypeNode(self::VOID);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,7 +57,7 @@ final class VoidTypeMapper implements TypeMapperInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Identifier('void');
|
||||
return new Identifier(self::VOID);
|
||||
}
|
||||
|
||||
public function mapToDocString(Type $type, ?Type $parentType = null): string
|
||||
@ -63,6 +68,6 @@ final class VoidTypeMapper implements TypeMapperInterface
|
||||
}
|
||||
|
||||
// fallback for PHP 7.0 and older, where void type was only in docs
|
||||
return 'void';
|
||||
return self::VOID;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,11 @@ use Symfony\Component\Process\Process;
|
||||
|
||||
final class ComposerPackageAutoloadUpdater
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const PSR_4 = 'psr-4';
|
||||
|
||||
/**
|
||||
* @var JsonFileSystem
|
||||
*/
|
||||
@ -54,8 +59,8 @@ final class ComposerPackageAutoloadUpdater
|
||||
return;
|
||||
}
|
||||
|
||||
$composerJson['autoload']['psr-4'][$package->getSrcNamespace()] = $package->getSrcDirectory();
|
||||
$composerJson['autoload-dev']['psr-4'][$package->getTestsNamespace()] = $package->getTestsDirectory();
|
||||
$composerJson['autoload'][self::PSR_4][$package->getSrcNamespace()] = $package->getSrcDirectory();
|
||||
$composerJson['autoload-dev'][self::PSR_4][$package->getTestsNamespace()] = $package->getTestsDirectory();
|
||||
|
||||
$this->jsonFileSystem->saveJsonToFile($composerJsonFilePath, $composerJson);
|
||||
|
||||
@ -83,7 +88,7 @@ final class ComposerPackageAutoloadUpdater
|
||||
|
||||
private function isPackageAlreadyLoaded(array $composerJson, Package $package): bool
|
||||
{
|
||||
return isset($composerJson['autoload']['psr-4'][$package->getSrcNamespace()]);
|
||||
return isset($composerJson['autoload'][self::PSR - 4][$package->getSrcNamespace()]);
|
||||
}
|
||||
|
||||
private function rebuildAutoload(): void
|
||||
|
@ -1,12 +1,15 @@
|
||||
services:
|
||||
Rector\SOLID\Rector\Class_\RepeatedLiteralToClassConstantRector: null
|
||||
|
||||
parameters:
|
||||
sets:
|
||||
- 'coding-style'
|
||||
- 'code-quality'
|
||||
- 'dead-code'
|
||||
- 'nette-utils-code-quality'
|
||||
- 'solid'
|
||||
- 'privatization'
|
||||
- 'naming'
|
||||
# sets:
|
||||
# - 'coding-style'
|
||||
# - 'code-quality'
|
||||
# - 'dead-code'
|
||||
# - 'nette-utils-code-quality'
|
||||
# - 'solid'
|
||||
# - 'privatization'
|
||||
# - 'naming'
|
||||
|
||||
paths:
|
||||
- 'src'
|
||||
@ -23,9 +26,9 @@ parameters:
|
||||
- 'packages/doctrine-annotation-generated/src/ConstantPreservingDocParser.php'
|
||||
- 'packages/doctrine-annotation-generated/src/ConstantPreservingAnnotationReader.php'
|
||||
|
||||
exclude_rectors:
|
||||
# @todo needs to check for "autoload-dev" local dependency
|
||||
- 'Rector\Php55\Rector\String_\StringClassNameToClassConstantRector'
|
||||
- 'Rector\CodingStyle\Rector\String_\SplitStringClassConstantToClassConstFetchRector'
|
||||
# fix in separated PR
|
||||
- 'Rector\SOLID\Rector\Class_\RepeatedLiteralToClassConstantRector'
|
||||
# exclude_rectors:
|
||||
# # @todo needs to check for "autoload-dev" local dependency
|
||||
# - 'Rector\Php55\Rector\String_\StringClassNameToClassConstantRector'
|
||||
# - 'Rector\CodingStyle\Rector\String_\SplitStringClassConstantToClassConstFetchRector'
|
||||
# # fix in separated PR
|
||||
# - 'Rector\SOLID\Rector\Class_\RepeatedLiteralToClassConstantRector'
|
||||
|
@ -92,7 +92,7 @@ PHP
|
||||
public function refactor(Node $class): ?Node
|
||||
{
|
||||
// skip tests, where string values are often used as fixtures
|
||||
if ($this->isName($class, 'Test')) {
|
||||
if ($this->isName($class, '*Test')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user