4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 * Marcello Duarte <marcello.duarte@gmail.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Prophecy\Argument;
15 * Arguments wildcarding.
17 * @author Konstantin Kudryashov <ever.zet@gmail.com>
19 class ArgumentsWildcard
22 * @var Token\TokenInterface[]
24 private $tokens = array();
28 * Initializes wildcard.
30 * @param array $arguments Array of argument tokens or values
32 public function __construct(array $arguments)
34 foreach ($arguments as $argument) {
35 if (!$argument instanceof Token\TokenInterface) {
36 $argument = new Token\ExactValueToken($argument);
39 $this->tokens[] = $argument;
44 * Calculates wildcard match score for provided arguments.
46 * @param array $arguments
48 * @return false|int False OR integer score (higher - better)
50 public function scoreArguments(array $arguments)
52 if (0 == count($arguments) && 0 == count($this->tokens)) {
56 $arguments = array_values($arguments);
58 foreach ($this->tokens as $i => $token) {
59 $argument = isset($arguments[$i]) ? $arguments[$i] : null;
60 if (1 >= $score = $token->scoreArgument($argument)) {
64 $totalScore += $score;
66 if (true === $token->isLast()) {
71 if (count($arguments) > count($this->tokens)) {
79 * Returns string representation for wildcard.
83 public function __toString()
85 if (null === $this->string) {
86 $this->string = implode(', ', array_map(function ($token) {
87 return (string) $token;
97 public function getTokens()