Skip to content

Commit

Permalink
misc (#4748)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Aug 9, 2023
1 parent ecdf208 commit db0388f
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function createFromNode(Node $node): ?PhpDocInfo
}

/**
* @api
* @api downgrade
*/
public function createEmpty(Node $node): PhpDocInfo
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function parseValue(
$tokenIterator->next();
}

// nested entity!
// nested entity!, supported in attribute since PHP 8.1
if ($tokenIterator->isCurrentTokenType(Lexer::TOKEN_OPEN_PARENTHESES)) {
return $this->parseNestedDoctrineAnnotationTagValueNode($currentTokenValue, $tokenIterator);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/PhpAttribute/AnnotationToAttributeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface;
use Rector\PhpAttribute\Enum\DocTagNodeState;
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Webmozart\Assert\Assert;

/**
* @see \Rector\Tests\PhpAttribute\AnnotationToAttributeMapper\AnnotationToAttributeMapperTest
Expand All @@ -35,6 +36,8 @@ public function __construct(iterable $annotationToAttributeMappers)
} else {
$this->annotationToAttributeMappers = $annotationToAttributeMappers;
}

Assert::notEmpty($this->annotationToAttributeMappers);
}

/**
Expand Down
15 changes: 10 additions & 5 deletions packages/Testing/PHPUnit/AbstractLazyTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Container\Container;
use PHPUnit\Framework\TestCase;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Contract\Rector\NonPhpRectorInterface;
use Rector\Core\Contract\Rector\PhpRectorInterface;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\DependencyInjection\LazyContainerFactory;
Expand Down Expand Up @@ -61,12 +61,18 @@ protected function forgetRectorsRules(): void
{
$container = self::getContainer();

// remove all tagged rules
// 1. forget instance first! then remove tags
$rectors = $container->tagged(RectorInterface::class);
foreach ($rectors as $rector) {
$container->offsetUnset($rector::class);
}

// 2. remove all tagged rules
$privatesAccessor = new PrivatesAccessor();
$privatesAccessor->propertyClosure($container, 'tags', static function (array $tags): array {
unset($tags[RectorInterface::class]);
unset($tags[PhpRectorInterface::class]);
unset($tags[ConfigurableRectorInterface::class]);
unset($tags[NonPhpRectorInterface::class]);
return $tags;
});

Expand All @@ -75,8 +81,7 @@ protected function forgetRectorsRules(): void
$container->offsetUnset($rector::class);
}

// remove after binding too, to avoid setting configuration over and over again

// 3. remove after binding too, to avoid setting configuration over and over again
$privatesAccessor->propertyClosure(
$container,
'afterResolvingCallbacks',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\SourcePhp81\All;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\SourcePhp81\Length;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\SourcePhp81\NotNull;
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\SourcePhp81\NotNumber;

return static function (RectorConfig $rectorConfig): void {
Expand All @@ -19,7 +18,6 @@
$rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
new AnnotationToAttribute(All::class),
new AnnotationToAttribute(Length::class),
new AnnotationToAttribute(NotNull::class),
new AnnotationToAttribute(NotNumber::class),
new AnnotationToAttribute(GenericAnnotation::class),
]);
Expand Down
2 changes: 2 additions & 0 deletions rules/Php80/Rector/Class_/AnnotationToAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@

/**
* @changelog https://wiki.php.net/rfc/attributes_v2
* @changelog https://wiki.php.net/rfc/new_in_initializers
*
* @see \Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\AnnotationToAttributeRectorTest
* @see \Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Php81NestedAttributesRectorTest
*/
final class AnnotationToAttributeRector extends AbstractRector implements ConfigurableRectorInterface, MinPhpVersionInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Console/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function __construct(iterable $commands)
$commands = iterator_to_array($commands->getIterator());
}

Assert::notEmpty($commands);
Assert::allIsInstanceOf($commands, Command::class);

$this->addCommands($commands);

// remove unused commands
Expand Down

0 comments on commit db0388f

Please sign in to comment.