@@ -18,35 +18,35 @@ |
||
18 | 18 | */ |
19 | 19 | class AnyValueToken implements TokenInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Always scores 3 for any argument. |
|
23 | - * |
|
24 | - * @param $argument |
|
25 | - * |
|
26 | - * @return int |
|
27 | - */ |
|
28 | - public function scoreArgument($argument) |
|
29 | - { |
|
30 | - return 3; |
|
31 | - } |
|
21 | + /** |
|
22 | + * Always scores 3 for any argument. |
|
23 | + * |
|
24 | + * @param $argument |
|
25 | + * |
|
26 | + * @return int |
|
27 | + */ |
|
28 | + public function scoreArgument($argument) |
|
29 | + { |
|
30 | + return 3; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Returns false. |
|
35 | - * |
|
36 | - * @return bool |
|
37 | - */ |
|
38 | - public function isLast() |
|
39 | - { |
|
40 | - return false; |
|
41 | - } |
|
33 | + /** |
|
34 | + * Returns false. |
|
35 | + * |
|
36 | + * @return bool |
|
37 | + */ |
|
38 | + public function isLast() |
|
39 | + { |
|
40 | + return false; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Returns string representation for token. |
|
45 | - * |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function __toString() |
|
49 | - { |
|
50 | - return '*'; |
|
51 | - } |
|
43 | + /** |
|
44 | + * Returns string representation for token. |
|
45 | + * |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function __toString() |
|
49 | + { |
|
50 | + return '*'; |
|
51 | + } |
|
52 | 52 | } |
@@ -20,124 +20,124 @@ |
||
20 | 20 | */ |
21 | 21 | class ArrayEntryToken implements TokenInterface |
22 | 22 | { |
23 | - /** @var \Prophecy\Argument\Token\TokenInterface */ |
|
24 | - private $key; |
|
25 | - /** @var \Prophecy\Argument\Token\TokenInterface */ |
|
26 | - private $value; |
|
27 | - |
|
28 | - /** |
|
29 | - * @param mixed $key exact value or token |
|
30 | - * @param mixed $value exact value or token |
|
31 | - */ |
|
32 | - public function __construct($key, $value) |
|
33 | - { |
|
34 | - $this->key = $this->wrapIntoExactValueToken($key); |
|
35 | - $this->value = $this->wrapIntoExactValueToken($value); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Scores half of combined scores from key and value tokens for same entry. Capped at 8. |
|
40 | - * If argument implements \ArrayAccess without \Traversable, then key token is restricted to ExactValueToken. |
|
41 | - * |
|
42 | - * @param array|\ArrayAccess|\Traversable $argument |
|
43 | - * |
|
44 | - * @throws \Prophecy\Exception\InvalidArgumentException |
|
45 | - * @return bool|int |
|
46 | - */ |
|
47 | - public function scoreArgument($argument) |
|
48 | - { |
|
49 | - if ($argument instanceof \Traversable) { |
|
50 | - $argument = iterator_to_array($argument); |
|
51 | - } |
|
52 | - |
|
53 | - if ($argument instanceof \ArrayAccess) { |
|
54 | - $argument = $this->convertArrayAccessToEntry($argument); |
|
55 | - } |
|
56 | - |
|
57 | - if (!is_array($argument) || empty($argument)) { |
|
58 | - return false; |
|
59 | - } |
|
60 | - |
|
61 | - $keyScores = array_map(array($this->key,'scoreArgument'), array_keys($argument)); |
|
62 | - $valueScores = array_map(array($this->value,'scoreArgument'), $argument); |
|
63 | - $scoreEntry = function ($value, $key) { |
|
64 | - return $value && $key ? min(8, ($key + $value) / 2) : false; |
|
65 | - }; |
|
66 | - |
|
67 | - return max(array_map($scoreEntry, $valueScores, $keyScores)); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns false. |
|
72 | - * |
|
73 | - * @return boolean |
|
74 | - */ |
|
75 | - public function isLast() |
|
76 | - { |
|
77 | - return false; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Returns string representation for token. |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function __toString() |
|
86 | - { |
|
87 | - return sprintf('[..., %s => %s, ...]', $this->key, $this->value); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Returns key |
|
92 | - * |
|
93 | - * @return TokenInterface |
|
94 | - */ |
|
95 | - public function getKey() |
|
96 | - { |
|
97 | - return $this->key; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Returns value |
|
102 | - * |
|
103 | - * @return TokenInterface |
|
104 | - */ |
|
105 | - public function getValue() |
|
106 | - { |
|
107 | - return $this->value; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Wraps non token $value into ExactValueToken |
|
112 | - * |
|
113 | - * @param $value |
|
114 | - * @return TokenInterface |
|
115 | - */ |
|
116 | - private function wrapIntoExactValueToken($value) |
|
117 | - { |
|
118 | - return $value instanceof TokenInterface ? $value : new ExactValueToken($value); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Converts instance of \ArrayAccess to key => value array entry |
|
123 | - * |
|
124 | - * @param \ArrayAccess $object |
|
125 | - * |
|
126 | - * @return array|null |
|
127 | - * @throws \Prophecy\Exception\InvalidArgumentException |
|
128 | - */ |
|
129 | - private function convertArrayAccessToEntry(\ArrayAccess $object) |
|
130 | - { |
|
131 | - if (!$this->key instanceof ExactValueToken) { |
|
132 | - throw new InvalidArgumentException(sprintf( |
|
133 | - 'You can only use exact value tokens to match key of ArrayAccess object'.PHP_EOL. |
|
134 | - 'But you used `%s`.', |
|
135 | - $this->key |
|
136 | - )); |
|
137 | - } |
|
138 | - |
|
139 | - $key = $this->key->getValue(); |
|
140 | - |
|
141 | - return $object->offsetExists($key) ? array($key => $object[$key]) : array(); |
|
142 | - } |
|
23 | + /** @var \Prophecy\Argument\Token\TokenInterface */ |
|
24 | + private $key; |
|
25 | + /** @var \Prophecy\Argument\Token\TokenInterface */ |
|
26 | + private $value; |
|
27 | + |
|
28 | + /** |
|
29 | + * @param mixed $key exact value or token |
|
30 | + * @param mixed $value exact value or token |
|
31 | + */ |
|
32 | + public function __construct($key, $value) |
|
33 | + { |
|
34 | + $this->key = $this->wrapIntoExactValueToken($key); |
|
35 | + $this->value = $this->wrapIntoExactValueToken($value); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Scores half of combined scores from key and value tokens for same entry. Capped at 8. |
|
40 | + * If argument implements \ArrayAccess without \Traversable, then key token is restricted to ExactValueToken. |
|
41 | + * |
|
42 | + * @param array|\ArrayAccess|\Traversable $argument |
|
43 | + * |
|
44 | + * @throws \Prophecy\Exception\InvalidArgumentException |
|
45 | + * @return bool|int |
|
46 | + */ |
|
47 | + public function scoreArgument($argument) |
|
48 | + { |
|
49 | + if ($argument instanceof \Traversable) { |
|
50 | + $argument = iterator_to_array($argument); |
|
51 | + } |
|
52 | + |
|
53 | + if ($argument instanceof \ArrayAccess) { |
|
54 | + $argument = $this->convertArrayAccessToEntry($argument); |
|
55 | + } |
|
56 | + |
|
57 | + if (!is_array($argument) || empty($argument)) { |
|
58 | + return false; |
|
59 | + } |
|
60 | + |
|
61 | + $keyScores = array_map(array($this->key,'scoreArgument'), array_keys($argument)); |
|
62 | + $valueScores = array_map(array($this->value,'scoreArgument'), $argument); |
|
63 | + $scoreEntry = function ($value, $key) { |
|
64 | + return $value && $key ? min(8, ($key + $value) / 2) : false; |
|
65 | + }; |
|
66 | + |
|
67 | + return max(array_map($scoreEntry, $valueScores, $keyScores)); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns false. |
|
72 | + * |
|
73 | + * @return boolean |
|
74 | + */ |
|
75 | + public function isLast() |
|
76 | + { |
|
77 | + return false; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Returns string representation for token. |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function __toString() |
|
86 | + { |
|
87 | + return sprintf('[..., %s => %s, ...]', $this->key, $this->value); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Returns key |
|
92 | + * |
|
93 | + * @return TokenInterface |
|
94 | + */ |
|
95 | + public function getKey() |
|
96 | + { |
|
97 | + return $this->key; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Returns value |
|
102 | + * |
|
103 | + * @return TokenInterface |
|
104 | + */ |
|
105 | + public function getValue() |
|
106 | + { |
|
107 | + return $this->value; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Wraps non token $value into ExactValueToken |
|
112 | + * |
|
113 | + * @param $value |
|
114 | + * @return TokenInterface |
|
115 | + */ |
|
116 | + private function wrapIntoExactValueToken($value) |
|
117 | + { |
|
118 | + return $value instanceof TokenInterface ? $value : new ExactValueToken($value); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Converts instance of \ArrayAccess to key => value array entry |
|
123 | + * |
|
124 | + * @param \ArrayAccess $object |
|
125 | + * |
|
126 | + * @return array|null |
|
127 | + * @throws \Prophecy\Exception\InvalidArgumentException |
|
128 | + */ |
|
129 | + private function convertArrayAccessToEntry(\ArrayAccess $object) |
|
130 | + { |
|
131 | + if (!$this->key instanceof ExactValueToken) { |
|
132 | + throw new InvalidArgumentException(sprintf( |
|
133 | + 'You can only use exact value tokens to match key of ArrayAccess object'.PHP_EOL. |
|
134 | + 'But you used `%s`.', |
|
135 | + $this->key |
|
136 | + )); |
|
137 | + } |
|
138 | + |
|
139 | + $key = $this->key->getValue(); |
|
140 | + |
|
141 | + return $object->offsetExists($key) ? array($key => $object[$key]) : array(); |
|
142 | + } |
|
143 | 143 | } |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | $argument = $this->convertArrayAccessToEntry($argument); |
55 | 55 | } |
56 | 56 | |
57 | - if (!is_array($argument) || empty($argument)) { |
|
57 | + if ( ! is_array($argument) || empty($argument)) { |
|
58 | 58 | return false; |
59 | 59 | } |
60 | 60 | |
61 | - $keyScores = array_map(array($this->key,'scoreArgument'), array_keys($argument)); |
|
62 | - $valueScores = array_map(array($this->value,'scoreArgument'), $argument); |
|
63 | - $scoreEntry = function ($value, $key) { |
|
61 | + $keyScores = array_map(array($this->key, 'scoreArgument'), array_keys($argument)); |
|
62 | + $valueScores = array_map(array($this->value, 'scoreArgument'), $argument); |
|
63 | + $scoreEntry = function($value, $key) { |
|
64 | 64 | return $value && $key ? min(8, ($key + $value) / 2) : false; |
65 | 65 | }; |
66 | 66 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | private function convertArrayAccessToEntry(\ArrayAccess $object) |
130 | 130 | { |
131 | - if (!$this->key instanceof ExactValueToken) { |
|
131 | + if ( ! $this->key instanceof ExactValueToken) { |
|
132 | 132 | throw new InvalidArgumentException(sprintf( |
133 | 133 | 'You can only use exact value tokens to match key of ArrayAccess object'.PHP_EOL. |
134 | 134 | 'But you used `%s`.', |
@@ -18,63 +18,63 @@ |
||
18 | 18 | */ |
19 | 19 | class LogicalAndToken implements TokenInterface |
20 | 20 | { |
21 | - private $tokens = array(); |
|
21 | + private $tokens = array(); |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param array $arguments exact values or tokens |
|
25 | - */ |
|
26 | - public function __construct(array $arguments) |
|
27 | - { |
|
28 | - foreach ($arguments as $argument) { |
|
29 | - if (!$argument instanceof TokenInterface) { |
|
30 | - $argument = new ExactValueToken($argument); |
|
31 | - } |
|
32 | - $this->tokens[] = $argument; |
|
33 | - } |
|
34 | - } |
|
23 | + /** |
|
24 | + * @param array $arguments exact values or tokens |
|
25 | + */ |
|
26 | + public function __construct(array $arguments) |
|
27 | + { |
|
28 | + foreach ($arguments as $argument) { |
|
29 | + if (!$argument instanceof TokenInterface) { |
|
30 | + $argument = new ExactValueToken($argument); |
|
31 | + } |
|
32 | + $this->tokens[] = $argument; |
|
33 | + } |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Scores maximum score from scores returned by tokens for this argument if all of them score. |
|
38 | - * |
|
39 | - * @param $argument |
|
40 | - * |
|
41 | - * @return bool|int |
|
42 | - */ |
|
43 | - public function scoreArgument($argument) |
|
44 | - { |
|
45 | - if (0 === count($this->tokens)) { |
|
46 | - return false; |
|
47 | - } |
|
36 | + /** |
|
37 | + * Scores maximum score from scores returned by tokens for this argument if all of them score. |
|
38 | + * |
|
39 | + * @param $argument |
|
40 | + * |
|
41 | + * @return bool|int |
|
42 | + */ |
|
43 | + public function scoreArgument($argument) |
|
44 | + { |
|
45 | + if (0 === count($this->tokens)) { |
|
46 | + return false; |
|
47 | + } |
|
48 | 48 | |
49 | - $maxScore = 0; |
|
50 | - foreach ($this->tokens as $token) { |
|
51 | - $score = $token->scoreArgument($argument); |
|
52 | - if (false === $score) { |
|
53 | - return false; |
|
54 | - } |
|
55 | - $maxScore = max($score, $maxScore); |
|
56 | - } |
|
49 | + $maxScore = 0; |
|
50 | + foreach ($this->tokens as $token) { |
|
51 | + $score = $token->scoreArgument($argument); |
|
52 | + if (false === $score) { |
|
53 | + return false; |
|
54 | + } |
|
55 | + $maxScore = max($score, $maxScore); |
|
56 | + } |
|
57 | 57 | |
58 | - return $maxScore; |
|
59 | - } |
|
58 | + return $maxScore; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Returns false. |
|
63 | - * |
|
64 | - * @return boolean |
|
65 | - */ |
|
66 | - public function isLast() |
|
67 | - { |
|
68 | - return false; |
|
69 | - } |
|
61 | + /** |
|
62 | + * Returns false. |
|
63 | + * |
|
64 | + * @return boolean |
|
65 | + */ |
|
66 | + public function isLast() |
|
67 | + { |
|
68 | + return false; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Returns string representation for token. |
|
73 | - * |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function __toString() |
|
77 | - { |
|
78 | - return sprintf('bool(%s)', implode(' AND ', $this->tokens)); |
|
79 | - } |
|
71 | + /** |
|
72 | + * Returns string representation for token. |
|
73 | + * |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function __toString() |
|
77 | + { |
|
78 | + return sprintf('bool(%s)', implode(' AND ', $this->tokens)); |
|
79 | + } |
|
80 | 80 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | public function __construct(array $arguments) |
27 | 27 | { |
28 | 28 | foreach ($arguments as $argument) { |
29 | - if (!$argument instanceof TokenInterface) { |
|
29 | + if ( ! $argument instanceof TokenInterface) { |
|
30 | 30 | $argument = new ExactValueToken($argument); |
31 | 31 | } |
32 | 32 | $this->tokens[] = $argument; |
@@ -18,65 +18,65 @@ |
||
18 | 18 | */ |
19 | 19 | class ArrayEveryEntryToken implements TokenInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @var TokenInterface |
|
23 | - */ |
|
24 | - private $value; |
|
21 | + /** |
|
22 | + * @var TokenInterface |
|
23 | + */ |
|
24 | + private $value; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param mixed $value exact value or token |
|
28 | - */ |
|
29 | - public function __construct($value) |
|
30 | - { |
|
31 | - if (!$value instanceof TokenInterface) { |
|
32 | - $value = new ExactValueToken($value); |
|
33 | - } |
|
26 | + /** |
|
27 | + * @param mixed $value exact value or token |
|
28 | + */ |
|
29 | + public function __construct($value) |
|
30 | + { |
|
31 | + if (!$value instanceof TokenInterface) { |
|
32 | + $value = new ExactValueToken($value); |
|
33 | + } |
|
34 | 34 | |
35 | - $this->value = $value; |
|
36 | - } |
|
35 | + $this->value = $value; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * {@inheritdoc} |
|
40 | - */ |
|
41 | - public function scoreArgument($argument) |
|
42 | - { |
|
43 | - if (!$argument instanceof \Traversable && !is_array($argument)) { |
|
44 | - return false; |
|
45 | - } |
|
38 | + /** |
|
39 | + * {@inheritdoc} |
|
40 | + */ |
|
41 | + public function scoreArgument($argument) |
|
42 | + { |
|
43 | + if (!$argument instanceof \Traversable && !is_array($argument)) { |
|
44 | + return false; |
|
45 | + } |
|
46 | 46 | |
47 | - $scores = array(); |
|
48 | - foreach ($argument as $key => $argumentEntry) { |
|
49 | - $scores[] = $this->value->scoreArgument($argumentEntry); |
|
50 | - } |
|
47 | + $scores = array(); |
|
48 | + foreach ($argument as $key => $argumentEntry) { |
|
49 | + $scores[] = $this->value->scoreArgument($argumentEntry); |
|
50 | + } |
|
51 | 51 | |
52 | - if (empty($scores) || in_array(false, $scores, true)) { |
|
53 | - return false; |
|
54 | - } |
|
52 | + if (empty($scores) || in_array(false, $scores, true)) { |
|
53 | + return false; |
|
54 | + } |
|
55 | 55 | |
56 | - return array_sum($scores) / count($scores); |
|
57 | - } |
|
56 | + return array_sum($scores) / count($scores); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inheritdoc} |
|
61 | - */ |
|
62 | - public function isLast() |
|
63 | - { |
|
64 | - return false; |
|
65 | - } |
|
59 | + /** |
|
60 | + * {@inheritdoc} |
|
61 | + */ |
|
62 | + public function isLast() |
|
63 | + { |
|
64 | + return false; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * {@inheritdoc} |
|
69 | - */ |
|
70 | - public function __toString() |
|
71 | - { |
|
72 | - return sprintf('[%s, ..., %s]', $this->value, $this->value); |
|
73 | - } |
|
67 | + /** |
|
68 | + * {@inheritdoc} |
|
69 | + */ |
|
70 | + public function __toString() |
|
71 | + { |
|
72 | + return sprintf('[%s, ..., %s]', $this->value, $this->value); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @return TokenInterface |
|
77 | - */ |
|
78 | - public function getValue() |
|
79 | - { |
|
80 | - return $this->value; |
|
81 | - } |
|
75 | + /** |
|
76 | + * @return TokenInterface |
|
77 | + */ |
|
78 | + public function getValue() |
|
79 | + { |
|
80 | + return $this->value; |
|
81 | + } |
|
82 | 82 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function __construct($value) |
30 | 30 | { |
31 | - if (!$value instanceof TokenInterface) { |
|
31 | + if ( ! $value instanceof TokenInterface) { |
|
32 | 32 | $value = new ExactValueToken($value); |
33 | 33 | } |
34 | 34 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function scoreArgument($argument) |
42 | 42 | { |
43 | - if (!$argument instanceof \Traversable && !is_array($argument)) { |
|
43 | + if ( ! $argument instanceof \Traversable && ! is_array($argument)) { |
|
44 | 44 | return false; |
45 | 45 | } |
46 | 46 |
@@ -18,58 +18,58 @@ |
||
18 | 18 | */ |
19 | 19 | class NotInArrayToken implements TokenInterface |
20 | 20 | { |
21 | - private $token = array(); |
|
22 | - private $strict; |
|
21 | + private $token = array(); |
|
22 | + private $strict; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param array $arguments tokens |
|
26 | - * @param bool $strict |
|
27 | - */ |
|
28 | - public function __construct(array $arguments, $strict = true) |
|
29 | - { |
|
30 | - $this->token = $arguments; |
|
31 | - $this->strict = $strict; |
|
32 | - } |
|
24 | + /** |
|
25 | + * @param array $arguments tokens |
|
26 | + * @param bool $strict |
|
27 | + */ |
|
28 | + public function __construct(array $arguments, $strict = true) |
|
29 | + { |
|
30 | + $this->token = $arguments; |
|
31 | + $this->strict = $strict; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Return scores 8 score if argument is in array. |
|
36 | - * |
|
37 | - * @param $argument |
|
38 | - * |
|
39 | - * @return bool|int |
|
40 | - */ |
|
41 | - public function scoreArgument($argument) |
|
42 | - { |
|
43 | - if (count($this->token) === 0) { |
|
44 | - return false; |
|
45 | - } |
|
34 | + /** |
|
35 | + * Return scores 8 score if argument is in array. |
|
36 | + * |
|
37 | + * @param $argument |
|
38 | + * |
|
39 | + * @return bool|int |
|
40 | + */ |
|
41 | + public function scoreArgument($argument) |
|
42 | + { |
|
43 | + if (count($this->token) === 0) { |
|
44 | + return false; |
|
45 | + } |
|
46 | 46 | |
47 | - if (!\in_array($argument, $this->token, $this->strict)) { |
|
48 | - return 8; |
|
49 | - } |
|
47 | + if (!\in_array($argument, $this->token, $this->strict)) { |
|
48 | + return 8; |
|
49 | + } |
|
50 | 50 | |
51 | - return false; |
|
52 | - } |
|
51 | + return false; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns false. |
|
56 | - * |
|
57 | - * @return boolean |
|
58 | - */ |
|
59 | - public function isLast() |
|
60 | - { |
|
61 | - return false; |
|
62 | - } |
|
54 | + /** |
|
55 | + * Returns false. |
|
56 | + * |
|
57 | + * @return boolean |
|
58 | + */ |
|
59 | + public function isLast() |
|
60 | + { |
|
61 | + return false; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Returns string representation for token. |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function __toString() |
|
70 | - { |
|
71 | - $arrayAsString = implode(', ', $this->token); |
|
72 | - return "[{$arrayAsString}]"; |
|
73 | - } |
|
64 | + /** |
|
65 | + * Returns string representation for token. |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function __toString() |
|
70 | + { |
|
71 | + $arrayAsString = implode(', ', $this->token); |
|
72 | + return "[{$arrayAsString}]"; |
|
73 | + } |
|
74 | 74 | } |
75 | 75 |
@@ -44,7 +44,7 @@ |
||
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | |
47 | - if (!\in_array($argument, $this->token, $this->strict)) { |
|
47 | + if ( ! \in_array($argument, $this->token, $this->strict)) { |
|
48 | 48 | return 8; |
49 | 49 | } |
50 | 50 |
@@ -18,35 +18,35 @@ |
||
18 | 18 | */ |
19 | 19 | class AnyValuesToken implements TokenInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Always scores 2 for any argument. |
|
23 | - * |
|
24 | - * @param $argument |
|
25 | - * |
|
26 | - * @return int |
|
27 | - */ |
|
28 | - public function scoreArgument($argument) |
|
29 | - { |
|
30 | - return 2; |
|
31 | - } |
|
21 | + /** |
|
22 | + * Always scores 2 for any argument. |
|
23 | + * |
|
24 | + * @param $argument |
|
25 | + * |
|
26 | + * @return int |
|
27 | + */ |
|
28 | + public function scoreArgument($argument) |
|
29 | + { |
|
30 | + return 2; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Returns true to stop wildcard from processing other tokens. |
|
35 | - * |
|
36 | - * @return bool |
|
37 | - */ |
|
38 | - public function isLast() |
|
39 | - { |
|
40 | - return true; |
|
41 | - } |
|
33 | + /** |
|
34 | + * Returns true to stop wildcard from processing other tokens. |
|
35 | + * |
|
36 | + * @return bool |
|
37 | + */ |
|
38 | + public function isLast() |
|
39 | + { |
|
40 | + return true; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Returns string representation for token. |
|
45 | - * |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function __toString() |
|
49 | - { |
|
50 | - return '* [, ...]'; |
|
51 | - } |
|
43 | + /** |
|
44 | + * Returns string representation for token. |
|
45 | + * |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function __toString() |
|
49 | + { |
|
50 | + return '* [, ...]'; |
|
51 | + } |
|
52 | 52 | } |
@@ -18,56 +18,56 @@ |
||
18 | 18 | */ |
19 | 19 | class LogicalNotToken implements TokenInterface |
20 | 20 | { |
21 | - /** @var \Prophecy\Argument\Token\TokenInterface */ |
|
22 | - private $token; |
|
21 | + /** @var \Prophecy\Argument\Token\TokenInterface */ |
|
22 | + private $token; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param mixed $value exact value or token |
|
26 | - */ |
|
27 | - public function __construct($value) |
|
28 | - { |
|
29 | - $this->token = $value instanceof TokenInterface? $value : new ExactValueToken($value); |
|
30 | - } |
|
24 | + /** |
|
25 | + * @param mixed $value exact value or token |
|
26 | + */ |
|
27 | + public function __construct($value) |
|
28 | + { |
|
29 | + $this->token = $value instanceof TokenInterface? $value : new ExactValueToken($value); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Scores 4 when preset token does not match the argument. |
|
34 | - * |
|
35 | - * @param $argument |
|
36 | - * |
|
37 | - * @return bool|int |
|
38 | - */ |
|
39 | - public function scoreArgument($argument) |
|
40 | - { |
|
41 | - return false === $this->token->scoreArgument($argument) ? 4 : false; |
|
42 | - } |
|
32 | + /** |
|
33 | + * Scores 4 when preset token does not match the argument. |
|
34 | + * |
|
35 | + * @param $argument |
|
36 | + * |
|
37 | + * @return bool|int |
|
38 | + */ |
|
39 | + public function scoreArgument($argument) |
|
40 | + { |
|
41 | + return false === $this->token->scoreArgument($argument) ? 4 : false; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns true if preset token is last. |
|
46 | - * |
|
47 | - * @return bool|int |
|
48 | - */ |
|
49 | - public function isLast() |
|
50 | - { |
|
51 | - return $this->token->isLast(); |
|
52 | - } |
|
44 | + /** |
|
45 | + * Returns true if preset token is last. |
|
46 | + * |
|
47 | + * @return bool|int |
|
48 | + */ |
|
49 | + public function isLast() |
|
50 | + { |
|
51 | + return $this->token->isLast(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns originating token. |
|
56 | - * |
|
57 | - * @return TokenInterface |
|
58 | - */ |
|
59 | - public function getOriginatingToken() |
|
60 | - { |
|
61 | - return $this->token; |
|
62 | - } |
|
54 | + /** |
|
55 | + * Returns originating token. |
|
56 | + * |
|
57 | + * @return TokenInterface |
|
58 | + */ |
|
59 | + public function getOriginatingToken() |
|
60 | + { |
|
61 | + return $this->token; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Returns string representation for token. |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function __toString() |
|
70 | - { |
|
71 | - return sprintf('not(%s)', $this->token); |
|
72 | - } |
|
64 | + /** |
|
65 | + * Returns string representation for token. |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function __toString() |
|
70 | + { |
|
71 | + return sprintf('not(%s)', $this->token); |
|
72 | + } |
|
73 | 73 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | */ |
27 | 27 | public function __construct($value) |
28 | 28 | { |
29 | - $this->token = $value instanceof TokenInterface? $value : new ExactValueToken($value); |
|
29 | + $this->token = $value instanceof TokenInterface ? $value : new ExactValueToken($value); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -19,68 +19,68 @@ |
||
19 | 19 | |
20 | 20 | class ArrayCountToken implements TokenInterface |
21 | 21 | { |
22 | - private $count; |
|
22 | + private $count; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param integer $value |
|
26 | - */ |
|
27 | - public function __construct($value) |
|
28 | - { |
|
29 | - $this->count = $value; |
|
30 | - } |
|
24 | + /** |
|
25 | + * @param integer $value |
|
26 | + */ |
|
27 | + public function __construct($value) |
|
28 | + { |
|
29 | + $this->count = $value; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Scores 6 when argument has preset number of elements. |
|
34 | - * |
|
35 | - * @param $argument |
|
36 | - * |
|
37 | - * @return bool|int |
|
38 | - */ |
|
39 | - public function scoreArgument($argument) |
|
40 | - { |
|
41 | - return $this->isCountable($argument) && $this->hasProperCount($argument) ? 6 : false; |
|
42 | - } |
|
32 | + /** |
|
33 | + * Scores 6 when argument has preset number of elements. |
|
34 | + * |
|
35 | + * @param $argument |
|
36 | + * |
|
37 | + * @return bool|int |
|
38 | + */ |
|
39 | + public function scoreArgument($argument) |
|
40 | + { |
|
41 | + return $this->isCountable($argument) && $this->hasProperCount($argument) ? 6 : false; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns false. |
|
46 | - * |
|
47 | - * @return boolean |
|
48 | - */ |
|
49 | - public function isLast() |
|
50 | - { |
|
51 | - return false; |
|
52 | - } |
|
44 | + /** |
|
45 | + * Returns false. |
|
46 | + * |
|
47 | + * @return boolean |
|
48 | + */ |
|
49 | + public function isLast() |
|
50 | + { |
|
51 | + return false; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns string representation for token. |
|
56 | - * |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function __toString() |
|
60 | - { |
|
61 | - return sprintf('count(%s)', $this->count); |
|
62 | - } |
|
54 | + /** |
|
55 | + * Returns string representation for token. |
|
56 | + * |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function __toString() |
|
60 | + { |
|
61 | + return sprintf('count(%s)', $this->count); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Returns true if object is either array or instance of \Countable |
|
66 | - * |
|
67 | - * @param $argument |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - private function isCountable($argument) |
|
71 | - { |
|
72 | - return (is_array($argument) || $argument instanceof \Countable); |
|
73 | - } |
|
64 | + /** |
|
65 | + * Returns true if object is either array or instance of \Countable |
|
66 | + * |
|
67 | + * @param $argument |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + private function isCountable($argument) |
|
71 | + { |
|
72 | + return (is_array($argument) || $argument instanceof \Countable); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Returns true if $argument has expected number of elements |
|
77 | - * |
|
78 | - * @param array|\Countable $argument |
|
79 | - * |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - private function hasProperCount($argument) |
|
83 | - { |
|
84 | - return $this->count === count($argument); |
|
85 | - } |
|
75 | + /** |
|
76 | + * Returns true if $argument has expected number of elements |
|
77 | + * |
|
78 | + * @param array|\Countable $argument |
|
79 | + * |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + private function hasProperCount($argument) |
|
83 | + { |
|
84 | + return $this->count === count($argument); |
|
85 | + } |
|
86 | 86 | } |
@@ -18,38 +18,38 @@ |
||
18 | 18 | */ |
19 | 19 | class ApproximateValueToken implements TokenInterface |
20 | 20 | { |
21 | - private $value; |
|
22 | - private $precision; |
|
21 | + private $value; |
|
22 | + private $precision; |
|
23 | 23 | |
24 | - public function __construct($value, $precision = 0) |
|
25 | - { |
|
26 | - $this->value = $value; |
|
27 | - $this->precision = $precision; |
|
28 | - } |
|
24 | + public function __construct($value, $precision = 0) |
|
25 | + { |
|
26 | + $this->value = $value; |
|
27 | + $this->precision = $precision; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - public function scoreArgument($argument) |
|
34 | - { |
|
35 | - return round((float)$argument, $this->precision) === round($this->value, $this->precision) ? 10 : false; |
|
36 | - } |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + public function scoreArgument($argument) |
|
34 | + { |
|
35 | + return round((float)$argument, $this->precision) === round($this->value, $this->precision) ? 10 : false; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * {@inheritdoc} |
|
40 | - */ |
|
41 | - public function isLast() |
|
42 | - { |
|
43 | - return false; |
|
44 | - } |
|
38 | + /** |
|
39 | + * {@inheritdoc} |
|
40 | + */ |
|
41 | + public function isLast() |
|
42 | + { |
|
43 | + return false; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Returns string representation for token. |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function __toString() |
|
52 | - { |
|
53 | - return sprintf('≅%s', round($this->value, $this->precision)); |
|
54 | - } |
|
46 | + /** |
|
47 | + * Returns string representation for token. |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function __toString() |
|
52 | + { |
|
53 | + return sprintf('≅%s', round($this->value, $this->precision)); |
|
54 | + } |
|
55 | 55 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | */ |
33 | 33 | public function scoreArgument($argument) |
34 | 34 | { |
35 | - return round((float)$argument, $this->precision) === round($this->value, $this->precision) ? 10 : false; |
|
35 | + return round((float) $argument, $this->precision) === round($this->value, $this->precision) ? 10 : false; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |