aboutsummaryrefslogtreecommitdiffstats
path: root/Iterator/Sampler.php
diff options
context:
space:
mode:
Diffstat (limited to 'Iterator/Sampler.php')
-rw-r--r--Iterator/Sampler.php110
1 files changed, 45 insertions, 65 deletions
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();
}
}
-
-}