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.

FqcnDescriptionSniff::configure()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 3
rs 10
1
<?php
2
3
namespace Gskema\TypeSniff\Sniffs\CodeElement;
4
5
use Gskema\TypeSniff\Core\CodeElement\Element\AbstractFqcnElement;
6
use Gskema\TypeSniff\Core\CodeElement\Element\ClassElement;
7
use Gskema\TypeSniff\Core\CodeElement\Element\CodeElementInterface;
8
use Gskema\TypeSniff\Core\CodeElement\Element\InterfaceElement;
9
use Gskema\TypeSniff\Core\CodeElement\Element\TraitElement;
10
use Gskema\TypeSniff\Core\SniffHelper;
11
use PHP_CodeSniffer\Files\File;
12
13
class FqcnDescriptionSniff implements CodeElementSniffInterface
14
{
15
    protected const CODE = 'FqcnDescriptionSniff';
16
17
    /** @var string[] */
18
    protected array $invalidPatterns = [
19
        '^(Class|Trait|Interface)\s+\w+\s*$',
20
    ];
21
22
    /** @var string[] */
23
    protected array $invalidTags = [
24
        '@package',
25
    ];
26
27
    protected string $reportType = 'warning';
28
29
    protected bool $addViolationId = false;
30
31
    /**
32
     * @inheritDoc
33
     */
34 16
    public function configure(array $config): void
35
    {
36 16
        $this->invalidPatterns = array_merge($this->invalidPatterns, $config['invalidPatterns'] ?? []);
37 16
        foreach ($this->invalidPatterns as &$invalidPattern) {
38 16
            $invalidPattern = '#' . $invalidPattern . '#i';
39
        }
40
41 16
        $this->invalidTags = array_merge($this->invalidTags, $config['invalidTags'] ?? []);
42 16
        foreach ($this->invalidTags as &$invalidTag) {
43 16
            $invalidTag = substr($invalidTag, 1);
44
        }
45
46 16
        $this->reportType = (string)($config['reportType'] ?? 'warning');
47 16
        $this->addViolationId = (bool)($config['addViolationId'] ?? false);
48 16
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53 16
    public function register(): array
54
    {
55
        return [
56 16
            ClassElement::class,
57
            InterfaceElement::class,
58
            TraitElement::class,
59
        ];
60
    }
61
62
    /**
63
     * @inheritDoc
64
     * @param AbstractFqcnElement $element
65
     */
66 16
    public function process(File $file, CodeElementInterface $element, CodeElementInterface $parentElement): void
67
    {
68 16
        foreach ($element->getDocBlock()->getDescriptionLines() as $lineNum => $descriptionLine) {
69 3
            foreach ($this->invalidPatterns as $invalidPattern) {
70 3
                if (preg_match($invalidPattern, $descriptionLine)) {
71 3
                    $originId = $this->addViolationId ? $element->getFqcn() . $descriptionLine : null;
0 ignored issues
show
Bug introduced by
The method getFqcn() does not exist on Gskema\TypeSniff\Core\Co...nt\CodeElementInterface. It seems like you code against a sub-type of Gskema\TypeSniff\Core\Co...nt\CodeElementInterface such as Gskema\TypeSniff\Core\Co...ent\AbstractFqcnElement. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
                    $originId = $this->addViolationId ? $element->/** @scrutinizer ignore-call */ getFqcn() . $descriptionLine : null;
Loading history...
72 3
                    SniffHelper::addViolation($file, 'Useless description', $lineNum, static::CODE, $this->reportType, $originId);
73
                }
74
            }
75
        }
76
77 16
        foreach ($element->getDocBlock()->getTags() as $tag) {
78 4
            foreach ($this->invalidTags as $invalidTagName) {
79 4
                if ($tag->getName() === $invalidTagName) {
80 3
                    $originId = $this->addViolationId ? $element->getFqcn() . $invalidTagName : null;
81 3
                    SniffHelper::addViolation($file, 'Useless tag', $tag->getLine(), static::CODE, $this->reportType, $originId);
82
                }
83
            }
84
        }
85 16
    }
86
}
87