File tree 3 files changed +39
-3
lines changed
3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 10
10
11
11
namespace PhpDeal \Contract ;
12
12
13
+ use Doctrine \Common \Annotations \Reader ;
13
14
use Go \Aop \Intercept \MethodInvocation ;
14
15
use PhpDeal \Contract \Fetcher \ParentClass \InvariantFetcher ;
15
16
use PhpDeal \Exception \ContractViolation ;
18
19
19
20
class InvariantContract extends Contract
20
21
{
22
+ /**
23
+ * @var InvariantFetcher
24
+ */
25
+ private $ invariantFetcher ;
26
+
27
+ public function __construct (Reader $ reader )
28
+ {
29
+ parent ::__construct ($ reader );
30
+ $ this ->invariantFetcher = new InvariantFetcher (Invariant::class);
31
+ }
32
+
21
33
/**
22
34
* Verifies invariants for contract class
23
35
*
@@ -66,7 +78,7 @@ private function fetchAllContracts(ReflectionClass $class)
66
78
*/
67
79
private function fetchParentsContracts (ReflectionClass $ class )
68
80
{
69
- return ( new InvariantFetcher (Invariant::class)) ->getConditions (
81
+ return $ this -> invariantFetcher ->getConditions (
70
82
$ class ,
71
83
$ this ->reader
72
84
);
Original file line number Diff line number Diff line change 10
10
11
11
namespace PhpDeal \Contract ;
12
12
13
+ use Doctrine \Common \Annotations \Reader ;
13
14
use Go \Aop \Intercept \MethodInvocation ;
14
15
use PhpDeal \Contract \Fetcher \ParentClass \MethodConditionFetcher ;
15
16
use PhpDeal \Exception \ContractViolation ;
16
17
use PhpDeal \Annotation \Ensure ;
17
18
18
19
class PostconditionContract extends Contract
19
20
{
21
+ /**
22
+ * @var MethodConditionFetcher
23
+ */
24
+ private $ methodConditionFetcher ;
25
+
26
+ public function __construct (Reader $ reader )
27
+ {
28
+ parent ::__construct ($ reader );
29
+ $ this ->methodConditionFetcher = new MethodConditionFetcher (Ensure::class);
30
+ }
31
+
20
32
/**
21
33
* @param MethodInvocation $invocation
22
34
* @throws ContractViolation
@@ -62,7 +74,7 @@ private function fetchAllContracts(MethodInvocation $invocation)
62
74
*/
63
75
private function fetchParentsContracts (MethodInvocation $ invocation )
64
76
{
65
- return ( new MethodConditionFetcher (Ensure::class)) ->getConditions (
77
+ return $ this -> methodConditionFetcher ->getConditions (
66
78
$ invocation ->getMethod ()->getDeclaringClass (),
67
79
$ this ->reader ,
68
80
$ invocation ->getMethod ()->name
Original file line number Diff line number Diff line change 10
10
11
11
namespace PhpDeal \Contract ;
12
12
13
+ use Doctrine \Common \Annotations \Reader ;
13
14
use Go \Aop \Intercept \MethodInvocation ;
14
15
use PhpDeal \Contract \Fetcher \ParentClass \MethodConditionWithInheritDocFetcher ;
15
16
use PhpDeal \Exception \ContractViolation ;
16
17
use PhpDeal \Annotation \Verify ;
17
18
18
19
class PreconditionContract extends Contract
19
20
{
21
+ /**
22
+ * @var MethodConditionWithInheritDocFetcher
23
+ */
24
+ private $ methodConditionFetcher ;
25
+
26
+ public function __construct (Reader $ reader )
27
+ {
28
+ parent ::__construct ($ reader );
29
+ $ this ->methodConditionFetcher = new MethodConditionWithInheritDocFetcher (Verify::class);
30
+ }
31
+
20
32
/**
21
33
* @param MethodInvocation $invocation
22
34
* @Before("@execution(PhpDeal\Annotation\Verify)")
@@ -55,7 +67,7 @@ private function fetchAllContracts(MethodInvocation $invocation)
55
67
*/
56
68
private function fetchParentsContracts (MethodInvocation $ invocation )
57
69
{
58
- return ( new MethodConditionWithInheritDocFetcher (Verify::class)) ->getConditions (
70
+ return $ this -> methodConditionFetcher ->getConditions (
59
71
$ invocation ->getMethod ()->getDeclaringClass (),
60
72
$ this ->reader ,
61
73
$ invocation ->getMethod ()->name
You can’t perform that action at this time.
0 commit comments