/hamcrest-php/hamcrest/Hamcrest/Collection/IsTraversableWithSize.php
PHP | 43 lines | 25 code | 7 blank | 11 comment | 0 complexity | 4c8e8b242462e39c7d63c71dab1842da MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
1<?php 2 3/* 4 Copyright (c) 2009 hamcrest.org 5 */ 6 7require_once 'Hamcrest/FeatureMatcher.php'; 8require_once 'Hamcrest/Matcher.php'; 9require_once 'Hamcrest/Util.php'; 10 11/** 12 * Matches if traversable size satisfies a nested matcher. 13 */ 14class Hamcrest_Collection_IsTraversableWithSize extends Hamcrest_FeatureMatcher 15{ 16 17 public function __construct(Hamcrest_Matcher $sizeMatcher) 18 { 19 parent::__construct(self::TYPE_OBJECT, 'Traversable', $sizeMatcher, 20 'a traversable with size', 'traversable size'); 21 } 22 23 protected function featureValueOf($actual) 24 { 25 $size = 0; 26 foreach ($actual as $value) 27 { 28 $size++; 29 } 30 return $size; 31 } 32 33 /** 34 * Does traversable size satisfy a given matcher? 35 * 36 * @factory 37 */ 38 public static function traversableWithSize($size) 39 { 40 return new self(Hamcrest_Util::wrapValueWithIsEqual($size)); 41 } 42 43}