diff options
author | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2015-05-28 12:10:30 +0200 |
---|---|---|
committer | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2015-05-28 12:10:30 +0200 |
commit | 0fce3078006928700d7e65660d49f693dc4293d2 (patch) | |
tree | 03636cd45b0422fc7558ef9d8c380c30e13b9069 /Iterator | |
parent | f7801604c0631304547eee00b68ce3174d40ccdc (diff) | |
download | Praspel-0fce3078006928700d7e65660d49f693dc4293d2.zip Praspel-0fce3078006928700d7e65660d49f693dc4293d2.tar.gz Praspel-0fce3078006928700d7e65660d49f693dc4293d2.tar.bz2 |
Move to PSR-1-2 & drop PHP5.3 & `from`/`import`.
Diffstat (limited to 'Iterator')
-rw-r--r-- | Iterator/Coverage/Coverage.php | 62 | ||||
-rw-r--r-- | Iterator/Coverage/Domain.php | 95 | ||||
-rw-r--r-- | Iterator/Coverage/Structural.php | 255 | ||||
-rw-r--r-- | Iterator/Sampler.php | 110 | ||||
-rw-r--r-- | Iterator/WeakStack.php | 38 |
5 files changed, 221 insertions, 339 deletions
diff --git a/Iterator/Coverage/Coverage.php b/Iterator/Coverage/Coverage.php index d5d521e..21957de 100644 --- a/Iterator/Coverage/Coverage.php +++ b/Iterator/Coverage/Coverage.php @@ -8,7 +8,7 @@ * * New BSD License * - * Copyright © 2007-2015, Ivan Enderlin. All rights reserved. + * Copyright © 2007-2015, Hoa community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -34,41 +34,22 @@ * POSSIBILITY OF SUCH DAMAGE. */ -namespace { +namespace Hoa\Praspel\Iterator\Coverage; -from('Hoa') - -/** - * \Hoa\Praspel\Iterator\Coverage\Structural - */ --> import('Praspel.Iterator.Coverage.Structural') - -/** - * \Hoa\Iterator\Aggregate - */ --> import('Iterator.Aggregate') - -/** - * \Hoa\Iterator\Recursive\Iterator - */ --> import('Iterator.Recursive.Iterator'); - -} - -namespace Hoa\Praspel\Iterator\Coverage { +use Hoa\Core; +use Hoa\Iterator; +use Hoa\Praspel; /** * Class \Hoa\Praspel\Iterator\Coverage. * * Coverage recursive iterator. * - * @author Ivan Enderlin <ivan.enderlin@hoa-project.net> - * @copyright Copyright © 2007-2015 Ivan Enderlin. + * @copyright Copyright © 2007-2015 Hoa community * @license New BSD License */ - -class Coverage implements \Hoa\Iterator\Aggregate { - +class Coverage implements Iterator\Aggregate +{ /** * Criteria: normal (@requires and @ensures). * @@ -93,7 +74,7 @@ class Coverage implements \Hoa\Iterator\Aggregate { /** * Iterator (of the specification to cover). * - * @var \Hoa\Praspel\Iterator\Coverage\Structural object + * @var \Hoa\Praspel\Iterator\Coverage\Structural */ protected $_iterator = null; @@ -102,12 +83,11 @@ class Coverage implements \Hoa\Iterator\Aggregate { /** * Constructor. * - * @access public * @param \Hoa\Praspel\Model\Specification $specification Specification. * @return void */ - public function __construct ( \Hoa\Praspel\Model\Specification $specification ) { - + public function __construct(Praspel\Model\Specification $specification) + { $this->_iterator = new Structural($specification); return; @@ -116,35 +96,27 @@ class Coverage implements \Hoa\Iterator\Aggregate { /** * Set coverage criteria. * - * @access public * @param int $criteria Criteria (please, see self::CRITERIA_* * constants). * @return int */ - public function setCriteria ( $criteria ) { - + public function setCriteria($criteria) + { return $this->_iterator->setCriteria($criteria); } /** * Get iterator. * - * @access public * @return \Hoa\Iterator\Recursive\Iterator */ - public function getIterator ( ) { - - return new \Hoa\Iterator\Recursive\Iterator($this->_iterator); + public function getIterator() + { + return new Iterator\Recursive\Iterator($this->_iterator); } } -} - -namespace { - /** * Flex entity. */ -Hoa\Core\Consistency::flexEntity('Hoa\Praspel\Iterator\Coverage\Coverage'); - -} +Core\Consistency::flexEntity('Hoa\Praspel\Iterator\Coverage\Coverage'); diff --git a/Iterator/Coverage/Domain.php b/Iterator/Coverage/Domain.php index 9e5dfb4..6b233a3 100644 --- a/Iterator/Coverage/Domain.php +++ b/Iterator/Coverage/Domain.php @@ -8,7 +8,7 @@ * * New BSD License * - * Copyright © 2007-2015, Ivan Enderlin. All rights reserved. + * Copyright © 2007-2015, Hoa community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -34,63 +34,52 @@ * POSSIBILITY OF SUCH DAMAGE. */ -namespace { +namespace Hoa\Praspel\Iterator\Coverage; -from('Hoa') - -/** - * \Hoa\Iterator - */ --> import('Iterator.~'); - -} - -namespace Hoa\Praspel\Iterator\Coverage { +use Hoa\Iterator; /** * Class \Hoa\Praspel\Iterator\Coverage\Domain. * * Domain coverage. * - * @author Ivan Enderlin <ivan.enderlin@hoa-project.net> - * @copyright Copyright © 2007-2015 Ivan Enderlin. + * @copyright Copyright © 2007-2015 Hoa community * @license New BSD License */ - -class Domain implements \Hoa\Iterator { - +class Domain implements Iterator +{ /** * Variables to cover. * - * @var \Hoa\Praspel\Iterator\Coverage\Domain array + * @var array */ - protected $_variables = array(); + protected $_variables = []; /** * Number of variables. * - * @var \Hoa\Praspel\Iterator\Coverage\Domain int + * @var int */ protected $_max = 0; /** * Key. * - * @var \Hoa\Praspel\Iterator\Coverage\Domain int + * @var int */ protected $_key = 0; /** * Current (contains all current domains). * - * @var \Hoa\Praspel\Iterator\Coverage\Domain array + * @var array */ protected $_current = null; /** * Whether the iterator has reached the end or not. * - * @var \Hoa\Praspel\Iterator\Coverage\Domain bool + * @var bool */ protected $_break = true; @@ -99,14 +88,14 @@ class Domain implements \Hoa\Iterator { /** * Constructor. * - * @access public * @param mixed $variables Variables. * @return void */ - public function __construct ( $variables ) { - - foreach($variables as $variable) + public function __construct($variables) + { + foreach ($variables as $variable) { $this->_variables[] = $variable->getDomains()->getIterator(); + } $this->_max = count($this->_variables) - 1; $this->_break = empty($this->_variables); @@ -117,27 +106,24 @@ class Domain implements \Hoa\Iterator { /** * Get the current value. * - * @access public * @return array */ - public function current ( ) { - + public function current() + { return $this->_current; } /** * Prepare the current value. * - * @access protected * @return void */ - protected function _current ( ) { - - $this->_current = array(); + protected function _current() + { + $this->_current = []; - foreach($this->_variables as $variable) { - - $current = $variable->current(); + foreach ($this->_variables as $variable) { + $current = $variable->current(); $this->_current[$current->getHolder()->getName()] = $current; } @@ -147,34 +133,32 @@ class Domain implements \Hoa\Iterator { /** * Get the current key. * - * @access public * @return int */ - public function key ( ) { - + public function key() + { return $this->_key; } /** * Advance the internal collection pointer, and return the current value. * - * @access public * @return array */ - public function next ( ) { - - for($i = 0; $i <= $this->_max; ++$i) { - + public function next() + { + for ($i = 0; $i <= $this->_max; ++$i) { $this->_variables[$i]->next(); - if(false !== $this->_variables[$i]->valid()) + if (false !== $this->_variables[$i]->valid()) { break; + } $this->_variables[$i]->rewind(); - if($i === $this->_max) { - + if ($i === $this->_max) { $this->_break = true; + break; } } @@ -188,16 +172,16 @@ class Domain implements \Hoa\Iterator { /** * Rewind the internal collection pointer, and return the first collection. * - * @access public * @return array */ - public function rewind ( ) { - + public function rewind() + { $this->_break = empty($this->_variables); $this->_key = 0; - foreach($this->_variables as $variable) + foreach ($this->_variables as $variable) { $variable->rewind(); + } $this->_current(); @@ -208,13 +192,10 @@ class Domain implements \Hoa\Iterator { * Check if there is a current element after calls to the rewind() or the * next() methods. * - * @access public * @return bool */ - public function valid ( ) { - + public function valid() + { return false === $this->_break; } } - -} diff --git a/Iterator/Coverage/Structural.php b/Iterator/Coverage/Structural.php index e299407..3ce04e5 100644 --- a/Iterator/Coverage/Structural.php +++ b/Iterator/Coverage/Structural.php @@ -8,7 +8,7 @@ * * New BSD License * - * Copyright © 2007-2015, Ivan Enderlin. All rights reserved. + * Copyright © 2007-2015, Hoa community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -34,61 +34,21 @@ * POSSIBILITY OF SUCH DAMAGE. */ -namespace { +namespace Hoa\Praspel\Iterator\Coverage; -from('Hoa') - -/** - * \Hoa\Praspel\Exception\Generic - */ --> import('Praspel.Exception.Generic') - -/** - * \Hoa\Praspel\Iterator\WeakStack - */ --> import('Praspel.Iterator.WeakStack') - -/** - * \Hoa\Praspel\Iterator\Coverage - */ --> import('Praspel.Iterator.Coverage.~') - -/** - * \Hoa\Praspel\Iterator\Coverage\Domain - */ --> import('Praspel.Iterator.Coverage.Domain') - -/** - * \Hoa\Iterator\Recursive - */ --> import('Iterator.Recursive.~') - -/** - * \Hoa\Iterator\Demultiplexer - */ --> import('Iterator.Demultiplexer') - -/** - * \Hoa\Iterator\Recursive\Mock - */ --> import('Iterator.Recursive.Mock'); - -} - -namespace Hoa\Praspel\Iterator\Coverage { +use Hoa\Iterator; +use Hoa\Praspel; /** * Class \Hoa\Praspel\Iterator\Coverage\Structural. * * Structural coverage. * - * @author Ivan Enderlin <ivan.enderlin@hoa-project.net> - * @copyright Copyright © 2007-2015 Ivan Enderlin. + * @copyright Copyright © 2007-2015 Hoa community * @license New BSD License */ - -class Structural implements \Hoa\Iterator\Recursive { - +class Structural implements Iterator\Recursive +{ /** * State of the iterator: will compute a @requires clause. * @@ -120,14 +80,14 @@ class Structural implements \Hoa\Iterator\Recursive { /** * Specification to cover. * - * @var \Hoa\Praspel\Model\Specification object + * @var \Hoa\Praspel\Model\Specification */ protected $_specification = null; /** * Coverage criteria. * - * @var \Hoa\Praspel\Iterator\Coverage\Structural int + * @var int */ protected $_criteria = 3; // Coverage::CRITERIA_NORMAL // | Coverage::CRITERIA_EXCEPTIONAL @@ -135,14 +95,14 @@ class Structural implements \Hoa\Iterator\Recursive { /** * Path. * - * @var \SplQueue object + * @var \SplQueue */ protected $_path = null; /** * Stack (to manage backtracks, yields, etc.) * - * @var \SplStack object + * @var \SplStack */ protected $_stack = null; @@ -156,7 +116,7 @@ class Structural implements \Hoa\Iterator\Recursive { /** * Key. * - * @var \Hoa\Praspel\Iterator\Coverage\Structural int + * @var int */ protected $_key = -1; @@ -164,7 +124,7 @@ class Structural implements \Hoa\Iterator\Recursive { * Current (with two indexes: pre and post, with SplStack * associated). * - * @var \Hoa\Praspel\Iterator\Coverage\Structural array + * @var array */ protected $_current = null; @@ -173,12 +133,11 @@ class Structural implements \Hoa\Iterator\Recursive { /** * Constructor. * - * @access public * @param \Hoa\Praspel\Model\Specification $specification Specification. * @return void */ - public function __construct ( \Hoa\Praspel\Model\Specification $specification ) { - + public function __construct(Praspel\Model\Specification $specification) + { $this->_specification = $specification; $this->setCriteria( Coverage::CRITERIA_NORMAL | Coverage::CRITERIA_EXCEPTIONAL @@ -190,18 +149,19 @@ class Structural implements \Hoa\Iterator\Recursive { /** * Get the current value. * - * @access public * @return array */ - public function current ( ) { + public function current() + { + $out = ['pre' => [], 'post' => []]; - $out = array('pre' => array(), 'post' => array()); - - foreach($this->_path as $element) - if($element instanceof \Hoa\Praspel\Model\Requires) + foreach ($this->_path as $element) { + if ($element instanceof Praspel\Model\Requires) { $out['pre'][] = $element; - else + } else { $out['post'][] = $element; + } + } return $out; } @@ -209,29 +169,27 @@ class Structural implements \Hoa\Iterator\Recursive { /** * Get the current key. * - * @access public * @return int */ - public function key ( ) { - + public function key() + { return $this->_key; } /** * Advance the internal collection pointer, and return the current value. * - * @access public * @return void */ - public function next ( ) { - + public function next() + { $this->_current = null; - if(0 === count($this->_stack)) + if (0 === count($this->_stack)) { return; + } - while(0 === $this->_pop->top()) { - + while (0 === $this->_pop->top()) { $this->_pop->pop(); $this->_path->pop(); $this->_pop->push($this->_pop->pop() - 1); @@ -239,61 +197,54 @@ class Structural implements \Hoa\Iterator\Recursive { list($behavior, $state) = array_values($this->_stack->pop()); - switch($state) { - + switch ($state) { case static::STATE_REQUIRES: ++$this->_key; - if(true === $behavior->clauseExists('requires')) { - + if (true === $behavior->clauseExists('requires')) { $this->_current = $behavior->getClause('requires'); $this->_path->push($this->_current); - } - else { - + } else { $this->_current = true; $this->_path->push(null); } - if(true === $behavior->clauseExists('behavior')) { - + if (true === $behavior->clauseExists('behavior')) { $behaviors = $behavior->getClause('behavior')->getIterator(); - $this->_stack->push(array( + $this->_stack->push([ 'behavior' => $behavior, 'state' => static::STATE_BEHAVIOR - )); - $this->_stack->push(array( + ]); + $this->_stack->push([ 'behavior' => $behaviors, 'state' => static::STATE_BEHAVIOR - )); + ]); $this->_pop->push( count($behaviors) + (2 * $behavior->clauseExists('default')) ); - } - else { - - $this->_stack->push(array( + } else { + $this->_stack->push([ 'behavior' => $behavior, 'state' => static::STATE_ENSURES - )); + ]); $this->_pop->push(2); $this->next(); } - break; - case static::STATE_BEHAVIOR: - if(true === $behavior->valid()) { + break; - $this->_stack->push(array( + case static::STATE_BEHAVIOR: + if (true === $behavior->valid()) { + $this->_stack->push([ 'behavior' => $behavior, 'state' => static::STATE_BEHAVIOR - )); - $this->_stack->push(array( + ]); + $this->_stack->push([ 'behavior' => $behavior->current(), 'state' => static::STATE_REQUIRES - )); + ]); $behavior->next(); $this->next(); @@ -302,24 +253,25 @@ class Structural implements \Hoa\Iterator\Recursive { list($parentBehavior, ) = array_values($this->_stack->pop()); - if(true === $parentBehavior->clauseExists('default')) - $this->_stack->push(array( + if (true === $parentBehavior->clauseExists('default')) { + $this->_stack->push([ 'behavior' => $parentBehavior->getClause('default'), 'state' => static::STATE_ENSURES - )); + ]); + } $this->next(); - break; + + break; case static::STATE_ENSURES: - $this->_stack->push(array( + $this->_stack->push([ 'behavior' => $behavior, 'state' => static::STATE_THROWABLE - )); - - if( false === $behavior->clauseExists('ensures') - || 0 === (Coverage::CRITERIA_NORMAL & $this->getCriteria())) { + ]); + if (false === $behavior->clauseExists('ensures') || + 0 === (Coverage::CRITERIA_NORMAL & $this->getCriteria())) { $this->_pop->push($this->_pop->pop() - 1); $this->next(); @@ -330,12 +282,12 @@ class Structural implements \Hoa\Iterator\Recursive { $this->_current = $behavior->getClause('ensures'); $this->_path->push($this->_current); $this->_pop->push(0); - break; - case static::STATE_THROWABLE: - if( false === $behavior->clauseExists('throwable') - || 0 === (Coverage::CRITERIA_EXCEPTIONAL & $this->getCriteria())) { + break; + case static::STATE_THROWABLE: + if (false === $behavior->clauseExists('throwable') || + 0 === (Coverage::CRITERIA_EXCEPTIONAL & $this->getCriteria())) { $this->_pop->push($this->_pop->pop() - 1); $this->next(); @@ -347,7 +299,8 @@ class Structural implements \Hoa\Iterator\Recursive { $this->_path->push($this->_current); $this->_pop->push(0); - break; + + break; } return; @@ -356,22 +309,21 @@ class Structural implements \Hoa\Iterator\Recursive { /** * Rewind the internal collection pointer, and return the first collection. * - * @access public * @return array */ - public function rewind ( ) { - + public function rewind() + { $this->_key = -1; unset($this->_path); - $this->_path = new \Hoa\Praspel\Iterator\WeakStack(); + $this->_path = new Praspel\Iterator\WeakStack(); unset($this->_stack); $this->_stack = new \SplStack(); - $this->_stack->push(array( + $this->_stack->push([ 'behavior' => $this->_specification, 'state' => static::STATE_REQUIRES - )); + ]); unset($this->_pop); $this->_pop = new \SplQueue(); @@ -386,29 +338,30 @@ class Structural implements \Hoa\Iterator\Recursive { * Check if there is a current element after calls to the rewind() or the * next() methods. * - * @access public * @return bool */ - public function valid ( ) { - + public function valid() + { return null !== $this->_current; } /** * Set coverage criteria. * - * @access public * @param int $criteria Criteria (please, see Coverage::CRITERIA_* * constants). * @return int */ - public function setCriteria ( $criteria ) { - - if( 0 !== (Coverage::CRITERIA_DOMAIN & $criteria) - && 0 !== (Coverage::CRITERIA_EXCEPTIONAL & $criteria)) - throw new \Hoa\Praspel\Exception\Generic( + public function setCriteria($criteria) + { + if (0 !== (Coverage::CRITERIA_DOMAIN & $criteria) && + 0 !== (Coverage::CRITERIA_EXCEPTIONAL & $criteria)) { + throw new Praspel\Exception\Generic( 'Mixing CRITERIA_EXCEPTIONAL and CRITERIA_DOMAIN is not ' . - 'supported yet. Sorry.', 0); + 'supported yet. Sorry.', + 0 + ); + } $old = $this->_criteria; $this->_criteria = $criteria; @@ -419,22 +372,20 @@ class Structural implements \Hoa\Iterator\Recursive { /** * get coverage criteria. * - * @access public * @return int */ - public function getCriteria ( ) { - + public function getCriteria() + { return $this->_criteria; } /** * Check if we can go deeper (structural to domain coverage). * - * @access public * @return bool */ - public function hasChildren ( ) { - + public function hasChildren() + { return 0 !== (Coverage::CRITERIA_DOMAIN & $this->getCriteria()); } @@ -442,37 +393,39 @@ class Structural implements \Hoa\Iterator\Recursive { * Get the domain coverage iterator from the current variables from pre and * post clauses. * - * @access public * @return \Hoa\Iterator\Recursive */ - public function getChildren ( ) { - - $variables = array(); + public function getChildren() + { + $variables = []; $current = $this->current(); - foreach($current['pre'] as $clause) - foreach($clause->getLocalVariables() as $variable) + foreach ($current['pre'] as $clause) { + foreach ($clause->getLocalVariables() as $variable) { $variables[] = $variable; + } + } - foreach($current['post'] as $clause) - foreach($clause->getLocalVariables() as $variable) + foreach ($current['post'] as $clause) { + foreach ($clause->getLocalVariables() as $variable) { $variables[] = $variable; + } + } - return new \Hoa\Iterator\Recursive\Mock( - new \Hoa\Iterator\Demultiplexer( + return new Iterator\Recursive\Mock( + new Iterator\Demultiplexer( new Domain($variables), - function ( $current ) { - - $out = array('pre' => array(), 'post' => array()); - - foreach($current as $name => $variable) { + function ($current) { + $out = ['pre' => [], 'post' => []]; + foreach ($current as $name => $variable) { $clause = $variable->getHolder()->getClause(); - if($clause instanceof \Hoa\Praspel\Model\Requires) + if ($clause instanceof Praspel\Model\Requires) { $out['pre'][$name] = $variable; - else + } else { $out['post'][$name] = $variable; + } } return $out; @@ -481,5 +434,3 @@ class Structural implements \Hoa\Iterator\Recursive { ); } } - -} diff --git a/Iterator/Sampler.php b/Iterator/Sampler.php index e0d6507..d227481 100644 --- a/Iterator/Sampler.php +++ b/Iterator/Sampler.php @@ -8,7 +8,7 @@ * * New BSD License * - * Copyright © 2007-2015, Ivan Enderlin. All rights reserved. + * Copyright © 2007-2015, Hoa community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -34,36 +34,21 @@ * POSSIBILITY OF SUCH DAMAGE. */ -namespace { +namespace Hoa\Praspel\Iterator; -from('Hoa') - -/** - * \Hoa\Iterator - */ --> import('Iterator.~') - -/** - * \Hoa\Praspel\Iterator\Coverage\Domain - */ --> import('Praspel.Iterator.Coverage.Domain'); - -} - -namespace Hoa\Praspel\Iterator { +use Hoa\Iterator; +use Hoa\Praspel; /** * Class \Hoa\Praspel\Iterator\Sampler. * * An easy way to iterate over data described by Praspel. * - * @author Ivan Enderlin <ivan.enderlin@hoa-project.net> - * @copyright Copyright © 2007-2015 Ivan Enderlin. + * @copyright Copyright © 2007-2015 Hoa community * @license New BSD License */ - -class Sampler implements \Hoa\Iterator { - +class Sampler implements Iterator +{ /** * Key value is variable name. * @@ -81,42 +66,42 @@ class Sampler implements \Hoa\Iterator { /** * Declaration. * - * @var \Hoa\Praspel\Model\Declaration object + * @var \Hoa\Praspel\Model\Declaration */ protected $_declaration = null; /** * Key type (please, see self::KEY_AS_* constants). * - * @var \Hoa\Praspel\Iterator\Sampler int + * @var int */ protected $_keyType = null; /** * Variables to consider. * - * @var \Hoa\Praspel\Iterator\Sampler array + * @var array */ - protected $_variables = array(); + protected $_variables = []; /** * Current key. * - * @var \Hoa\Praspel\Iterator\Sampler int + * @var int */ protected $_key = -1; /** * Current value. * - * @var \Hoa\Praspel\Iterator\Sampler array + * @var array */ protected $_current = null; /** * Coverage iterator. * - * @var \Hoa\Praspel\Iterator\Coverage\Domain object + * @var \Hoa\Praspel\Iterator\Coverage\Domain */ protected $_coverage = null; @@ -125,7 +110,6 @@ class Sampler implements \Hoa\Iterator { /** * Construct. * - * @access public * @param \Hoa\Praspel\Model\Declaration $declaration Declaration. * @param int $keyType Key type (plese, * see @@ -133,9 +117,10 @@ class Sampler implements \Hoa\Iterator { * constants). * @return void */ - public function __construct ( \Hoa\Praspel\Model\Declaration $declaration, - $keyType = self::KEY_AS_VARIABLE_NAME ) { - + public function __construct( + Praspel\Model\Declaration $declaration, + $keyType = self::KEY_AS_VARIABLE_NAME + ) { $this->_declaration = $declaration; $this->_keyType = $keyType; @@ -147,15 +132,15 @@ class Sampler implements \Hoa\Iterator { * Example: * $this->extract('x', 'y', 'z') * - * @access public * @param string $variable Variable name. * @param ... ... ... * @return \Hoa\Praspel\Iterator\Sampler */ - public function extract ( ) { - - foreach(func_get_args() as $variable) + public function extract() + { + foreach (func_get_args() as $variable) { $this->_variables[] = $this->_declaration[$variable]; + } return $this; } @@ -163,33 +148,30 @@ class Sampler implements \Hoa\Iterator { /** * Get current value. * - * @access public * @return array */ - public function current ( ) { - + public function current() + { return $this->_current; } /** * Get current key. * - * @access public * @return int */ - public function key ( ) { - + public function key() + { return $this->_key; } /** * Compute the next value and return it. * - * @access public * @return array */ - public function next ( ) { - + public function next() + { $this->_coverage->next(); $this->_current(); @@ -199,20 +181,22 @@ class Sampler implements \Hoa\Iterator { /** * Prepare the current value. * - * @access protected * @return void */ - protected function _current ( ) { - + protected function _current() + { $current = $this->_coverage->current(); - $handle = array(); + $handle = []; - if(self::KEY_AS_VARIABLE_NAME === $this->_keyType) - foreach($current as $name => $domain) + if (self::KEY_AS_VARIABLE_NAME === $this->_keyType) { + foreach ($current as $name => $domain) { $handle[$name] = $domain->sample(); - else - foreach($current as $domain) + } + } else { + foreach ($current as $domain) { $handle[] = $domain->sample(); + } + } ++$this->_key; $this->_current = $handle; @@ -223,18 +207,17 @@ class Sampler implements \Hoa\Iterator { /** * Rewind the iterator. * - * @access public * @return void */ - public function rewind ( ) { - + public function rewind() + { $this->_key = -1; $this->_current = null; - if(null === $this->_coverage) { - - if(empty($this->_variables)) + if (null === $this->_coverage) { + if (empty($this->_variables)) { $this->_variables = $this->_declaration->getLocalVariables(); + } $this->_coverage = new Coverage\Domain($this->_variables); } @@ -248,13 +231,10 @@ class Sampler implements \Hoa\Iterator { /** * Check if there is enough data to continue. * - * @access public * @return bool */ - public function valid ( ) { - + public function valid() + { return $this->_coverage->valid(); } } - -} diff --git a/Iterator/WeakStack.php b/Iterator/WeakStack.php index b4e5746..83ba98e 100644 --- a/Iterator/WeakStack.php +++ b/Iterator/WeakStack.php @@ -8,7 +8,7 @@ * * New BSD License * - * Copyright © 2007-2015, Ivan Enderlin. All rights reserved. + * Copyright © 2007-2015, Hoa community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -34,31 +34,30 @@ * POSSIBILITY OF SUCH DAMAGE. */ -namespace Hoa\Praspel\Iterator { +namespace Hoa\Praspel\Iterator; /** * Class \Hoa\Praspel\Iterator\WeakStack. * * A weak stack is a SplStack with null elements that are not iterated. * - * @author Ivan Enderlin <ivan.enderlin@hoa-project.net> - * @copyright Copyright © 2007-2015 Ivan Enderlin. + * @copyright Copyright © 2007-2015 Hoa community * @license New BSD License */ - -class WeakStack extends \SplStack { - +class WeakStack extends \SplStack +{ /** * Skip null elements while validated the current one. * - * @access public * @return bool */ - public function valid ( ) { - - while( true === parent::valid() - && null === $this->current() - && null === parent::next()); + public function valid() + { + while ( + true === parent::valid() && + null === $this->current() && + null === parent::next() + ); return parent::valid(); } @@ -67,17 +66,16 @@ class WeakStack extends \SplStack { * Check whether the stack is empty or not. * An element is present if different of null. * - * @access public * @return bool */ - public function isEmpty ( ) { - - foreach($this as $element) - if(null !== $element) + public function isEmpty() + { + foreach ($this as $element) { + if (null !== $element) { return false; + } + } return true; } } - -} |