DefaultChangelog   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 getChanges() 0 3 1
A getDate() 0 3 1
A __construct() 0 5 1
A getVersion() 0 3 1
A __toArray() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\Changelog;
6
7
use DateTimeInterface;
8
use Inspirum\Arrayable\BaseModel;
9
10
/**
11
 * @extends \Inspirum\Arrayable\BaseModel<string,mixed>
12
 */
13
final class DefaultChangelog extends BaseModel implements Changelog
14
{
15 5
    public function __construct(
16
        private readonly string $version,
17
        private readonly DateTimeInterface $date,
18
        private readonly ChangelogStatusCollection $changes,
19
    ) {
20 5
    }
21
22 4
    public function getVersion(): string
23
    {
24 4
        return $this->version;
25
    }
26
27 1
    public function getDate(): DateTimeInterface
28
    {
29 1
        return $this->date;
30
    }
31
32 1
    public function getChanges(): ChangelogStatusCollection
33
    {
34 1
        return $this->changes;
35
    }
36
37
    /** @inheritDoc */
38 2
    public function __toArray(): array
39
    {
40 2
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('code' => $...->changes->__toArray()) returns the type array<string,Inspirum\Arrayable\TValue[]|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...
41 2
            'code' => $this->version,
42 2
            'date' => $this->date->format('Y-m-d'),
43 2
            'changes' => $this->changes->__toArray(),
44 2
        ];
45
    }
46
}
47