Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rector] Apply SetList::DEAD_CODE #472

Merged
merged 9 commits into from
Dec 24, 2021
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Spiral\Boot\Bootloader\ConfigurationBootloader;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
Expand All @@ -15,7 +20,18 @@

$parameters->set(Option::SKIP, [
CountOnNullRector::class,

// for PHP 8
RemoveUnusedPromotedPropertyRector::class,

// buggy when remove private property, but filled by construct in the middle of parameter
RemoveUnusedPrivatePropertyRector::class,
butschster marked this conversation as resolved.
Show resolved Hide resolved

RemoveUnusedPrivateMethodRector::class => [
__DIR__ . '/src/Boot/src/Bootloader/ConfigurationBootloader.php',
butschster marked this conversation as resolved.
Show resolved Hide resolved
],
]);

$containerConfigurator->import(LevelSetList::UP_TO_PHP_72);
$containerConfigurator->import(SetList::DEAD_CODE);
};
15 changes: 0 additions & 15 deletions src/AnnotatedRoutes/src/Bootloader/AnnotatedRoutesBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,12 @@ final class AnnotatedRoutesBootloader extends Bootloader implements SingletonInt
/** @var GroupRegistry */
private $groups;

/**
* @param MemoryInterface $memory
* @param GroupRegistry $groupRegistry
*/
public function __construct(MemoryInterface $memory, GroupRegistry $groupRegistry)
{
$this->memory = $memory;
$this->groups = $groupRegistry;
}

/**
* @param EnvironmentInterface $env
* @param ConsoleBootloader $console
* @param RouteLocator $locator
*/
public function boot(ConsoleBootloader $console, EnvironmentInterface $env, RouteLocator $locator): void
{
$console->addCommand(ResetCommand::class);
Expand All @@ -79,17 +70,11 @@ public function boot(ConsoleBootloader $console, EnvironmentInterface $env, Rout
}
}

/**
* @return GroupRegistry
*/
public function getGroups(): GroupRegistry
{
return $this->groups;
}

/**
* @param array $routes
*/
private function configureRoutes(array $routes): void
{
foreach ($routes as $name => $schema) {
Expand Down
3 changes: 0 additions & 3 deletions src/AnnotatedRoutes/src/Command/ResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ final class ResetCommand extends Command
protected const NAME = 'route:reset';
protected const DESCRIPTION = 'Reset route cache';

/**
* @param MemoryInterface $memory
*/
public function perform(MemoryInterface $memory): void
{
$memory->saveData(AnnotatedRoutesBootloader::MEMORY_SECTION, null);
Expand Down
7 changes: 0 additions & 7 deletions src/AnnotatedRoutes/src/GroupRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,11 @@ final class GroupRegistry implements \IteratorAggregate
/** @var RouteGroup[] */
private $groups = [];

/**
* @param FactoryInterface $factory
*/
public function __construct(FactoryInterface $factory)
{
$this->factory = $factory;
}

/**
* @param string $name
* @return RouteGroup
*/
public function getGroup(string $name): RouteGroup
{
if (!isset($this->groups[$name])) {
Expand Down
24 changes: 0 additions & 24 deletions src/AnnotatedRoutes/src/RouteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ final class RouteGroup
/** @var CoreInterface */
private $core;

/**
* @param ContainerInterface $container
* @param RouterInterface $router
* @param Pipeline $pipeline
*/
public function __construct(
ContainerInterface $container,
RouterInterface $router,
Expand All @@ -58,9 +53,6 @@ public function __construct(

/**
* Prefix added to all the routes.
*
* @param string $prefix
* @return $this
*/
public function setPrefix(string $prefix): self
{
Expand All @@ -74,7 +66,6 @@ public function setPrefix(string $prefix): self

/**
* @param CoreInterface|string|Autowire $core
* @return $this
*/
public function setCore($core): self
{
Expand All @@ -91,7 +82,6 @@ public function setCore($core): self

/**
* @param MiddlewareInterface|string $middleware
* @return $this
*/
public function addMiddleware($middleware): self
{
Expand All @@ -109,14 +99,6 @@ public function addMiddleware($middleware): self

/**
* Register route to group.
*
* @param string $name
* @param string $pattern
* @param string $controller
* @param string $action
* @param array $verbs
* @param array $defaults
* @param array $middleware
*/
public function registerRoute(
string $name,
Expand Down Expand Up @@ -156,12 +138,6 @@ public function flushRoutes()
}
}

/**
* @param string $pattern
* @param string $controller
* @param string $action
* @return Route
*/
public function createRoute(string $pattern, string $controller, string $action): Route
{
$action = new Action($controller, $action);
Expand Down
6 changes: 0 additions & 6 deletions src/AnnotatedRoutes/src/RouteLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@ final class RouteLocator
/** @var AnnotationLocator */
private $locator;

/**
* @param AnnotationLocator $locator
*/
public function __construct(AnnotationLocator $locator)
{
$this->locator = $locator;
}

/**
* @return array
*/
public function findDeclarations(): array
{
$result = [];
Expand Down
4 changes: 0 additions & 4 deletions src/Annotations/src/AnnotatedClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class AnnotatedClass
private $annotation;

/**
* @param \ReflectionClass $class
* @param mixed $annotation
*/
public function __construct(\ReflectionClass $class, $annotation)
Expand All @@ -29,9 +28,6 @@ public function __construct(\ReflectionClass $class, $annotation)
$this->annotation = $annotation;
}

/**
* @return \ReflectionClass
*/
public function getClass(): \ReflectionClass
{
return $this->class;
Expand Down
7 changes: 0 additions & 7 deletions src/Annotations/src/AnnotatedMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class AnnotatedMethod
private $annotation;

/**
* @param \ReflectionMethod $method
* @param mixed $annotation
*/
public function __construct(\ReflectionMethod $method, $annotation)
Expand All @@ -29,17 +28,11 @@ public function __construct(\ReflectionMethod $method, $annotation)
$this->annotation = $annotation;
}

/**
* @return \ReflectionClass
*/
public function getClass(): \ReflectionClass
{
return $this->method->getDeclaringClass();
}

/**
* @return \ReflectionMethod
*/
public function getMethod(): \ReflectionMethod
{
return $this->method;
Expand Down
7 changes: 0 additions & 7 deletions src/Annotations/src/AnnotatedProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class AnnotatedProperty
private $annotation;

/**
* @param \ReflectionProperty $property
* @param mixed $annotation
*/
public function __construct(\ReflectionProperty $property, $annotation)
Expand All @@ -29,17 +28,11 @@ public function __construct(\ReflectionProperty $property, $annotation)
$this->annotation = $annotation;
}

/**
* @return \ReflectionClass
*/
public function getClass(): \ReflectionClass
{
return $this->property->getDeclaringClass();
}

/**
* @return \ReflectionProperty
*/
public function getProperty(): \ReflectionProperty
{
return $this->property;
Expand Down
8 changes: 0 additions & 8 deletions src/Annotations/src/AnnotationLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ final class AnnotationLocator implements SingletonInterface
/**
* AnnotationLocator constructor.
*
* @param ClassesInterface $classLocator
* @param AnnotationReader|null $reader
*
* @throws \Doctrine\Common\Annotations\AnnotationException
*/
public function __construct(ClassesInterface $classLocator, AnnotationReader $reader = null)
Expand All @@ -45,9 +43,6 @@ public function __construct(ClassesInterface $classLocator, AnnotationReader $re

/**
* Limit locator to only specific class types.
*
* @param array $targets
* @return AnnotationLocator
*/
public function withTargets(array $targets): self
{
Expand All @@ -60,7 +55,6 @@ public function withTargets(array $targets): self
/**
* Find all classes with given annotation.
*
* @param string $annotation
* @return iterable|AnnotatedClass[]
*/
public function findClasses(string $annotation): iterable
Expand All @@ -76,7 +70,6 @@ public function findClasses(string $annotation): iterable
/**
* Find all methods with given annotation.
*
* @param string $annotation
* @return iterable|AnnotatedMethod[]
*/
public function findMethods(string $annotation): iterable
Expand All @@ -94,7 +87,6 @@ public function findMethods(string $annotation): iterable
/**
* Find all properties with given annotation.
*
* @param string $annotation
* @return iterable|AnnotatedProperty[]
*/
public function findProperties(string $annotation): iterable
Expand Down
3 changes: 0 additions & 3 deletions src/Attributes/src/Bridge/DoctrineReaderBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ final class DoctrineReaderBridge implements Reader
*/
private ReaderInterface $reader;

/**
* @param ReaderInterface $reader
*/
public function __construct(ReaderInterface $reader)
{
$this->reader = $reader;
Expand Down
2 changes: 0 additions & 2 deletions src/Attributes/src/Composite/Composite.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ public function getParameterMetadata(\ReflectionParameter $parameter, string $na

/**
* @param callable(ReaderInterface): list<array-key, object> $resolver
* @return iterable
*/
abstract protected function each(callable $resolver): iterable;

/**
* @param \Traversable|array $result
* @return array
*/
protected function iterableToArray(iterable $result): array
{
Expand Down
9 changes: 0 additions & 9 deletions src/Attributes/src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Factory implements FactoryInterface

/**
* @param CacheInterface|CacheItemPoolInterface|null $cache
* @return $this
*/
public function withCache($cache): self
{
Expand All @@ -50,10 +49,6 @@ public function create(): ReaderInterface
);
}

/**
* @param ReaderInterface $reader
* @return ReaderInterface
*/
private function decorateByAnnotations(ReaderInterface $reader): ReaderInterface
{
if (\interface_exists(DoctrineReaderInterface::class)) {
Expand All @@ -65,10 +60,6 @@ private function decorateByAnnotations(ReaderInterface $reader): ReaderInterface
return $reader;
}

/**
* @param ReaderInterface $reader
* @return ReaderInterface
*/
private function decorateByCache(ReaderInterface $reader): ReaderInterface
{
switch (true) {
Expand Down
3 changes: 0 additions & 3 deletions src/Attributes/src/FactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@

interface FactoryInterface
{
/**
* @return ReaderInterface
*/
public function create(): ReaderInterface;
}
Loading