@@ -18,27 +18,27 @@ |
||
18 | 18 | */ |
19 | 19 | class Revealer implements RevealerInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Unwraps value(s). |
|
23 | - * |
|
24 | - * @param mixed $value |
|
25 | - * |
|
26 | - * @return mixed |
|
27 | - */ |
|
28 | - public function reveal($value) |
|
29 | - { |
|
30 | - if (is_array($value)) { |
|
31 | - return array_map(array($this, __FUNCTION__), $value); |
|
32 | - } |
|
21 | + /** |
|
22 | + * Unwraps value(s). |
|
23 | + * |
|
24 | + * @param mixed $value |
|
25 | + * |
|
26 | + * @return mixed |
|
27 | + */ |
|
28 | + public function reveal($value) |
|
29 | + { |
|
30 | + if (is_array($value)) { |
|
31 | + return array_map(array($this, __FUNCTION__), $value); |
|
32 | + } |
|
33 | 33 | |
34 | - if (!is_object($value)) { |
|
35 | - return $value; |
|
36 | - } |
|
34 | + if (!is_object($value)) { |
|
35 | + return $value; |
|
36 | + } |
|
37 | 37 | |
38 | - if ($value instanceof ProphecyInterface) { |
|
39 | - $value = $value->reveal(); |
|
40 | - } |
|
38 | + if ($value instanceof ProphecyInterface) { |
|
39 | + $value = $value->reveal(); |
|
40 | + } |
|
41 | 41 | |
42 | - return $value; |
|
43 | - } |
|
42 | + return $value; |
|
43 | + } |
|
44 | 44 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | return array_map(array($this, __FUNCTION__), $value); |
32 | 32 | } |
33 | 33 | |
34 | - if (!is_object($value)) { |
|
34 | + if ( ! is_object($value)) { |
|
35 | 35 | return $value; |
36 | 36 | } |
37 | 37 |
@@ -18,10 +18,10 @@ |
||
18 | 18 | */ |
19 | 19 | interface ProphecyInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Reveals prophecy object (double) . |
|
23 | - * |
|
24 | - * @return object |
|
25 | - */ |
|
26 | - public function reveal(); |
|
21 | + /** |
|
22 | + * Reveals prophecy object (double) . |
|
23 | + * |
|
24 | + * @return object |
|
25 | + */ |
|
26 | + public function reveal(); |
|
27 | 27 | } |
@@ -18,84 +18,84 @@ |
||
18 | 18 | */ |
19 | 19 | class ArgumentsWildcard |
20 | 20 | { |
21 | - /** |
|
22 | - * @var Token\TokenInterface[] |
|
23 | - */ |
|
24 | - private $tokens = array(); |
|
25 | - private $string; |
|
21 | + /** |
|
22 | + * @var Token\TokenInterface[] |
|
23 | + */ |
|
24 | + private $tokens = array(); |
|
25 | + private $string; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Initializes wildcard. |
|
29 | - * |
|
30 | - * @param array $arguments Array of argument tokens or values |
|
31 | - */ |
|
32 | - public function __construct(array $arguments) |
|
33 | - { |
|
34 | - foreach ($arguments as $argument) { |
|
35 | - if (!$argument instanceof Token\TokenInterface) { |
|
36 | - $argument = new Token\ExactValueToken($argument); |
|
37 | - } |
|
27 | + /** |
|
28 | + * Initializes wildcard. |
|
29 | + * |
|
30 | + * @param array $arguments Array of argument tokens or values |
|
31 | + */ |
|
32 | + public function __construct(array $arguments) |
|
33 | + { |
|
34 | + foreach ($arguments as $argument) { |
|
35 | + if (!$argument instanceof Token\TokenInterface) { |
|
36 | + $argument = new Token\ExactValueToken($argument); |
|
37 | + } |
|
38 | 38 | |
39 | - $this->tokens[] = $argument; |
|
40 | - } |
|
41 | - } |
|
39 | + $this->tokens[] = $argument; |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Calculates wildcard match score for provided arguments. |
|
45 | - * |
|
46 | - * @param array $arguments |
|
47 | - * |
|
48 | - * @return false|int False OR integer score (higher - better) |
|
49 | - */ |
|
50 | - public function scoreArguments(array $arguments) |
|
51 | - { |
|
52 | - if (0 == count($arguments) && 0 == count($this->tokens)) { |
|
53 | - return 1; |
|
54 | - } |
|
43 | + /** |
|
44 | + * Calculates wildcard match score for provided arguments. |
|
45 | + * |
|
46 | + * @param array $arguments |
|
47 | + * |
|
48 | + * @return false|int False OR integer score (higher - better) |
|
49 | + */ |
|
50 | + public function scoreArguments(array $arguments) |
|
51 | + { |
|
52 | + if (0 == count($arguments) && 0 == count($this->tokens)) { |
|
53 | + return 1; |
|
54 | + } |
|
55 | 55 | |
56 | - $arguments = array_values($arguments); |
|
57 | - $totalScore = 0; |
|
58 | - foreach ($this->tokens as $i => $token) { |
|
59 | - $argument = isset($arguments[$i]) ? $arguments[$i] : null; |
|
60 | - if (1 >= $score = $token->scoreArgument($argument)) { |
|
61 | - return false; |
|
62 | - } |
|
56 | + $arguments = array_values($arguments); |
|
57 | + $totalScore = 0; |
|
58 | + foreach ($this->tokens as $i => $token) { |
|
59 | + $argument = isset($arguments[$i]) ? $arguments[$i] : null; |
|
60 | + if (1 >= $score = $token->scoreArgument($argument)) { |
|
61 | + return false; |
|
62 | + } |
|
63 | 63 | |
64 | - $totalScore += $score; |
|
64 | + $totalScore += $score; |
|
65 | 65 | |
66 | - if (true === $token->isLast()) { |
|
67 | - return $totalScore; |
|
68 | - } |
|
69 | - } |
|
66 | + if (true === $token->isLast()) { |
|
67 | + return $totalScore; |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - if (count($arguments) > count($this->tokens)) { |
|
72 | - return false; |
|
73 | - } |
|
71 | + if (count($arguments) > count($this->tokens)) { |
|
72 | + return false; |
|
73 | + } |
|
74 | 74 | |
75 | - return $totalScore; |
|
76 | - } |
|
75 | + return $totalScore; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Returns string representation for wildcard. |
|
80 | - * |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function __toString() |
|
84 | - { |
|
85 | - if (null === $this->string) { |
|
86 | - $this->string = implode(', ', array_map(function ($token) { |
|
87 | - return (string) $token; |
|
88 | - }, $this->tokens)); |
|
89 | - } |
|
78 | + /** |
|
79 | + * Returns string representation for wildcard. |
|
80 | + * |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function __toString() |
|
84 | + { |
|
85 | + if (null === $this->string) { |
|
86 | + $this->string = implode(', ', array_map(function ($token) { |
|
87 | + return (string) $token; |
|
88 | + }, $this->tokens)); |
|
89 | + } |
|
90 | 90 | |
91 | - return $this->string; |
|
92 | - } |
|
91 | + return $this->string; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function getTokens() |
|
98 | - { |
|
99 | - return $this->tokens; |
|
100 | - } |
|
94 | + /** |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function getTokens() |
|
98 | + { |
|
99 | + return $this->tokens; |
|
100 | + } |
|
101 | 101 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public function __construct(array $arguments) |
33 | 33 | { |
34 | 34 | foreach ($arguments as $argument) { |
35 | - if (!$argument instanceof Token\TokenInterface) { |
|
35 | + if ( ! $argument instanceof Token\TokenInterface) { |
|
36 | 36 | $argument = new Token\ExactValueToken($argument); |
37 | 37 | } |
38 | 38 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | public function __toString() |
84 | 84 | { |
85 | 85 | if (null === $this->string) { |
86 | - $this->string = implode(', ', array_map(function ($token) { |
|
86 | + $this->string = implode(', ', array_map(function($token) { |
|
87 | 87 | return (string) $token; |
88 | 88 | }, $this->tokens)); |
89 | 89 | } |
@@ -20,56 +20,56 @@ |
||
20 | 20 | */ |
21 | 21 | class CallbackToken implements TokenInterface |
22 | 22 | { |
23 | - private $callback; |
|
23 | + private $callback; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Initializes token. |
|
27 | - * |
|
28 | - * @param callable $callback |
|
29 | - * |
|
30 | - * @throws \Prophecy\Exception\InvalidArgumentException |
|
31 | - */ |
|
32 | - public function __construct($callback) |
|
33 | - { |
|
34 | - if (!is_callable($callback)) { |
|
35 | - throw new InvalidArgumentException(sprintf( |
|
36 | - 'Callable expected as an argument to CallbackToken, but got %s.', |
|
37 | - gettype($callback) |
|
38 | - )); |
|
39 | - } |
|
25 | + /** |
|
26 | + * Initializes token. |
|
27 | + * |
|
28 | + * @param callable $callback |
|
29 | + * |
|
30 | + * @throws \Prophecy\Exception\InvalidArgumentException |
|
31 | + */ |
|
32 | + public function __construct($callback) |
|
33 | + { |
|
34 | + if (!is_callable($callback)) { |
|
35 | + throw new InvalidArgumentException(sprintf( |
|
36 | + 'Callable expected as an argument to CallbackToken, but got %s.', |
|
37 | + gettype($callback) |
|
38 | + )); |
|
39 | + } |
|
40 | 40 | |
41 | - $this->callback = $callback; |
|
42 | - } |
|
41 | + $this->callback = $callback; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Scores 7 if callback returns true, false otherwise. |
|
46 | - * |
|
47 | - * @param $argument |
|
48 | - * |
|
49 | - * @return bool|int |
|
50 | - */ |
|
51 | - public function scoreArgument($argument) |
|
52 | - { |
|
53 | - return call_user_func($this->callback, $argument) ? 7 : false; |
|
54 | - } |
|
44 | + /** |
|
45 | + * Scores 7 if callback returns true, false otherwise. |
|
46 | + * |
|
47 | + * @param $argument |
|
48 | + * |
|
49 | + * @return bool|int |
|
50 | + */ |
|
51 | + public function scoreArgument($argument) |
|
52 | + { |
|
53 | + return call_user_func($this->callback, $argument) ? 7 : false; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Returns false. |
|
58 | - * |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function isLast() |
|
62 | - { |
|
63 | - return false; |
|
64 | - } |
|
56 | + /** |
|
57 | + * Returns false. |
|
58 | + * |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function isLast() |
|
62 | + { |
|
63 | + return false; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Returns string representation for token. |
|
68 | - * |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function __toString() |
|
72 | - { |
|
73 | - return 'callback()'; |
|
74 | - } |
|
66 | + /** |
|
67 | + * Returns string representation for token. |
|
68 | + * |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function __toString() |
|
72 | + { |
|
73 | + return 'callback()'; |
|
74 | + } |
|
75 | 75 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | */ |
32 | 32 | public function __construct($callback) |
33 | 33 | { |
34 | - if (!is_callable($callback)) { |
|
34 | + if ( ! is_callable($callback)) { |
|
35 | 35 | throw new InvalidArgumentException(sprintf( |
36 | 36 | 'Callable expected as an argument to CallbackToken, but got %s.', |
37 | 37 | gettype($callback) |
@@ -20,55 +20,55 @@ |
||
20 | 20 | */ |
21 | 21 | class IdenticalValueToken implements TokenInterface |
22 | 22 | { |
23 | - private $value; |
|
24 | - private $string; |
|
25 | - private $util; |
|
23 | + private $value; |
|
24 | + private $string; |
|
25 | + private $util; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Initializes token. |
|
29 | - * |
|
30 | - * @param mixed $value |
|
31 | - * @param StringUtil $util |
|
32 | - */ |
|
33 | - public function __construct($value, StringUtil $util = null) |
|
34 | - { |
|
35 | - $this->value = $value; |
|
36 | - $this->util = $util ?: new StringUtil(); |
|
37 | - } |
|
27 | + /** |
|
28 | + * Initializes token. |
|
29 | + * |
|
30 | + * @param mixed $value |
|
31 | + * @param StringUtil $util |
|
32 | + */ |
|
33 | + public function __construct($value, StringUtil $util = null) |
|
34 | + { |
|
35 | + $this->value = $value; |
|
36 | + $this->util = $util ?: new StringUtil(); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Scores 11 if argument matches preset value. |
|
41 | - * |
|
42 | - * @param $argument |
|
43 | - * |
|
44 | - * @return bool|int |
|
45 | - */ |
|
46 | - public function scoreArgument($argument) |
|
47 | - { |
|
48 | - return $argument === $this->value ? 11 : false; |
|
49 | - } |
|
39 | + /** |
|
40 | + * Scores 11 if argument matches preset value. |
|
41 | + * |
|
42 | + * @param $argument |
|
43 | + * |
|
44 | + * @return bool|int |
|
45 | + */ |
|
46 | + public function scoreArgument($argument) |
|
47 | + { |
|
48 | + return $argument === $this->value ? 11 : false; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns false. |
|
53 | - * |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function isLast() |
|
57 | - { |
|
58 | - return false; |
|
59 | - } |
|
51 | + /** |
|
52 | + * Returns false. |
|
53 | + * |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function isLast() |
|
57 | + { |
|
58 | + return false; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Returns string representation for token. |
|
63 | - * |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - public function __toString() |
|
67 | - { |
|
68 | - if (null === $this->string) { |
|
69 | - $this->string = sprintf('identical(%s)', $this->util->stringify($this->value)); |
|
70 | - } |
|
61 | + /** |
|
62 | + * Returns string representation for token. |
|
63 | + * |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + public function __toString() |
|
67 | + { |
|
68 | + if (null === $this->string) { |
|
69 | + $this->string = sprintf('identical(%s)', $this->util->stringify($this->value)); |
|
70 | + } |
|
71 | 71 | |
72 | - return $this->string; |
|
73 | - } |
|
72 | + return $this->string; |
|
73 | + } |
|
74 | 74 | } |
@@ -18,26 +18,26 @@ |
||
18 | 18 | */ |
19 | 19 | interface TokenInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Calculates token match score for provided argument. |
|
23 | - * |
|
24 | - * @param $argument |
|
25 | - * |
|
26 | - * @return bool|int |
|
27 | - */ |
|
28 | - public function scoreArgument($argument); |
|
21 | + /** |
|
22 | + * Calculates token match score for provided argument. |
|
23 | + * |
|
24 | + * @param $argument |
|
25 | + * |
|
26 | + * @return bool|int |
|
27 | + */ |
|
28 | + public function scoreArgument($argument); |
|
29 | 29 | |
30 | - /** |
|
31 | - * Returns true if this token prevents check of other tokens (is last one). |
|
32 | - * |
|
33 | - * @return bool|int |
|
34 | - */ |
|
35 | - public function isLast(); |
|
30 | + /** |
|
31 | + * Returns true if this token prevents check of other tokens (is last one). |
|
32 | + * |
|
33 | + * @return bool|int |
|
34 | + */ |
|
35 | + public function isLast(); |
|
36 | 36 | |
37 | - /** |
|
38 | - * Returns string representation for token. |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function __toString(); |
|
37 | + /** |
|
38 | + * Returns string representation for token. |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function __toString(); |
|
43 | 43 | } |
@@ -18,57 +18,57 @@ |
||
18 | 18 | */ |
19 | 19 | class InArrayToken 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 | } |
@@ -20,57 +20,57 @@ |
||
20 | 20 | */ |
21 | 21 | class TypeToken implements TokenInterface |
22 | 22 | { |
23 | - private $type; |
|
23 | + private $type; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param string $type |
|
27 | - */ |
|
28 | - public function __construct($type) |
|
29 | - { |
|
30 | - $checker = "is_{$type}"; |
|
31 | - if (!function_exists($checker) && !interface_exists($type) && !class_exists($type)) { |
|
32 | - throw new InvalidArgumentException(sprintf( |
|
33 | - 'Type or class name expected as an argument to TypeToken, but got %s.', $type |
|
34 | - )); |
|
35 | - } |
|
25 | + /** |
|
26 | + * @param string $type |
|
27 | + */ |
|
28 | + public function __construct($type) |
|
29 | + { |
|
30 | + $checker = "is_{$type}"; |
|
31 | + if (!function_exists($checker) && !interface_exists($type) && !class_exists($type)) { |
|
32 | + throw new InvalidArgumentException(sprintf( |
|
33 | + 'Type or class name expected as an argument to TypeToken, but got %s.', $type |
|
34 | + )); |
|
35 | + } |
|
36 | 36 | |
37 | - $this->type = $type; |
|
38 | - } |
|
37 | + $this->type = $type; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Scores 5 if argument has the same type this token was constructed with. |
|
42 | - * |
|
43 | - * @param $argument |
|
44 | - * |
|
45 | - * @return bool|int |
|
46 | - */ |
|
47 | - public function scoreArgument($argument) |
|
48 | - { |
|
49 | - $checker = "is_{$this->type}"; |
|
50 | - if (function_exists($checker)) { |
|
51 | - return call_user_func($checker, $argument) ? 5 : false; |
|
52 | - } |
|
40 | + /** |
|
41 | + * Scores 5 if argument has the same type this token was constructed with. |
|
42 | + * |
|
43 | + * @param $argument |
|
44 | + * |
|
45 | + * @return bool|int |
|
46 | + */ |
|
47 | + public function scoreArgument($argument) |
|
48 | + { |
|
49 | + $checker = "is_{$this->type}"; |
|
50 | + if (function_exists($checker)) { |
|
51 | + return call_user_func($checker, $argument) ? 5 : false; |
|
52 | + } |
|
53 | 53 | |
54 | - return $argument instanceof $this->type ? 5 : false; |
|
55 | - } |
|
54 | + return $argument instanceof $this->type ? 5 : false; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns false. |
|
59 | - * |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - public function isLast() |
|
63 | - { |
|
64 | - return false; |
|
65 | - } |
|
57 | + /** |
|
58 | + * Returns false. |
|
59 | + * |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + public function isLast() |
|
63 | + { |
|
64 | + return false; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Returns string representation for token. |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function __toString() |
|
73 | - { |
|
74 | - return sprintf('type(%s)', $this->type); |
|
75 | - } |
|
67 | + /** |
|
68 | + * Returns string representation for token. |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function __toString() |
|
73 | + { |
|
74 | + return sprintf('type(%s)', $this->type); |
|
75 | + } |
|
76 | 76 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | public function __construct($type) |
29 | 29 | { |
30 | 30 | $checker = "is_{$type}"; |
31 | - if (!function_exists($checker) && !interface_exists($type) && !class_exists($type)) { |
|
31 | + if ( ! function_exists($checker) && ! interface_exists($type) && ! class_exists($type)) { |
|
32 | 32 | throw new InvalidArgumentException(sprintf( |
33 | 33 | 'Type or class name expected as an argument to TypeToken, but got %s.', $type |
34 | 34 | )); |
@@ -22,97 +22,97 @@ |
||
22 | 22 | */ |
23 | 23 | class ExactValueToken implements TokenInterface |
24 | 24 | { |
25 | - private $value; |
|
26 | - private $string; |
|
27 | - private $util; |
|
28 | - private $comparatorFactory; |
|
25 | + private $value; |
|
26 | + private $string; |
|
27 | + private $util; |
|
28 | + private $comparatorFactory; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Initializes token. |
|
32 | - * |
|
33 | - * @param mixed $value |
|
34 | - * @param StringUtil $util |
|
35 | - * @param ComparatorFactory $comparatorFactory |
|
36 | - */ |
|
37 | - public function __construct($value, StringUtil $util = null, ComparatorFactory $comparatorFactory = null) |
|
38 | - { |
|
39 | - $this->value = $value; |
|
40 | - $this->util = $util ?: new StringUtil(); |
|
30 | + /** |
|
31 | + * Initializes token. |
|
32 | + * |
|
33 | + * @param mixed $value |
|
34 | + * @param StringUtil $util |
|
35 | + * @param ComparatorFactory $comparatorFactory |
|
36 | + */ |
|
37 | + public function __construct($value, StringUtil $util = null, ComparatorFactory $comparatorFactory = null) |
|
38 | + { |
|
39 | + $this->value = $value; |
|
40 | + $this->util = $util ?: new StringUtil(); |
|
41 | 41 | |
42 | - $this->comparatorFactory = $comparatorFactory ?: ComparatorFactory::getInstance(); |
|
43 | - } |
|
42 | + $this->comparatorFactory = $comparatorFactory ?: ComparatorFactory::getInstance(); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Scores 10 if argument matches preset value. |
|
47 | - * |
|
48 | - * @param $argument |
|
49 | - * |
|
50 | - * @return bool|int |
|
51 | - */ |
|
52 | - public function scoreArgument($argument) |
|
53 | - { |
|
54 | - if (is_object($argument) && is_object($this->value)) { |
|
55 | - $comparator = $this->comparatorFactory->getComparatorFor( |
|
56 | - $argument, $this->value |
|
57 | - ); |
|
45 | + /** |
|
46 | + * Scores 10 if argument matches preset value. |
|
47 | + * |
|
48 | + * @param $argument |
|
49 | + * |
|
50 | + * @return bool|int |
|
51 | + */ |
|
52 | + public function scoreArgument($argument) |
|
53 | + { |
|
54 | + if (is_object($argument) && is_object($this->value)) { |
|
55 | + $comparator = $this->comparatorFactory->getComparatorFor( |
|
56 | + $argument, $this->value |
|
57 | + ); |
|
58 | 58 | |
59 | - try { |
|
60 | - $comparator->assertEquals($argument, $this->value); |
|
61 | - return 10; |
|
62 | - } catch (ComparisonFailure $failure) { |
|
63 | - return false; |
|
59 | + try { |
|
60 | + $comparator->assertEquals($argument, $this->value); |
|
61 | + return 10; |
|
62 | + } catch (ComparisonFailure $failure) { |
|
63 | + return false; |
|
64 | 64 | } |
65 | - } |
|
65 | + } |
|
66 | 66 | |
67 | - // If either one is an object it should be castable to a string |
|
68 | - if (is_object($argument) xor is_object($this->value)) { |
|
69 | - if (is_object($argument) && !method_exists($argument, '__toString')) { |
|
70 | - return false; |
|
71 | - } |
|
67 | + // If either one is an object it should be castable to a string |
|
68 | + if (is_object($argument) xor is_object($this->value)) { |
|
69 | + if (is_object($argument) && !method_exists($argument, '__toString')) { |
|
70 | + return false; |
|
71 | + } |
|
72 | 72 | |
73 | - if (is_object($this->value) && !method_exists($this->value, '__toString')) { |
|
74 | - return false; |
|
75 | - } |
|
76 | - } elseif (is_numeric($argument) && is_numeric($this->value)) { |
|
77 | - // noop |
|
78 | - } elseif (gettype($argument) !== gettype($this->value)) { |
|
79 | - return false; |
|
80 | - } |
|
73 | + if (is_object($this->value) && !method_exists($this->value, '__toString')) { |
|
74 | + return false; |
|
75 | + } |
|
76 | + } elseif (is_numeric($argument) && is_numeric($this->value)) { |
|
77 | + // noop |
|
78 | + } elseif (gettype($argument) !== gettype($this->value)) { |
|
79 | + return false; |
|
80 | + } |
|
81 | 81 | |
82 | - return $argument == $this->value ? 10 : false; |
|
83 | - } |
|
82 | + return $argument == $this->value ? 10 : false; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Returns preset value against which token checks arguments. |
|
87 | - * |
|
88 | - * @return mixed |
|
89 | - */ |
|
90 | - public function getValue() |
|
91 | - { |
|
92 | - return $this->value; |
|
93 | - } |
|
85 | + /** |
|
86 | + * Returns preset value against which token checks arguments. |
|
87 | + * |
|
88 | + * @return mixed |
|
89 | + */ |
|
90 | + public function getValue() |
|
91 | + { |
|
92 | + return $this->value; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Returns false. |
|
97 | - * |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function isLast() |
|
101 | - { |
|
102 | - return false; |
|
103 | - } |
|
95 | + /** |
|
96 | + * Returns false. |
|
97 | + * |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function isLast() |
|
101 | + { |
|
102 | + return false; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Returns string representation for token. |
|
107 | - * |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function __toString() |
|
111 | - { |
|
112 | - if (null === $this->string) { |
|
113 | - $this->string = sprintf('exact(%s)', $this->util->stringify($this->value)); |
|
114 | - } |
|
105 | + /** |
|
106 | + * Returns string representation for token. |
|
107 | + * |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function __toString() |
|
111 | + { |
|
112 | + if (null === $this->string) { |
|
113 | + $this->string = sprintf('exact(%s)', $this->util->stringify($this->value)); |
|
114 | + } |
|
115 | 115 | |
116 | - return $this->string; |
|
117 | - } |
|
116 | + return $this->string; |
|
117 | + } |
|
118 | 118 | } |
@@ -66,11 +66,11 @@ |
||
66 | 66 | |
67 | 67 | // If either one is an object it should be castable to a string |
68 | 68 | if (is_object($argument) xor is_object($this->value)) { |
69 | - if (is_object($argument) && !method_exists($argument, '__toString')) { |
|
69 | + if (is_object($argument) && ! method_exists($argument, '__toString')) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | - if (is_object($this->value) && !method_exists($this->value, '__toString')) { |
|
73 | + if (is_object($this->value) && ! method_exists($this->value, '__toString')) { |
|
74 | 74 | return false; |
75 | 75 | } |
76 | 76 | } elseif (is_numeric($argument) && is_numeric($this->value)) { |