GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AbstractTypeSubject   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 46
dl 0
loc 165
ccs 57
cts 57
cp 1
rs 10
c 1
b 0
f 0
wmc 24

19 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A hasAttribute() 0 3 1
A writeViolationsTo() 0 13 4
A hasDefinedDocType() 0 3 2
A getFnTypeWarnings() 0 3 1
A getDocBlock() 0 3 1
A hasDocTypeTag() 0 3 1
A __construct() 0 20 1
A hasDefinedDocBlock() 0 3 1
A getName() 0 3 1
A getDocTypeWarnings() 0 3 1
A getFnTypeLine() 0 3 1
A hasDefinedFnType() 0 3 2
A addDocTypeWarning() 0 3 1
A addFnTypeWarning() 0 3 1
A getDocType() 0 3 1
A getValueType() 0 3 1
A getDocTypeLine() 0 3 1
A getFnType() 0 3 1
1
<?php
2
3
namespace Gskema\TypeSniff\Inspection\Subject;
4
5
use Gskema\TypeSniff\Core\DocBlock\DocBlock;
6
use Gskema\TypeSniff\Core\DocBlock\UndefinedDocBlock;
7
use Gskema\TypeSniff\Core\SniffHelper;
8
use Gskema\TypeSniff\Core\Type\Common\UndefinedType;
9
use Gskema\TypeSniff\Core\Type\TypeInterface;
10
use PHP_CodeSniffer\Files\File;
11
12
/**
13
 * @see AbstractTypeSubjectTest
14
 */
15
abstract class AbstractTypeSubject
16
{
17
    protected ?TypeInterface $docType; // null = missing in PHPDoc
18
19
    protected TypeInterface $fnType;
20
21
    protected ?TypeInterface $valueType; // null = could not be detected
22
23
    protected ?int $docTypeLine; // null = missing in PHPDoc
24
25
    protected int $fnTypeLine;
26
27
    protected string $name; // "parameter $param1", "property $prop1", "constant CONST1"
28
29
    protected string $id; // TestClass::method1(), etc.
30
31
    protected DocBlock $docBlock;
32
33
    /** @var string[] */
34
    protected array $docTypeWarnings = [];
35
36
    /** @var string[] */
37
    protected array $fnTypeWarnings = [];
38
39
    /** @var string[] */
40
    protected array $attributeNames = [];
41
42
    /**
43
     * @param TypeInterface|null $docType
44
     * @param TypeInterface      $fnType
45
     * @param TypeInterface|null $valueType
46
     * @param int|null           $docTypeLine
47
     * @param int                $fnTypeLine
48
     * @param string             $name
49
     * @param DocBlock           $docBlock
50
     * @param string[]           $attributeNames
51
     * @param string             $id
52
     */
53 17
    public function __construct(
54
        ?TypeInterface $docType,
55
        TypeInterface $fnType,
56
        ?TypeInterface $valueType,
57
        ?int $docTypeLine,
58
        int $fnTypeLine,
59
        string $name,
60
        DocBlock $docBlock,
61
        array $attributeNames,
62
        string $id
63
    ) {
64 17
        $this->docType = $docType;
65 17
        $this->fnType = $fnType;
66 17
        $this->valueType = $valueType;
67 17
        $this->docTypeLine = $docTypeLine;
68 17
        $this->fnTypeLine = $fnTypeLine;
69 17
        $this->name = $name;
70 17
        $this->docBlock = $docBlock;
71 17
        $this->attributeNames = $attributeNames;
72 17
        $this->id = $id;
73 17
    }
74
75 17
    public function getDocType(): ?TypeInterface
76
    {
77 17
        return $this->docType;
78
    }
79
80 17
    public function getFnType(): TypeInterface
81
    {
82 17
        return $this->fnType;
83
    }
84
85 17
    public function getValueType(): ?TypeInterface
86
    {
87 17
        return $this->valueType;
88
    }
89
90 1
    public function getDocTypeLine(): ?int
91
    {
92 1
        return $this->docTypeLine;
93
    }
94
95 1
    public function getFnTypeLine(): int
96
    {
97 1
        return $this->fnTypeLine;
98
    }
99
100 1
    public function getName(): string
101
    {
102 1
        return $this->name;
103
    }
104
105 1
    public function getId(): string
106
    {
107 1
        return $this->id;
108
    }
109
110 13
    public function getDocBlock(): DocBlock
111
    {
112 13
        return $this->docBlock;
113
    }
114
115
    /**
116
     * @return string[]
117
     */
118 1
    public function getDocTypeWarnings(): array
119
    {
120 1
        return $this->docTypeWarnings;
121
    }
122
123
    /**
124
     * @return string[]
125
     */
126 1
    public function getFnTypeWarnings(): array
127
    {
128 1
        return $this->fnTypeWarnings;
129
    }
130
131 16
    public function hasDefinedDocType(): bool
132
    {
133 16
        return $this->docType && !($this->docType instanceof UndefinedType);
134
    }
135
136 16
    public function hasDefinedFnType(): bool
137
    {
138 16
        return $this->fnType && !($this->fnType instanceof UndefinedType);
139
    }
140
141 16
    public function hasDefinedDocBlock(): bool
142
    {
143 16
        return !($this->docBlock instanceof UndefinedDocBlock);
144
    }
145
146 11
    public function addDocTypeWarning(string $warning): void
147
    {
148 11
        $this->docTypeWarnings[] = $warning;
149 11
    }
150
151 16
    public function addFnTypeWarning(string $warning): void
152
    {
153 16
        $this->fnTypeWarnings[] = $warning;
154 16
    }
155
156 16
    public function writeViolationsTo(File $file, string $sniffCode, string $reportType, bool $addViolationId): void
157
    {
158 16
        $originId = $addViolationId ? $this->getId() : null;
159
160 16
        $ucName = ucfirst($this->name);
161 16
        foreach ($this->docTypeWarnings as $docTypeWarning) {
162 10
            $warning = str_replace([':subject:', ':Subject:'], [$this->name, $ucName], $docTypeWarning);
163 10
            SniffHelper::addViolation($file, $warning, $this->docTypeLine ?? $this->fnTypeLine, $sniffCode, $reportType, $originId);
164
        }
165
166 16
        foreach ($this->fnTypeWarnings as $fnTypeWarning) {
167 15
            $warning = str_replace([':subject:', ':Subject:'], [$this->name, $ucName], $fnTypeWarning);
168 15
            SniffHelper::addViolation($file, $warning, $this->fnTypeLine, $sniffCode, $reportType, $originId);
169
        }
170 16
    }
171
172 2
    public function hasDocTypeTag(): bool
173
    {
174 2
        return null !== $this->docType;
175
    }
176
177 17
    public function hasAttribute(string $attributeName): bool
178
    {
179 17
        return in_array($attributeName, $this->attributeNames);
180
    }
181
}
182