ContractViolation   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
1
<?php
2
3
/**
4
 * PHP Deal framework
5
 *
6
 * @copyright Copyright 2019, Lisachenko Alexander <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpDeal\Exception;
15
16
use Go\Aop\Intercept\MethodInvocation;
17
use Throwable;
18
19
/**
20
 * Specific contract violation exception to point to the file and line of invocation
21
 */
22
class ContractViolation extends \LogicException
23
{
24
25
    /**
26
     * Violation constructor
27
     *
28
     * @param MethodInvocation $invocation Current method invocation
29
     * @param string $contract Violated contract code
30
     * @param Throwable $previous
31
     */
32 28
    public function __construct(MethodInvocation $invocation, $contract, Throwable $previous = null)
33
    {
34 28
        $obj        = $invocation->getThis();
35 28
        $objName    = \is_object($obj) ? \get_class($obj) : $obj;
36 28
        $method     = $invocation->getMethod();
37 28
        $args       = \implode(', ', $invocation->getArguments());
38
39 28
        $message = "Contract {$contract} violated with argument set {{$args}} for {$objName}->{$method->name}";
40 28
        parent::__construct($message, 0, $previous);
41
42 28
        $this->file = $method->getFileName();
43 28
        $this->line = $method->getStartLine() + 1;
44 28
    }
45
}
46