|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Reflection\Deprecation; |
| 4 | + |
| 5 | +use PHPStan\BetterReflection\Reflection\Adapter\ReflectionClass; |
| 6 | +use PHPStan\BetterReflection\Reflection\Adapter\ReflectionClassConstant; |
| 7 | +use PHPStan\BetterReflection\Reflection\Adapter\ReflectionEnum; |
| 8 | +use PHPStan\BetterReflection\Reflection\Adapter\ReflectionFunction; |
| 9 | +use PHPStan\BetterReflection\Reflection\Adapter\ReflectionMethod; |
| 10 | +use PHPStan\BetterReflection\Reflection\Adapter\ReflectionProperty; |
| 11 | +use PHPStan\BetterReflection\Reflection\ReflectionConstant; |
| 12 | +use PHPStan\DependencyInjection\Container; |
| 13 | + |
| 14 | +final class DeprecationProvider |
| 15 | +{ |
| 16 | + |
| 17 | + /** @var array<PropertyDeprecationExtension> $propertyDeprecationExtensions */ |
| 18 | + private array $propertyDeprecationExtensions; |
| 19 | + |
| 20 | + /** @var array<MethodDeprecationExtension> $methodDeprecationExtensions */ |
| 21 | + private array $methodDeprecationExtensions; |
| 22 | + |
| 23 | + /** @var array<ClassConstantDeprecationExtension> $classConstantDeprecationExtensions */ |
| 24 | + private array $classConstantDeprecationExtensions; |
| 25 | + |
| 26 | + /** @var array<ClassDeprecationExtension> $classDeprecationExtensions */ |
| 27 | + private array $classDeprecationExtensions; |
| 28 | + |
| 29 | + /** @var array<FunctionDeprecationExtension> $functionDeprecationExtensions */ |
| 30 | + private array $functionDeprecationExtensions; |
| 31 | + |
| 32 | + /** @var array<ConstantDeprecationExtension> $constantDeprecationExtensions */ |
| 33 | + private array $constantDeprecationExtensions; |
| 34 | + |
| 35 | + public function __construct( |
| 36 | + Container $container, |
| 37 | + ) |
| 38 | + { |
| 39 | + $this->propertyDeprecationExtensions = $container->getServicesByTag('phpstan.propertyDeprecationExtension'); |
| 40 | + $this->methodDeprecationExtensions = $container->getServicesByTag('phpstan.methodDeprecationExtension'); |
| 41 | + $this->classConstantDeprecationExtensions = $container->getServicesByTag('phpstan.classConstantDeprecationExtension'); |
| 42 | + $this->classDeprecationExtensions = $container->getServicesByTag('phpstan.classDeprecationExtension'); |
| 43 | + $this->functionDeprecationExtensions = $container->getServicesByTag('phpstan.functionDeprecationExtension'); |
| 44 | + $this->constantDeprecationExtensions = $container->getServicesByTag('phpstan.constantDeprecationExtension'); |
| 45 | + } |
| 46 | + |
| 47 | + public function getPropertyDeprecation(ReflectionProperty $reflectionProperty): ?Deprecation |
| 48 | + { |
| 49 | + foreach ($this->propertyDeprecationExtensions as $extension) { |
| 50 | + $deprecation = $extension->getPropertyDeprecation($reflectionProperty); |
| 51 | + if ($deprecation !== null) { |
| 52 | + return $deprecation; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + return null; |
| 57 | + } |
| 58 | + |
| 59 | + public function getMethodDeprecation(ReflectionMethod $methodReflection): ?Deprecation |
| 60 | + { |
| 61 | + foreach ($this->methodDeprecationExtensions as $extension) { |
| 62 | + $deprecation = $extension->getMethodDeprecation($methodReflection); |
| 63 | + if ($deprecation !== null) { |
| 64 | + return $deprecation; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + return null; |
| 69 | + } |
| 70 | + |
| 71 | + public function getClassConstantDeprecation(ReflectionClassConstant $reflectionConstant): ?Deprecation |
| 72 | + { |
| 73 | + foreach ($this->classConstantDeprecationExtensions as $extension) { |
| 74 | + $deprecation = $extension->getClassConstantDeprecation($reflectionConstant); |
| 75 | + if ($deprecation !== null) { |
| 76 | + return $deprecation; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + return null; |
| 81 | + } |
| 82 | + |
| 83 | + public function isClassDeprecated(ReflectionClass|ReflectionEnum $reflection): ?Deprecation |
| 84 | + { |
| 85 | + foreach ($this->classDeprecationExtensions as $extension) { |
| 86 | + $deprecation = $extension->getClassDeprecation($reflection); |
| 87 | + if ($deprecation !== null) { |
| 88 | + return $deprecation; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + return null; |
| 93 | + } |
| 94 | + |
| 95 | + public function getFunctionDeprecation(ReflectionFunction $reflectionFunction): ?Deprecation |
| 96 | + { |
| 97 | + foreach ($this->functionDeprecationExtensions as $extension) { |
| 98 | + $deprecation = $extension->getFunctionDeprecation($reflectionFunction); |
| 99 | + if ($deprecation !== null) { |
| 100 | + return $deprecation; |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + return null; |
| 105 | + } |
| 106 | + |
| 107 | + public function getConstantDeprecation(ReflectionConstant $constantReflection): ?Deprecation |
| 108 | + { |
| 109 | + foreach ($this->constantDeprecationExtensions as $extension) { |
| 110 | + $deprecation = $extension->getConstantDeprecation($constantReflection); |
| 111 | + if ($deprecation !== null) { |
| 112 | + return $deprecation; |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + return null; |
| 117 | + } |
| 118 | + |
| 119 | +} |
0 commit comments