| @@ 10-49 (lines=40) @@ | ||
| 7 | use Marcosh\PhpTypeChecker\Check\Parameter; |
|
| 8 | use Roave\BetterReflection\Reflection\ReflectionParameter; |
|
| 9 | ||
| 10 | final class MethodParamTypeDoesNotCoincideWithDocBlock |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var ReflectionParameter |
|
| 14 | */ |
|
| 15 | private $parameter; |
|
| 16 | ||
| 17 | private function __construct(ReflectionParameter $parameter) |
|
| 18 | { |
|
| 19 | $this->parameter = $parameter; |
|
| 20 | } |
|
| 21 | ||
| 22 | public static function param(ReflectionParameter $parameter): \Iterator |
|
| 23 | { |
|
| 24 | if ((new Parameter($parameter))->typeDoesNotCoincideWithDocBlock()) { |
|
| 25 | yield new self($parameter); |
|
| 26 | } |
|
| 27 | } |
|
| 28 | ||
| 29 | public function message(): string |
|
| 30 | { |
|
| 31 | try { |
|
| 32 | $docBlockTypes = $this->parameter->getDocBlockTypes(); |
|
| 33 | } catch (\InvalidArgumentException $e) { |
|
| 34 | // we need this here to prevent reflection-bocblock errors on @see invalid Fqsen |
|
| 35 | } |
|
| 36 | ||
| 37 | return sprintf( |
|
| 38 | 'Parameter <info>%s</info> of method <info>%s</info> of the class <info>%s</info> ' . |
|
| 39 | 'defined in <comment>%s</comment> has a <info>%s</info> type hint, ' . |
|
| 40 | 'but has a <info>%s</info> doc block type.', |
|
| 41 | $this->parameter->getName(), |
|
| 42 | $this->parameter->getDeclaringFunction()->getName(), |
|
| 43 | $this->parameter->getDeclaringFunction()->getDeclaringClass()->getName(), |
|
| 44 | $this->parameter->getDeclaringFunction()->getFileName(), |
|
| 45 | $this->parameter->getTypeHint(), |
|
| 46 | implode($docBlockTypes) |
|
| 47 | ); |
|
| 48 | } |
|
| 49 | } |
|
| 50 | ||
| @@ 10-48 (lines=39) @@ | ||
| 7 | use Marcosh\PhpTypeChecker\Check\Parameter; |
|
| 8 | use Roave\BetterReflection\Reflection\ReflectionParameter; |
|
| 9 | ||
| 10 | final class MissingMethodParamTypeWithDocBlock implements Anomaly |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var ReflectionParameter |
|
| 14 | */ |
|
| 15 | private $parameter; |
|
| 16 | ||
| 17 | public function __construct(ReflectionParameter $parameter) |
|
| 18 | { |
|
| 19 | $this->parameter = $parameter; |
|
| 20 | } |
|
| 21 | ||
| 22 | public static function param(ReflectionParameter $parameter): \Generator |
|
| 23 | { |
|
| 24 | if ((new Parameter($parameter))->typeIsMissingWithDocBlock()) { |
|
| 25 | yield new self($parameter); |
|
| 26 | } |
|
| 27 | } |
|
| 28 | ||
| 29 | public function message(): string |
|
| 30 | { |
|
| 31 | try { |
|
| 32 | $docBlockTypes = $this->parameter->getDocBlockTypes(); |
|
| 33 | } catch (\InvalidArgumentException $e) { |
|
| 34 | // we need this here to prevent reflection-bocblock errors on @see invalid Fqsen |
|
| 35 | } |
|
| 36 | ||
| 37 | return sprintf( |
|
| 38 | 'Parameter <info>%s</info> of method <info>%s</info> of the class <info>%s</info> ' . |
|
| 39 | 'defined in <comment>%s</comment> does not have a type hint but has a boc block type of ' . |
|
| 40 | '<info>%s</info>.', |
|
| 41 | $this->parameter->getName(), |
|
| 42 | $this->parameter->getDeclaringFunction()->getName(), |
|
| 43 | $this->parameter->getDeclaringFunction()->getDeclaringClass()->getName(), |
|
| 44 | $this->parameter->getDeclaringFunction()->getFileName(), |
|
| 45 | implode($docBlockTypes) |
|
| 46 | ); |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||