1 | <?php |
||
21 | class PostconditionCheckerAspect extends AbstractContractAspect implements Aspect |
||
22 | { |
||
23 | /** |
||
24 | * @var MethodConditionFetcher |
||
25 | */ |
||
26 | private $methodConditionFetcher; |
||
27 | |||
28 | public function __construct(Reader $reader) |
||
33 | |||
34 | /** |
||
35 | * Verifies post-condition contract for the method |
||
36 | * |
||
37 | * @Around("@execution(PhpDeal\Annotation\Ensure)") |
||
38 | * @param MethodInvocation $invocation |
||
39 | * |
||
40 | * @throws ContractViolation |
||
41 | * @return mixed |
||
42 | */ |
||
43 | 12 | public function postConditionContract(MethodInvocation $invocation) |
|
44 | { |
||
45 | 12 | $object = $invocation->getThis(); |
|
46 | 12 | $args = $this->fetchMethodArguments($invocation); |
|
47 | 12 | $class = $invocation->getMethod()->getDeclaringClass(); |
|
48 | 12 | if ($class->isCloneable()) { |
|
49 | 12 | $args['__old'] = clone $object; |
|
50 | } |
||
51 | |||
52 | 12 | $result = $invocation->proceed(); |
|
53 | 12 | $args['__result'] = $result; |
|
54 | 12 | $allContracts = $this->fetchAllContracts($invocation); |
|
55 | |||
56 | 12 | $this->ensureContracts($invocation, $allContracts, $object, $class->name, $args); |
|
57 | |||
58 | 4 | return $result; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param MethodInvocation $invocation |
||
63 | * @return array |
||
64 | */ |
||
65 | 12 | private function fetchAllContracts(MethodInvocation $invocation) |
|
76 | |||
77 | /** |
||
78 | * @param MethodInvocation $invocation |
||
79 | * @return array |
||
80 | */ |
||
81 | 12 | private function fetchParentsContracts(MethodInvocation $invocation) |
|
88 | } |
||
89 |