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.
Completed
Pull Request — master (#153)
by joseph
16:48
created

WeightEmbeddable::validateUnit()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 8
nop 1
dl 0
loc 13
ccs 0
cts 13
cp 0
crap 20
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Attribute;
4
5
use Doctrine\ORM\Mapping\ClassMetadata;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Attribute\HasWeightEmbeddableInterface;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Attribute\WeightEmbeddableInterface;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\AbstractEmbeddableObject;
9
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
10
11
class WeightEmbeddable extends AbstractEmbeddableObject implements WeightEmbeddableInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $unit;
17
    /**
18
     * @var float
19
     */
20
    private $value;
21
22
    public function __construct(string $unit, float $value)
23
    {
24
        $this->validateUnit($unit, $value);
0 ignored issues
show
Unused Code introduced by
The call to EdmondsCommerce\Doctrine...eddable::validateUnit() has too many arguments starting with $value. ( Ignorable by Annotation )

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

24
        $this->/** @scrutinizer ignore-call */ 
25
               validateUnit($unit, $value);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
25
        $this->unit  = $unit;
26
        $this->value = $value;
27
    }
28
29
    private function validateUnit(string $unit): void
30
    {
31
        $errors = [];
32
        if ('' === $unit) {
33
            $errors[] = 'unit is empty';
34
        }
35
        if (!\in_array($unit, WeightEmbeddableInterface::VALID_UNITS, true)) {
36
            $errors[] = 'invalid unit';
37
        }
38
        if ([] === $errors) {
39
            return;
40
        }
41
        throw new \InvalidArgumentException('Invalid arguments: ' . print_r($errors, true));
42
    }
43
44
    /**
45
     * @param ClassMetadata $metadata
46
     * @SuppressWarnings(PHPMD.StaticAccess)
47
     */
48
    public static function loadMetadata(ClassMetadata $metadata): void
49
    {
50
        $builder = self::setEmbeddableAndGetBuilder($metadata);
51
        MappingHelper::setSimpleFields(
52
            [
53
                WeightEmbeddableInterface::EMBEDDED_PROP_UNIT  => MappingHelper::TYPE_STRING,
54
                WeightEmbeddableInterface::EMBEDDED_PROP_VALUE => MappingHelper::TYPE_STRING,
55
            ],
56
            $builder
57
        );
58
    }
59
60
    public function __toString(): string
61
    {
62
        return (string)print_r(
63
            [
64
                'weightEmbeddable' => [
65
                    WeightEmbeddableInterface::EMBEDDED_PROP_UNIT  => $this->getUnit(),
66
                    WeightEmbeddableInterface::EMBEDDED_PROP_VALUE => $this->getValue(),
67
                ],
68
            ],
69
            true
70
        );
71
    }
72
73
    public function getUnit(): string
74
    {
75
        return $this->unit;
76
    }
77
78
    public function getValue(): float
79
    {
80
        return $this->value;
81
    }
82
83
    protected function getPrefix(): string
84
    {
85
        return HasWeightEmbeddableInterface::PROP_WEIGHT_EMBEDDABLE;
86
    }
87
}