Mercurial > hg > isophonics-drupal-site
annotate vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayCountToken.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 /* |
Chris@0 | 4 * This file is part of the Prophecy. |
Chris@0 | 5 * (c) Konstantin Kudryashov <ever.zet@gmail.com> |
Chris@0 | 6 * Marcello Duarte <marcello.duarte@gmail.com> |
Chris@0 | 7 * |
Chris@0 | 8 * For the full copyright and license information, please view the LICENSE |
Chris@0 | 9 * file that was distributed with this source code. |
Chris@0 | 10 */ |
Chris@0 | 11 |
Chris@0 | 12 namespace Prophecy\Argument\Token; |
Chris@0 | 13 |
Chris@0 | 14 /** |
Chris@0 | 15 * Array elements count token. |
Chris@0 | 16 * |
Chris@0 | 17 * @author Boris Mikhaylov <kaguxmail@gmail.com> |
Chris@0 | 18 */ |
Chris@0 | 19 |
Chris@0 | 20 class ArrayCountToken implements TokenInterface |
Chris@0 | 21 { |
Chris@0 | 22 private $count; |
Chris@0 | 23 |
Chris@0 | 24 /** |
Chris@0 | 25 * @param integer $value |
Chris@0 | 26 */ |
Chris@0 | 27 public function __construct($value) |
Chris@0 | 28 { |
Chris@0 | 29 $this->count = $value; |
Chris@0 | 30 } |
Chris@0 | 31 |
Chris@0 | 32 /** |
Chris@0 | 33 * Scores 6 when argument has preset number of elements. |
Chris@0 | 34 * |
Chris@0 | 35 * @param $argument |
Chris@0 | 36 * |
Chris@0 | 37 * @return bool|int |
Chris@0 | 38 */ |
Chris@0 | 39 public function scoreArgument($argument) |
Chris@0 | 40 { |
Chris@0 | 41 return $this->isCountable($argument) && $this->hasProperCount($argument) ? 6 : false; |
Chris@0 | 42 } |
Chris@0 | 43 |
Chris@0 | 44 /** |
Chris@0 | 45 * Returns false. |
Chris@0 | 46 * |
Chris@0 | 47 * @return boolean |
Chris@0 | 48 */ |
Chris@0 | 49 public function isLast() |
Chris@0 | 50 { |
Chris@0 | 51 return false; |
Chris@0 | 52 } |
Chris@0 | 53 |
Chris@0 | 54 /** |
Chris@0 | 55 * Returns string representation for token. |
Chris@0 | 56 * |
Chris@0 | 57 * @return string |
Chris@0 | 58 */ |
Chris@0 | 59 public function __toString() |
Chris@0 | 60 { |
Chris@0 | 61 return sprintf('count(%s)', $this->count); |
Chris@0 | 62 } |
Chris@0 | 63 |
Chris@0 | 64 /** |
Chris@0 | 65 * Returns true if object is either array or instance of \Countable |
Chris@0 | 66 * |
Chris@0 | 67 * @param $argument |
Chris@0 | 68 * @return bool |
Chris@0 | 69 */ |
Chris@0 | 70 private function isCountable($argument) |
Chris@0 | 71 { |
Chris@0 | 72 return (is_array($argument) || $argument instanceof \Countable); |
Chris@0 | 73 } |
Chris@0 | 74 |
Chris@0 | 75 /** |
Chris@0 | 76 * Returns true if $argument has expected number of elements |
Chris@0 | 77 * |
Chris@0 | 78 * @param array|\Countable $argument |
Chris@0 | 79 * |
Chris@0 | 80 * @return bool |
Chris@0 | 81 */ |
Chris@0 | 82 private function hasProperCount($argument) |
Chris@0 | 83 { |
Chris@0 | 84 return $this->count === count($argument); |
Chris@0 | 85 } |
Chris@0 | 86 } |