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.
Passed
Push — master ( 17dafe...3e29f4 )
by Gytis
02:42 queued 11s
created

FqcnDescriptionSniff   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 57
ccs 19
cts 19
cp 1
rs 10
wmc 11

3 Methods

Rating   Name   Duplication   Size   Complexity  
B process() 0 14 7
A register() 0 6 1
A configure() 0 10 3
1
<?php
2
3
namespace Gskema\TypeSniff\Sniffs\CodeElement;
4
5
use Gskema\TypeSniff\Core\CodeElement\Element\ClassElement;
6
use Gskema\TypeSniff\Core\CodeElement\Element\CodeElementInterface;
7
use Gskema\TypeSniff\Core\CodeElement\Element\InterfaceElement;
8
use Gskema\TypeSniff\Core\CodeElement\Element\TraitElement;
9
use PHP_CodeSniffer\Files\File;
10
11
class FqcnDescriptionSniff implements CodeElementSniffInterface
12
{
13
    /** @var string[] */
14
    protected $invalidPatterns = [
15
        '^(Class|Trait|Interface)\s+\w+\s*$',
16
    ];
17
18
    /** @var string[] */
19
    protected $invalidTags = [
20
        '@package'
21
    ];
22
23
    /**
24
     * @inheritDoc
25
     */
26 6
    public function configure(array $config): void
27
    {
28 6
        $this->invalidPatterns = array_merge($this->invalidPatterns, $config['invalidPatterns'] ?? []);
29 6
        foreach ($this->invalidPatterns as &$invalidPattern) {
30 6
            $invalidPattern = '#'.$invalidPattern.'#i';
31
        }
32
33 6
        $this->invalidTags = array_merge($this->invalidTags, $config['invalidTags'] ?? []);
34 6
        foreach ($this->invalidTags as &$invalidTag) {
35 6
             $invalidTag = substr($invalidTag, 1);
36
        }
37 6
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42 6
    public function register(): array
43
    {
44
        return [
45 6
            ClassElement::class,
46
            InterfaceElement::class,
47
            TraitElement::class,
48
        ];
49
    }
50
51
    /**
52
     * @inheritDoc
53
     */
54 6
    public function process(File $file, CodeElementInterface $element): void
55
    {
56 6
        foreach ($element->getDocBlock()->getDescriptionLines() as $lineNum => $descriptionLine) {
57 1
            foreach ($this->invalidPatterns as $invalidPattern) {
58 1
                if (preg_match($invalidPattern, $descriptionLine)) {
59 1
                    $file->addWarningOnLine('Useless description', $lineNum, 'FqcnDescriptionSniff');
60
                }
61
            }
62
        }
63
64 6
        foreach ($element->getDocBlock()->getTags() as $tag) {
65 1
            foreach ($this->invalidTags as $invalidTagName) {
66 1
                if ($tag->getName() === $invalidTagName) {
67 1
                    $file->addWarningOnLine('Useless tag', $tag->getLine(), 'FqcnDescriptionSniff');
68
                }
69
            }
70
        }
71 6
    }
72
}
73