DefaultChangelog::getChanges()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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