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.

ConstTypeSubject::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 8
dl 0
loc 20
ccs 4
cts 4
cp 1
crap 1
rs 9.9332
c 1
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Gskema\TypeSniff\Inspection\Subject;
4
5
use Gskema\TypeSniff\Core\CodeElement\Element\AbstractFqcnConstElement;
6
use Gskema\TypeSniff\Core\DocBlock\DocBlock;
7
use Gskema\TypeSniff\Core\DocBlock\Tag\VarTag;
8
use Gskema\TypeSniff\Core\Type\Common\UndefinedType;
9
use Gskema\TypeSniff\Core\Type\TypeInterface;
10
11
class ConstTypeSubject extends AbstractTypeSubject
12
{
13
    /**
14
     * @param TypeInterface|null $docType
15
     * @param TypeInterface|null $valueType
16
     * @param int|null           $docTypeLine
17
     * @param int                $fnTypeLine
18
     * @param string             $name
19
     * @param DocBlock           $docBlock
20
     * @param string[]           $attributeNames
21
     * @param string             $id
22
     */
23 7
    public function __construct(
24
        ?TypeInterface $docType,
25
        ?TypeInterface $valueType,
26
        ?int $docTypeLine,
27
        int $fnTypeLine,
28
        string $name,
29
        DocBlock $docBlock,
30
        array $attributeNames,
31
        string $id
32
    ) {
33 7
        parent::__construct(
34 7
            $docType,
35 7
            new UndefinedType(), // not in PHP 7.4 :(
36
            $valueType,
37
            $docTypeLine,
38
            $fnTypeLine,
39
            $name,
40
            $docBlock,
41
            $attributeNames,
42
            $id
43
        );
44 7
    }
45
46
    /**
47
     * @param AbstractFqcnConstElement $const
48
     *
49
     * @return static
50
     */
51 7
    public static function fromElement(AbstractFqcnConstElement $const)
52
    {
53 7
        $docBlock = $const->getDocBlock();
54
55
        /** @var VarTag|null $varTag */
56 7
        $varTag = $docBlock->getTagsByName('var')[0] ?? null;
57
58 7
        return new static(
59 7
            $varTag ? $varTag->getType() : null,
60 7
            $const->getValueType(),
61 7
            $varTag ? $varTag->getLine() : null,
62 7
            $const->getLine(),
63 7
            $const->getConstName() . ' constant',
64
            $docBlock,
65 7
            $const->getAttributeNames(),
66 7
            $const->getFqcn() . '::' . $const->getConstName()
67
        );
68
    }
69
}
70