Passed
Branch master (0d8fc3)
by Tomáš
12:26
created

DefaultCountry::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 0
c 1
b 0
f 1
nc 1
nop 5
dl 0
loc 7
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\Country;
6
7
use Inspirum\Arrayable\BaseModel;
8
9
/**
10
 * @extends \Inspirum\Arrayable\BaseModel<string,mixed>
11
 */
12
final class DefaultCountry extends BaseModel implements Country
13
{
14
    /**
15
     * @param array<string,string> $names
16
     * @param array<string>        $phonePrefixes
17
     */
18 4
    public function __construct(
19
        private array $names,
20
        private string $code,
21
        private string $currencyCode,
22
        private array $phonePrefixes,
23
        private string $continent
24
    ) {
25
    }
26
27
    /** @inheritDoc */
28 1
    public function getNames(): array
29
    {
30 1
        return $this->names;
31
    }
32
33 1
    public function getName(string $locale): ?string
34
    {
35 1
        return $this->names[$locale] ?? null;
36
    }
37
38 1
    public function getCode(): string
39
    {
40 1
        return $this->code;
41
    }
42
43 1
    public function getCurrencyCode(): string
44
    {
45 1
        return $this->currencyCode;
46
    }
47
48
    /** @inheritDoc */
49 1
    public function getPhonePrefixes(): array
50
    {
51 1
        return $this->phonePrefixes;
52
    }
53
54 1
    public function getPhonePrefix(): string
55
    {
56 1
        return $this->phonePrefixes[0];
57
    }
58
59 1
    public function getContinent(): string
60
    {
61 1
        return $this->continent;
62
    }
63
64
    /** @inheritDoc */
65 1
    public function __toArray(): array
66
    {
67
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('names' => ...t' => $this->continent) returns the type array<string,array|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...
68 1
            'names'         => $this->names,
69 1
            'code'          => $this->code,
70 1
            'currencyCode'  => $this->currencyCode,
71 1
            'phonePrefixes' => $this->phonePrefixes,
72 1
            'continent'     => $this->continent,
73
        ];
74
    }
75
}
76