Completed
Push — master ( c48d17...757eef )
by Andreu
13s
created

InconsistentCurrenciesError::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Adsmurai\Currency\Errors;
4
5
use Adsmurai\Currency\Contracts\CurrencyError;
6
use Adsmurai\Currency\Contracts\Currency;
7
use LogicException;
8
9
final class InconsistentCurrenciesError extends LogicException implements CurrencyError
10
{
11
    /** @var Currency */
12
    private $ct1;
13
    /** @var Currency */
14
    private $ct2;
15
16 2
    public function __construct(Currency $ct1, Currency $ct2)
17
    {
18 2
        $this->ct1 = $ct1;
19 2
        $this->ct2 = $ct2;
20
21 2
        if ($ct1 === $ct2) {
22 1
            throw new LogicException(
23 1
                'Trying to construct InconsistentCurrencyTypesError with exactly equal CurrencyType instances'
24
            );
25
        }
26
27 1
        parent::__construct('Same ISO currency code but different currency settings', 0, null);
28 1
    }
29
30
    /**
31
     * @return Currency[]
32
     */
33 1
    public function getInconsistentCurrencyTypes(): array
34
    {
35 1
        return [$this->ct1, $this->ct2];
36
    }
37
}
38