Completed
Pull Request — master (#10)
by
unknown
03:04
created

ContractCheckerAspect::getMethodArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * PHP Deal framework
4
 *
5
 * @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace PhpDeal\Aspect;
12
13
use Doctrine\Common\Annotations\Reader;
14
use Go\Aop\Aspect;
15
use Go\Aop\Intercept\MethodInvocation;
16
use Go\Lang\Annotation\Around;
17
use Go\Lang\Annotation\Before;
18
use PhpDeal\Contract\InvariantContract;
19
use PhpDeal\Contract\PostconditionContract;
20
use PhpDeal\Contract\PreconditionContract;
21
use PhpDeal\Exception\ContractViolation;
22
23
class ContractCheckerAspect implements Aspect
24
{
25
    /**
26
     * Annotation reader
27
     *
28
     * @var Reader
29
     */
30
    private $reader;
31
32
    /**
33
     * Default constructor
34
     *
35
     * @param Reader $reader Annotation reader
36
     */
37
    public function __construct(Reader $reader)
38
    {
39
        $this->reader = $reader;
40
    }
41
42
    /**
43
     * Verifies pre-condition contract for the method
44
     *
45
     * @param MethodInvocation $invocation
46
     * @Before("@execution(PhpDeal\Annotation\Verify)")
47
     *
48
     * @throws ContractViolation
49
     */
50 19
    public function preConditionContract(MethodInvocation $invocation)
51
    {
52 19
        (new PreconditionContract($this->reader))->check($invocation);
53 6
    }
54
55
    /**
56
     * Verifies post-condition contract for the method
57
     *
58
     * @Around("@execution(PhpDeal\Annotation\Ensure)")
59
     * @param MethodInvocation $invocation
60
     *
61
     * @throws ContractViolation
62
     * @return mixed
63
     */
64 8
    public function postConditionContract(MethodInvocation $invocation)
65
    {
66 8
        return (new PostconditionContract($this->reader))->check($invocation);
67
    }
68
69
    /**
70
     * Verifies invariants for contract class
71
     *
72
     * @Around("@within(PhpDeal\Annotation\Invariant) && execution(public **->*(*))")
73
     * @param MethodInvocation $invocation
74
     *
75
     * @throws ContractViolation
76
     * @return mixed
77
     */
78 7
    public function invariantContract(MethodInvocation $invocation)
79
    {
80 7
        return (new InvariantContract($this->reader))->check($invocation);
81
    }
82
}
83