1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gskema\TypeSniff\Sniffs\CodeElement; |
4
|
|
|
|
5
|
|
|
use Gskema\TypeSniff\Inspection\DocTypeInspector; |
6
|
|
|
use Gskema\TypeSniff\Inspection\Subject\PropTypeSubject; |
7
|
|
|
use PHP_CodeSniffer\Files\File; |
8
|
|
|
use Gskema\TypeSniff\Core\CodeElement\Element\AbstractFqcnPropElement; |
9
|
|
|
use Gskema\TypeSniff\Core\CodeElement\Element\ClassPropElement; |
10
|
|
|
use Gskema\TypeSniff\Core\CodeElement\Element\CodeElementInterface; |
11
|
|
|
use Gskema\TypeSniff\Core\CodeElement\Element\TraitPropElement; |
12
|
|
|
|
13
|
|
|
class FqcnPropSniff implements CodeElementSniffInterface |
14
|
|
|
{ |
15
|
|
|
protected const CODE = 'FqcnPropSniff'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @inheritDoc |
19
|
|
|
*/ |
20
|
6 |
|
public function configure(array $config): void |
21
|
|
|
{ |
22
|
|
|
// nothing to do |
23
|
6 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritDoc |
27
|
|
|
*/ |
28
|
6 |
|
public function register(): array |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
6 |
|
ClassPropElement::class, |
32
|
|
|
TraitPropElement::class, |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritDoc |
38
|
|
|
* @param AbstractFqcnPropElement $prop |
39
|
|
|
*/ |
40
|
4 |
|
public function process(File $file, CodeElementInterface $prop): void |
41
|
|
|
{ |
42
|
4 |
|
$subject = PropTypeSubject::fromElement($prop); |
43
|
|
|
|
44
|
4 |
|
DocTypeInspector::reportMandatoryTypes($subject); |
45
|
4 |
|
DocTypeInspector::reportReplaceableTypes($subject); |
46
|
4 |
|
DocTypeInspector::reportRemovableTypes($subject); |
47
|
4 |
|
DocTypeInspector::reportMissingOrWrongTypes($subject); |
48
|
|
|
|
49
|
4 |
|
static::reportInvalidDescription($subject); |
50
|
|
|
|
51
|
4 |
|
$subject->writeWarningsTo($file, static::CODE); |
52
|
4 |
|
} |
53
|
|
|
|
54
|
4 |
|
protected static function reportInvalidDescription(PropTypeSubject $subject): void |
55
|
|
|
{ |
56
|
4 |
|
$varTag = $subject->getDocBlock()->getTagsByName('var')[0] ?? null; |
57
|
|
|
|
58
|
4 |
|
if ($varTag && null !== $varTag->getParamName()) { |
59
|
1 |
|
$subject->addDocTypeWarning('Remove property name $'.$varTag->getParamName().' from @var tag'); |
60
|
|
|
} |
61
|
4 |
|
} |
62
|
|
|
} |
63
|
|
|
|