Chris@0: Chris@0: * Marcello Duarte Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Prophecy\Argument\Token; Chris@0: Chris@0: /** Chris@0: * Logical AND token. Chris@0: * Chris@0: * @author Boris Mikhaylov Chris@0: */ Chris@0: class LogicalAndToken implements TokenInterface Chris@0: { Chris@0: private $tokens = array(); Chris@0: Chris@0: /** Chris@0: * @param array $arguments exact values or tokens Chris@0: */ Chris@0: public function __construct(array $arguments) Chris@0: { Chris@0: foreach ($arguments as $argument) { Chris@0: if (!$argument instanceof TokenInterface) { Chris@0: $argument = new ExactValueToken($argument); Chris@0: } Chris@0: $this->tokens[] = $argument; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Scores maximum score from scores returned by tokens for this argument if all of them score. Chris@0: * Chris@0: * @param $argument Chris@0: * Chris@0: * @return bool|int Chris@0: */ Chris@0: public function scoreArgument($argument) Chris@0: { Chris@0: if (0 === count($this->tokens)) { Chris@0: return false; Chris@0: } Chris@0: Chris@0: $maxScore = 0; Chris@0: foreach ($this->tokens as $token) { Chris@0: $score = $token->scoreArgument($argument); Chris@0: if (false === $score) { Chris@0: return false; Chris@0: } Chris@0: $maxScore = max($score, $maxScore); Chris@0: } Chris@0: Chris@0: return $maxScore; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns false. Chris@0: * Chris@0: * @return boolean Chris@0: */ Chris@0: public function isLast() Chris@0: { Chris@0: return false; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns string representation for token. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function __toString() Chris@0: { Chris@0: return sprintf('bool(%s)', implode(' AND ', $this->tokens)); Chris@0: } Chris@0: }