MissingFunctionParamTypeWithDocBlock   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 37
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A param() 6 6 2
A message() 17 17 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marcosh\PhpTypeChecker\Anomaly;
6
7
use Marcosh\PhpTypeChecker\Check\Parameter;
8
use Roave\BetterReflection\Reflection\ReflectionParameter;
9
10 View Code Duplication
final class MissingFunctionParamTypeWithDocBlock
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * @var ReflectionParameter
14
     */
15
    private $parameter;
16
17
    public function __construct(ReflectionParameter $parameter)
18
    {
19
        $this->parameter = $parameter;
20
    }
21
22
    public static function param(ReflectionParameter $parameter): \Generator
23
    {
24
        if ((new Parameter($parameter))->typeIsMissingWithDocBlock()) {
25
            yield new self($parameter);
26
        }
27
    }
28
29
    public function message(): string
30
    {
31
        try {
32
            $docBlockTypes = $this->parameter->getDocBlockTypes();
33
        } catch (\InvalidArgumentException $e) {
34
            // we need this here to prevent reflection-bocblock errors on @see invalid Fqsen
35
        }
36
37
        return sprintf(
38
            'Parameter <info>%s</info> of function <info>%s</info> defined in <comment>%s</comment> ' .
39
            'does not have a type hint but has a boc block type of <info>%s</info>.',
40
            $this->parameter->getName(),
41
            $this->parameter->getDeclaringFunction()->getName(),
42
            $this->parameter->getDeclaringFunction()->getFileName(),
43
            implode($docBlockTypes)
44
        );
45
    }
46
}
47