DefaultAttribute   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 31
ccs 13
cts 13
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMaxLength() 0 3 1
A getName() 0 3 1
A getDataType() 0 3 1
A __toArray() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\Attribute;
6
7
use Inspirum\Arrayable\BaseModel;
8
9
/**
10
 * @extends \Inspirum\Arrayable\BaseModel<string,mixed>
11
 */
12
final class DefaultAttribute extends BaseModel implements Attribute
13
{
14 5
    public function __construct(
15
        private readonly string $name,
16
        private readonly string $dataType,
17
        private readonly ?string $maxLength,
18
    ) {
19 5
    }
20
21 2
    public function getName(): string
22
    {
23 2
        return $this->name;
24
    }
25
26 1
    public function getDataType(): string
27
    {
28 1
        return $this->dataType;
29
    }
30
31 1
    public function getMaxLength(): ?string
32
    {
33 1
        return $this->maxLength;
34
    }
35
36
    /** @inheritDoc */
37 2
    public function __toArray(): array
38
    {
39 2
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('name' => $...h' => $this->maxLength) returns the type array<string,null|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...
40 2
            'name' => $this->name,
41 2
            'dataType' => $this->dataType,
42 2
            'maxLength' => $this->maxLength,
43 2
        ];
44
    }
45
}
46