DefaultManipulationUnit   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
c 1
b 0
f 1
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getCode() 0 3 1
A __construct() 0 4 1
A __toArray() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\ManipulationUnit;
6
7
use Inspirum\Arrayable\BaseModel;
8
9
/**
10
 * @extends \Inspirum\Arrayable\BaseModel<string,mixed>
11
 */
12
final class DefaultManipulationUnit extends BaseModel implements ManipulationUnit
13
{
14 5
    public function __construct(
15
        private readonly string $code,
16
        private readonly string $name,
17
    ) {
18 5
    }
19
20 1
    public function getCode(): string
21
    {
22 1
        return $this->code;
23
    }
24
25 1
    public function getName(): string
26
    {
27 1
        return $this->name;
28
    }
29
30
    /** @inheritDoc */
31 2
    public function __toArray(): array
32
    {
33 2
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('code' => $... 'name' => $this->name) returns the type array<string,string> which is incompatible with the return type mandated by Inspirum\Arrayable\BaseModel::__toArray() of Inspirum\Arrayable\TValue[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
34 2
            'code' => $this->code,
35 2
            'name' => $this->name,
36 2
        ];
37
    }
38
}
39