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\Token;
15 * Array elements count token.
17 * @author Boris Mikhaylov <kaguxmail@gmail.com>
20 class ArrayCountToken implements TokenInterface
25 * @param integer $value
27 public function __construct($value)
29 $this->count = $value;
33 * Scores 6 when argument has preset number of elements.
39 public function scoreArgument($argument)
41 return $this->isCountable($argument) && $this->hasProperCount($argument) ? 6 : false;
49 public function isLast()
55 * Returns string representation for token.
59 public function __toString()
61 return sprintf('count(%s)', $this->count);
65 * Returns true if object is either array or instance of \Countable
70 private function isCountable($argument)
72 return (is_array($argument) || $argument instanceof \Countable);
76 * Returns true if $argument has expected number of elements
78 * @param array|\Countable $argument
82 private function hasProperCount($argument)
84 return $this->count === count($argument);