aboutsummaryrefslogtreecommitdiffstats
path: root/Model
diff options
context:
space:
mode:
Diffstat (limited to 'Model')
-rw-r--r--Model/Behavior.php225
-rw-r--r--Model/Clause.php79
-rw-r--r--Model/Collection.php142
-rw-r--r--Model/Declaration.php179
-rw-r--r--Model/DefaultBehavior.php36
-rw-r--r--Model/Description.php83
-rw-r--r--Model/Ensures.php25
-rw-r--r--Model/Invariant.php25
-rw-r--r--Model/Is.php70
-rw-r--r--Model/Requires.php25
-rw-r--r--Model/Specification.php68
-rw-r--r--Model/Throwable.php154
-rw-r--r--Model/Variable/Borrowing.php221
-rw-r--r--Model/Variable/Implicit.php63
-rw-r--r--Model/Variable/Variable.php257
15 files changed, 648 insertions, 1004 deletions
diff --git a/Model/Behavior.php b/Model/Behavior.php
index d962846..f21ca0b 100644
--- a/Model/Behavior.php
+++ b/Model/Behavior.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,76 +34,20 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Model;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Model
- */
--> import('Praspel.Exception.Model')
-
-/**
- * \Hoa\Praspel\Model\Clause
- */
--> import('Praspel.Model.Clause')
-
-/**
- * \Hoa\Praspel\Model\Is
- */
--> import('Praspel.Model.Is')
-
-/**
- * \Hoa\Praspel\Model\Requires
- */
--> import('Praspel.Model.Requires')
-
-/**
- * \Hoa\Praspel\Model\Ensures
- */
--> import('Praspel.Model.Ensures')
-
-/**
- * \Hoa\Praspel\Model\Requires
- */
--> import('Praspel.Model.Throwable')
-
-/**
- * \Hoa\Praspel\Model\Invariant
- */
--> import('Praspel.Model.Invariant')
-
-/**
- * \Hoa\Praspel\Model\DefaultBehavior
- */
--> import('Praspel.Model.DefaultBehavior')
-
-/**
- * \Hoa\Praspel\Model\Collection
- */
--> import('Praspel.Model.Collection')
-
-/**
- * \Hoa\Praspel\Model\Description
- */
--> import('Praspel.Model.Description');
-
-}
-
-namespace Hoa\Praspel\Model {
+use Hoa\Praspel;
/**
* Class \Hoa\Praspel\Model\Behavior.
*
* Represent the @behavior clause.
*
- * @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 Behavior extends Clause {
-
+class Behavior extends Clause
+{
/**
* Name.
*
@@ -114,28 +58,28 @@ class Behavior extends Clause {
/**
* Allowed clauses.
*
- * @var \Hoa\Praspel\Model\Behavior array
+ * @var array
*/
- protected static $_allowedClauses = array(
+ protected static $_allowedClauses = [
'requires',
'behavior',
'default',
'ensures',
'throwable',
'description'
- );
+ ];
/**
* Clauses.
*
- * @var \Hoa\Praspel\Model\Behavior array
+ * @var array
*/
- protected $_clauses = array();
+ protected $_clauses = [];
/**
* Identifier (@behavior <identifier> { … }).
*
- * @var \Hoa\Praspel\Model\Behavior string
+ * @var string
*/
protected $_identifier = null;
@@ -144,96 +88,122 @@ class Behavior extends Clause {
/**
* Get or create a specific clause.
*
- * @access public
* @param string $clause Clause (without leading arobase).
* @return \Hoa\Praspel\Model\Clause
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- public function getClause ( $clause ) {
-
- if(isset($this->_clauses[$clause]))
+ public function getClause($clause)
+ {
+ if (isset($this->_clauses[$clause])) {
return $this->_clauses[$clause];
+ }
$handle = null;
- if(false === in_array($clause, static::getAllowedClauses()))
- throw new \Hoa\Praspel\Exception\Model(
+ if (false === in_array($clause, static::getAllowedClauses())) {
+ throw new Praspel\Exception\Model(
'Clause @%s is not allowed in @%s.',
- 0, array($clause, $this->getId()));
-
- switch($clause) {
+ 0,
+ [$clause, $this->getId()]
+ );
+ }
+ switch ($clause) {
case 'is':
$handle = new Is($this);
- break;
+
+ break;
case 'requires':
$handle = new Requires($this);
- break;
+
+ break;
case 'ensures':
- if(true === $this->clauseExists('behavior'))
- throw new \Hoa\Praspel\Exception\Model(
+ if (true === $this->clauseExists('behavior')) {
+ throw new Praspel\Exception\Model(
'Cannot add the @ensures clause, since a @behavior ' .
- 'clause exists at the same level.', 1);
+ 'clause exists at the same level.',
+ 1
+ );
+ }
$handle = new Ensures($this);
- break;
+
+ break;
case 'throwable':
- if(true === $this->clauseExists('behavior'))
- throw new \Hoa\Praspel\Exception\Model(
+ if (true === $this->clauseExists('behavior')) {
+ throw new Praspel\Exception\Model(
'Cannot add the @throwable clause, since a @behavior ' .
- 'clause exists at the same level.', 2);
+ 'clause exists at the same level.',
+ 2
+ );
+ }
$handle = new Throwable($this);
- break;
+
+ break;
case 'invariant':
$handle = new Invariant($this);
- break;
+
+ break;
case 'behavior':
- if( true === $this->clauseExists('ensures')
- || true === $this->clauseExists('throwable'))
- throw new \Hoa\Praspel\Exception\Model(
+ if (true === $this->clauseExists('ensures') ||
+ true === $this->clauseExists('throwable')) {
+ throw new Praspel\Exception\Model(
'Cannot add the @behavior clause, since an @ensures ' .
- 'or a @throwable clause exists at the same level.', 3);
+ 'or a @throwable clause exists at the same level.',
+ 3
+ );
+ }
$handle = new Collection(
new self($this),
- function ( Behavior $clause, $identifier ) {
-
+ function (Behavior $clause, $identifier) {
$clause->setIdentifier($identifier);
return;
}
);
- break;
+
+ break;
case 'default':
- if( true === $this->clauseExists('ensures')
- || true === $this->clauseExists('throwable'))
- throw new \Hoa\Praspel\Exception\Model(
+ if (true === $this->clauseExists('ensures') ||
+ true === $this->clauseExists('throwable')) {
+ throw new Praspel\Exception\Model(
'Cannot add the @default clause, since an @ensures ' .
- 'or a @throwable clause exists at the same level.', 4);
+ 'or a @throwable clause exists at the same level.',
+ 4
+ );
+ }
- if(false === $this->clauseExists('behavior'))
- throw new \Hoa\Praspel\Exception\Model(
+ if (false === $this->clauseExists('behavior')) {
+ throw new Praspel\Exception\Model(
'Cannot add a @default clause if at least one ' .
- '@behavior clause has not been declared.', 5);
+ '@behavior clause has not been declared.',
+ 5
+ );
+ }
$handle = new DefaultBehavior($this);
- break;
+
+ break;
case 'description':
$handle = new Description($this);
- break;
+
+ break;
default:
- throw new \Hoa\Praspel\Exception\Model(
+ throw new Praspel\Exception\Model(
'Clause @%s is unknown.',
- 6, array($clause, $this->getName()));
+ 6,
+ [$clause, $this->getName()]
+ );
}
return $this->_clauses[$clause] = $handle;
@@ -242,18 +212,20 @@ class Behavior extends Clause {
/**
* Add a clause.
*
- * @access public
* @param \Hoa\Praspel\Model\Clause $clause Clause.
* @return \Hoa\Praspel\Model\Clause
*/
- public function addClause ( Clause $clause ) {
-
+ public function addClause(Clause $clause)
+ {
$name = $clause->getName();
- if(false === in_array($name, static::getAllowedClauses()))
- throw new \Hoa\Praspel\Exception\Model(
+ if (false === in_array($name, static::getAllowedClauses())) {
+ throw new Praspel\Exception\Model(
'Clause @%s is not allowed in @%s.',
- 7, array($name, $this->getId()));
+ 7,
+ [$name, $this->getId()]
+ );
+ }
$clause->setParent($this);
@@ -263,34 +235,31 @@ class Behavior extends Clause {
/**
* Check if a clause already exists, i.e. has been declared.
*
- * @access public
* @param string $clause Clause (without leading arobase).
* @return bool
*/
- public function clauseExists ( $clause ) {
-
+ public function clauseExists($clause)
+ {
return isset($this->_clauses[$clause]);
}
/**
* Get allowed clauses.
*
- * @access public
* @return array
*/
- public static function getAllowedClauses ( ) {
-
+ public static function getAllowedClauses()
+ {
return static::$_allowedClauses;
}
/**
* Set identifier.
*
- * @access public
* @return string
*/
- public function setIdentifier ( $identifier ) {
-
+ public function setIdentifier($identifier)
+ {
$old = $this->_identifier;
$this->_identifier = $identifier;
@@ -300,24 +269,20 @@ class Behavior extends Clause {
/**
* Get identifier.
*
- * @access public
* @return string
*/
- public function getIdentifier ( ) {
-
+ public function getIdentifier()
+ {
return $this->_identifier;
}
/**
* Get identifier (fallback).
*
- * @access protected
* @return string
*/
- protected function _getId ( ) {
-
+ protected function _getId()
+ {
return $this->getName() . '_' . $this->getIdentifier();
}
}
-
-}
diff --git a/Model/Clause.php b/Model/Clause.php
index ed66b47..198eb6f 100644
--- a/Model/Clause.php
+++ b/Model/Clause.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,20 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Model;
-from('Hoa')
-
-/**
- * \Hoa\Visitor\Element
- */
--> import('Visitor.Element');
-
-}
-
-namespace Hoa\Praspel\Model {
+use Hoa\Visitor;
/**
* Class \Hoa\Praspel\Model\Clause.
*
* Represent a clause.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
-abstract class Clause implements \Hoa\Visitor\Element {
-
+abstract class Clause implements Visitor\Element
+{
/**
* Name.
*
@@ -69,7 +58,7 @@ abstract class Clause implements \Hoa\Visitor\Element {
/**
* Parent clause.
*
- * @var \Hoa\Praspel\Model\Clause object
+ * @var \Hoa\Praspel\Model\Clause
*/
protected $_parent = null;
@@ -78,12 +67,11 @@ abstract class Clause implements \Hoa\Visitor\Element {
/**
* Build a clause.
*
- * @access public
* @param \Hoa\Praspel\Model\Clause $parent Parent.
* @return void
*/
- public function __construct ( Clause $parent ) {
-
+ public function __construct(Clause $parent)
+ {
$this->setParent($parent);
return;
@@ -92,12 +80,11 @@ abstract class Clause implements \Hoa\Visitor\Element {
/**
* Set parent clause.
*
- * @access protected
* @param \Hoa\Praspel\Model\Clause $parent Parent.
* @return \Hoa\Praspel\Model\Clause
*/
- protected function setParent ( Clause $parent ) {
-
+ protected function setParent(Clause $parent)
+ {
$old = $this->_parent;
$this->_parent = $parent;
@@ -107,26 +94,25 @@ abstract class Clause implements \Hoa\Visitor\Element {
/**
* Get parent clause.
*
- * @access public
* @return \Hoa\Praspel\Model\Clause
*/
- public function getParent ( ) {
-
+ public function getParent()
+ {
return $this->_parent;
}
/**
* Get the root clause.
*
- * @access public
* @return \Hoa\Praspel\Model\Clause
*/
- public function getRoot ( ) {
-
+ public function getRoot()
+ {
$parent = $this;
- while(null !== $nextParent = $parent->getParent())
+ while (null !== $nextParent = $parent->getParent()) {
$parent = $nextParent;
+ }
return $parent;
}
@@ -134,28 +120,27 @@ abstract class Clause implements \Hoa\Visitor\Element {
/**
* Get clause name.
*
- * @access public
* @return string
*/
- public function getName ( ) {
-
+ public function getName()
+ {
return static::NAME;
}
/**
* Get identifier.
*
- * @access public
* @return string
*/
- public function getId ( ) {
-
+ public function getId()
+ {
$out = null;
$parent = $this->getParent();
- if( null !== $parent
- && !($parent instanceof Specification))
+ if (null !== $parent &&
+ !($parent instanceof Specification)) {
$out .= $this->getParent()->getId() . '_';
+ }
return $out . $this->_getId();
}
@@ -163,28 +148,26 @@ abstract class Clause implements \Hoa\Visitor\Element {
/**
* Get identifier (fallback).
*
- * @access protected
* @return string
*/
- protected function _getId ( ) {
-
+ protected function _getId()
+ {
return $this->getName();
}
/**
* Accept a visitor.
*
- * @access public
* @param \Hoa\Visitor\Visit $visitor Visitor.
* @param mixed &$handle Handle (reference).
* @param mixed $eldnah Handle (no reference).
* @return mixed
*/
- public function accept ( \Hoa\Visitor\Visit $visitor,
- &$handle = null, $eldnah = null ) {
-
+ public function accept(
+ Visitor\Visit $visitor,
+ &$handle = null,
+ $eldnah = null
+ ) {
return $visitor->visit($this, $handle, $eldnah);
}
}
-
-}
diff --git a/Model/Collection.php b/Model/Collection.php
index 74cd182..98ad7f0 100644
--- a/Model/Collection.php
+++ b/Model/Collection.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,75 +34,51 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Model;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Model
- */
--> import('Praspel.Exception.Model')
-
-/**
- * \Hoa\Visitor\Element
- */
--> import('Visitor.Element')
-
-/**
- * \Hoa\Iterator\Aggregate
- */
--> import('Iterator.Aggregate')
-
-/**
- * \Hoa\Iterator\Map
- */
--> import('Iterator.Map');
-
-}
-
-namespace Hoa\Praspel\Model {
+use Hoa\Iterator;
+use Hoa\Praspel;
+use Hoa\Visitor;
/**
* Class \Hoa\Praspel\Model\Collection.
*
* Represent a collection of clauses.
*
- * @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 Collection
- implements \Hoa\Visitor\Element,
- \Hoa\Iterator\Aggregate,
+ implements Visitor\Element,
+ Iterator\Aggregate,
\ArrayAccess,
- \Countable {
-
+ \Countable
+{
/**
* Clauses.
*
- * @var \Hoa\Praspel\Model\Collection array
+ * @var array
*/
- protected $_clauses = array();
+ protected $_clauses = [];
/**
* Mapping from position to clauses (instead of identifier).
*
- * @var \Hoa\Praspel\Model\Collection array
+ * @var array
*/
- protected $_mapping = array();
+ protected $_mapping = [];
/**
* Reference clause.
*
- * @var \Hoa\Praspel\Model\Clause object
+ * @var \Hoa\Praspel\Model\Clause
*/
protected $_clause = null;
/**
* Post-clone function.
*
- * @var \Closure closure
+ * @var closure
*/
protected $_postClone = null;
@@ -111,14 +87,12 @@ class Collection
/**
* Build a collection of clauses.
*
- * @access public
* @param \Hoa\Praspel\Model\Clause $clause Clause.
* @param \Closure $postClone Post-clone function.
* @return void
*/
- public function __construct ( Clause $clause,
- \Closure $postClone = null ) {
-
+ public function __construct(Clause $clause, \Closure $postClone = null)
+ {
$this->_clause = $clause;
$this->_postClone = $postClone;
@@ -128,33 +102,31 @@ class Collection
/**
* Check whether an offset exists.
*
- * @access public
* @param string $offset Offset.
* @return bool
*/
- public function offsetExists ( $offset ) {
-
+ public function offsetExists($offset)
+ {
return false !== array_key_exists($offset, $this->_clauses);
}
/**
* Get a clause.
*
- * @access public
* @param string $offset Offset.
* @return \Hoa\Praspel\Model\Clause
*/
- public function offsetGet ( $offset ) {
-
- if(false === $this->offsetExists($offset)) {
-
+ public function offsetGet($offset)
+ {
+ if (false === $this->offsetExists($offset)) {
$clause = $this->getClause();
$this->_clauses[$offset] = clone $clause;
$this->_mapping[] = &$this->_clauses[$offset];
$postClone = $this->getPostClone();
- if(null !== $postClone)
+ if (null !== $postClone) {
$postClone($this->_clauses[$offset], $offset);
+ }
}
return $this->_clauses[$offset];
@@ -163,26 +135,25 @@ class Collection
/**
* Alias of $this->offsetGet($offset).
*
- * @access public
* @param string $identifier Identifier.
* @return \Hoa\Praspel\Model\Clause
*/
- public function get ( $offset ) {
-
+ public function get($offset)
+ {
return $this->offsetGet($offset);
}
/**
* Get a clause from its position.
*
- * @access public
* @param string $position Position.
* @return \Hoa\Praspel\Model\Clause
*/
- public function getNth ( $position ) {
-
- if(!isset($this->_mapping[$position]))
+ public function getNth($position)
+ {
+ if (!isset($this->_mapping[$position])) {
return null;
+ }
return $this->_mapping[$position];
}
@@ -190,85 +161,78 @@ class Collection
/**
* Disabled.
*
- * @access public
* @return void
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- public function offsetSet ( $offset, $value ) {
-
- throw new \Hoa\Praspel\Exception\Model('Operation denied.', 0);
+ public function offsetSet($offset, $value)
+ {
+ throw new Praspel\Exception\Model('Operation denied.', 0);
}
/**
* Disabled.
*
- * @access public
* @return void
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- public function offsetUnset ( $offset ) {
-
- throw new \Hoa\Praspel\Exception\Model('Operation denied.', 0);
+ public function offsetUnset($offset)
+ {
+ throw new Praspel\Exception\Model('Operation denied.', 1);
}
/**
* Get reference clause.
*
- * @access protected
* @return \Hoa\Praspel\Model\Clause
*/
- protected function getClause ( ) {
-
+ protected function getClause()
+ {
return $this->_clause;
}
/**
* Get post-clone function.
*
- * @access protected
* @return \Closure
*/
- protected function getPostClone ( ) {
-
+ protected function getPostClone()
+ {
return $this->_postClone;
}
/**
* Iterate over all clauses.
*
- * @access public
* @return \Hoa\Iterator\Map
*/
- public function getIterator ( ) {
-
- return new \Hoa\Iterator\Map($this->_clauses);
+ public function getIterator()
+ {
+ return new Iterator\Map($this->_clauses);
}
/**
* Count number of clauses.
*
- * @access public
* @return int
*/
- public function count ( ) {
-
+ public function count()
+ {
return count($this->_clauses);
}
/**
* Accept a visitor.
*
- * @access public
* @param \Hoa\Visitor\Visit $visitor Visitor.
* @param mixed &$handle Handle (reference).
* @param mixed $eldnah Handle (no reference).
* @return mixed
*/
- public function accept ( \Hoa\Visitor\Visit $visitor,
- &$handle = null, $eldnah = null ) {
-
+ public function accept(
+ Visitor\Visit $visitor,
+ &$handle = null,
+ $eldnah = null
+ ) {
return $visitor->visit($this, $handle, $eldnah);
}
}
-
-}
diff --git a/Model/Declaration.php b/Model/Declaration.php
index e0708fe..697d9e8 100644
--- a/Model/Declaration.php
+++ b/Model/Declaration.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,93 +34,44 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Model;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Model
- */
--> import('Praspel.Exception.Model')
-
-/**
- * \Hoa\Praspel\Model\Clause
- */
--> import('Praspel.Model.Clause')
-
-/**
- * \Hoa\Praspel\Model\Variable
- */
--> import('Praspel.Model.Variable.~')
-
-/**
- * \Hoa\Praspel\Model\Variable\Borrowing
- */
--> import('Praspel.Model.Variable.Borrowing')
-
-/**
- * \Hoa\Realdom\Crate\Variable
- */
--> import('Realdom.Crate.Variable')
-
-/**
- * \Hoa\Realdom\Crate\Constant
- */
--> import('Realdom.Crate.Constant')
-
-/**
- * \Hoa\Iterator\Aggregate
- */
--> import('Iterator.Aggregate')
-
-/**
- * \Hoa\Iterator\CallbackFilter
- */
--> import('Iterator.CallbackFilter')
-
-/**
- * \Hoa\Iterator\Map
- */
--> import('Iterator.Map');
-
-}
-
-namespace Hoa\Praspel\Model {
+use Hoa\Iterator;
+use Hoa\Praspel;
+use Hoa\Realdom;
/**
* Class \Hoa\Praspel\Model\Declaration.
*
* Represent a declaration.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
abstract class Declaration
extends Clause
- implements \Hoa\Iterator\Aggregate,
+ implements Iterator\Aggregate,
\ArrayAccess,
- \Countable {
-
+ \Countable
+{
/**
* Declared variables.
*
- * @var \Hoa\Praspel\Model\Declaration array
+ * @var array
*/
- protected $_variables = array();
+ protected $_variables = [];
/**
* Predicates.
*
- * @var \Hoa\Praspel\Model\Declaration array
+ * @var array
*/
- protected $_predicates = array();
+ protected $_predicates = [];
/**
* Whether declaring a local variable or not.
*
- * @var \Hoa\Praspel\Model\Declaration bool
+ * @var bool
*/
protected $_let = false;
@@ -129,61 +80,54 @@ abstract class Declaration
/**
* Check if a variable exists.
*
- * @access public
* @param string $offset Variable name.
* @return bool
*/
- public function offsetExists ( $offset ) {
-
+ public function offsetExists($offset)
+ {
return isset($this->_variables[$offset]);
}
/**
* Get or create a variable.
*
- * @access public
* @param string $offset Variable name.
* @return \Hoa\Praspel\Model\Variable
*/
- public function offsetGet ( $offset ) {
-
+ public function offsetGet($offset)
+ {
return $this->getVariable($offset);
}
/**
* Declare or get a new variable.
*
- * @access public
* @param string $name Variable name.
* @param bool $borrowing Borrowing variable or not.
* @return mixed
*/
- public function getVariable ( $name, $borrowing = false ) {
-
- if(true === $borrowing) {
-
+ public function getVariable($name, $borrowing = false)
+ {
+ if (true === $borrowing) {
$out = new Variable\Borrowing($name, $this->_let, $this);
$this->_let = false;
return $out;
}
- if('\old(' === substr($name, 0, 5)) {
-
+ if ('\old(' === substr($name, 0, 5)) {
$variable = $this->getVariable($name, true);
- return new \Hoa\Realdom\Crate\Constant(
+ return new Realdom\Crate\Constant(
$variable->getBorrowedVariable(),
- function ( ) use ( $variable ) {
-
+ function () use ($variable) {
return $variable->getName();
},
$this
);
}
- if(false === $this->offsetExists($name)) {
-
+ if (false === $this->offsetExists($name)) {
$variable = new Variable($name, $this->_let, $this);
$this->_let = false;
@@ -196,26 +140,24 @@ abstract class Declaration
/**
* Add a variable.
*
- * @access public
* @param string $name Name.
* @param \Hoa\Praspel\Model\Variable $variable Variable.
* @return \Hoa\Praspel\Model\Variable
*/
- public function addVariable ( $name, Variable $variable ) {
-
+ public function addVariable($name, Variable $variable)
+ {
return $this->_variables[$name] = $variable;
}
/**
* Set a value to a variable.
*
- * @access public
* @param string $offset Variable name.
* @param mixed $value Variable value.
* @return mixed
*/
- public function offsetSet ( $offset, $value ) {
-
+ public function offsetSet($offset, $value)
+ {
$variable = $this->offsetGet($offset);
$old = $variable->getValue();
$variable->setValue($value);
@@ -226,12 +168,11 @@ abstract class Declaration
/**
* Delete a variable.
*
- * @access public
* @param string $offset Variable name.
* @return void
*/
- public function offsetUnset ( $offset ) {
-
+ public function offsetUnset($offset)
+ {
unset($this->_variables[$offset]);
return;
@@ -241,14 +182,14 @@ abstract class Declaration
* Allow to write $clause->let['var'] = … to define a local variable (if
* $name is not equal to "let", then it is a normal behavior).
*
- * @access public
* @param string $name Name.
* @return \Hoa\Praspel\Model\Declaration
*/
- public function __get ( $name ) {
-
- if('let' !== $name)
+ public function __get($name)
+ {
+ if ('let' !== $name) {
return $this->$name;
+ }
$this->_let = true;
@@ -258,15 +199,13 @@ abstract class Declaration
/**
* Iterator over local variables.
*
- * @access public
* @return \Hoa\Iterator\CallbackFilter
*/
- public function getIterator ( ) {
-
- return new \Hoa\Iterator\CallbackFilter(
- new \Hoa\Iterator\Map($this->getLocalVariables()),
- function ( Variable $variable ) {
-
+ public function getIterator()
+ {
+ return new Iterator\CallbackFilter(
+ new Iterator\Map($this->getLocalVariables()),
+ function (Variable $variable) {
return false === $variable->isLocal();
}
);
@@ -275,46 +214,44 @@ abstract class Declaration
/**
* Count number of variables.
*
- * @access public
* @return int
*/
- public function count ( ) {
-
+ public function count()
+ {
return count($this->_variables);
}
/**
* Get local variables.
*
- * @access public
* @return array
*/
- public function &getLocalVariables ( ) {
-
+ public function &getLocalVariables()
+ {
return $this->_variables;
}
/**
* Get in-scope variables.
*
- * @access public
* @return array
*/
- public function getInScopeVariables ( ) {
-
- $out = array();
+ public function getInScopeVariables()
+ {
+ $out = [];
$clause = $this->getName();
$current = $this;
- while(null !== $current = $current->getParent()) {
-
- if(false === $current->clauseExists($clause))
+ while (null !== $current = $current->getParent()) {
+ if (false === $current->clauseExists($clause)) {
continue;
+ }
$localVariables = &$current->getClause($clause)->getLocalVariables();
- foreach($localVariables as $name => &$variables)
+ foreach ($localVariables as $name => &$variables) {
$out[$name] = &$variables;
+ }
}
return $out;
@@ -323,12 +260,11 @@ abstract class Declaration
/**
* Add a predicate.
*
- * @access public
* @param string $predicate Predicate.
* @return \Hoa\Praspel\Model\Declaration
*/
- public function predicate ( $predicate ) {
-
+ public function predicate($predicate)
+ {
$this->_predicates[] = $predicate;
return $this;
@@ -337,13 +273,10 @@ abstract class Declaration
/**
* Get all predicates.
*
- * @access public
* @return array
*/
- public function getPredicates ( ) {
-
+ public function getPredicates()
+ {
return $this->_predicates;
}
}
-
-}
diff --git a/Model/DefaultBehavior.php b/Model/DefaultBehavior.php
index 5675ff8..5696f35 100644
--- a/Model/DefaultBehavior.php
+++ b/Model/DefaultBehavior.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,18 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Model\Behavior
- */
--> import('Praspel.Model.Behavior');
-
-}
-
-namespace Hoa\Praspel\Model {
+namespace Hoa\Praspel\Model;
/**
* Class \Hoa\Praspel\Model\DefaultBehavior.
*
* Represent a default behavior.
*
- * @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 DefaultBehavior extends Behavior {
-
+class DefaultBehavior extends Behavior
+{
/**
* Name.
*
@@ -69,26 +56,23 @@ class DefaultBehavior extends Behavior {
/**
* Allowed clauses.
*
- * @var \Hoa\Praspel\Model\DefaultBehavior array
+ * @var array
*/
- protected static $_allowedClauses = array(
+ protected static $_allowedClauses = [
'invariant',
'ensures',
'throwable'
- );
+ ];
/**
* Get identifier (fallback).
*
- * @access protected
* @return string
*/
- protected function _getId ( ) {
-
+ protected function _getId()
+ {
return $this->getName();
}
}
-
-}
diff --git a/Model/Description.php b/Model/Description.php
index 68274a3..191a37b 100644
--- a/Model/Description.php
+++ b/Model/Description.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,45 +34,24 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Model;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Model\Clause
- */
--> import('Praspel.Model.Clause')
-
-/**
- * \Hoa\Iterator\Aggregate
- */
--> import('Iterator.Aggregate')
-
-/**
- * \Hoa\Iterator\Map
- */
--> import('Iterator.Map');
-
-}
-
-namespace Hoa\Praspel\Model {
+use Hoa\Iterator;
/**
* Class \Hoa\Praspel\Model\Description.
*
* Represent the @description clause.
*
- * @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 Description
extends Clause
- implements \Hoa\Iterator\Aggregate,
+ implements Iterator\Aggregate,
\ArrayAccess,
- \Countable {
-
+ \Countable
+{
/**
* Name.
*
@@ -83,35 +62,34 @@ class Description
/**
* Examples.
*
- * @var \Hoa\Praspel\Model\Description array
+ * @var array
*/
- protected $_examples = array();
+ protected $_examples = [];
/**
* Check if an example exists.
*
- * @access public
* @param int $offset Offset.
* @return bool
*/
- public function offsetExists ( $offset ) {
-
+ public function offsetExists($offset)
+ {
return isset($this->_examples[$offset]);
}
/**
* Get an example.
*
- * @access public
* @param int $offset Offset.
* @return string
*/
- public function offsetGet ( $offset ) {
-
- if(false === $this->offsetExists($offset))
+ public function offsetGet($offset)
+ {
+ if (false === $this->offsetExists($offset)) {
return null;
+ }
return $this->_examples[$offset];
}
@@ -119,17 +97,17 @@ class Description
/**
* Set an example.
*
- * @access public
* @param int $offset Offset.
* @param string $value Example value.
* @return \Hoa\Praspel\Model\Description
*/
- public function offsetSet ( $offset, $value ) {
-
- if(null === $offset)
- $this->_examples[] = $value;
- else
+ public function offsetSet($offset, $value)
+ {
+ if (null === $offset) {
+ $this->_examples[] = $value;
+ } else {
$this->_examples[$offset] = $value;
+ }
return $this;
}
@@ -137,12 +115,11 @@ class Description
/**
* Unset an example.
*
- * @access public
* @param int $offset Offset.
* @return void
*/
- public function offsetUnset ( $offset ) {
-
+ public function offsetUnset($offset)
+ {
unset($this->_examples[$offset]);
return;
@@ -151,24 +128,20 @@ class Description
/**
* Iterator over examples.
*
- * @access public
* @return \Hoa\Iterator\Map
*/
- public function getIterator ( ) {
-
- return new \Hoa\Iterator\Map($this->_examples);
+ public function getIterator()
+ {
+ return new Iterator\Map($this->_examples);
}
/**
* Count number of examples.
*
- * @access public
* @return int
*/
- public function count ( ) {
-
+ public function count()
+ {
return count($this->_examples);
}
}
-
-}
diff --git a/Model/Ensures.php b/Model/Ensures.php
index 0a08c4e..57c65e4 100644
--- a/Model/Ensures.php
+++ b/Model/Ensures.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,18 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Model\Declaration
- */
--> import('Praspel.Model.Declaration');
-
-}
-
-namespace Hoa\Praspel\Model {
+namespace Hoa\Praspel\Model;
/**
* Class \Hoa\Praspel\Model\Ensures.
*
* Represent the @ensures clause.
*
- * @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 Ensures extends Declaration {
-
+class Ensures extends Declaration
+{
/**
* Name.
*
@@ -66,5 +53,3 @@ class Ensures extends Declaration {
*/
const NAME = 'ensures';
}
-
-}
diff --git a/Model/Invariant.php b/Model/Invariant.php
index c084f05..6f8eadc 100644
--- a/Model/Invariant.php
+++ b/Model/Invariant.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,18 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Model\Declaration
- */
--> import('Praspel.Model.Declaration');
-
-}
-
-namespace Hoa\Praspel\Model {
+namespace Hoa\Praspel\Model;
/**
* Class \Hoa\Praspel\Model\Invariant.
*
* Represent the @invariant clause.
*
- * @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 Invariant extends Declaration {
-
+class Invariant extends Declaration
+{
/**
* Name.
*
@@ -66,5 +53,3 @@ class Invariant extends Declaration {
*/
const NAME = 'invariant';
}
-
-}
diff --git a/Model/Is.php b/Model/Is.php
index f2c213c..c26b948 100644
--- a/Model/Is.php
+++ b/Model/Is.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,18 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Model\Clause
- */
--> import('Praspel.Model.Clause');
-
-}
-
-namespace Hoa\Praspel\Model {
+namespace Hoa\Praspel\Model;
/**
* Class \Hoa\Praspel\Model\Is.
*
* Represent the @is clause.
*
- * @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 Is extends Clause {
-
+class Is extends Clause
+{
/**
* Name.
*
@@ -76,7 +63,7 @@ class Is extends Clause {
/**
* Properties.
*
- * @var \Hoa\Praspel\Model\Is int
+ * @var int
*/
protected $_property = 0;
@@ -85,24 +72,22 @@ class Is extends Clause {
/**
* Check if a property is declared.
*
- * @access public
* @param int $property Property.
* @return bool
*/
- public function is ( $property ) {
-
+ public function is($property)
+ {
return $property === ($this->_property & $property);
}
/**
* Set the property value.
*
- * @access public
* @param int $property Property.
* @return int
*/
- public function setProperty ( $property ) {
-
+ public function setProperty($property)
+ {
$old = $this->_property;
$this->_property = $property;
@@ -112,12 +97,11 @@ class Is extends Clause {
/**
* Add a property.
*
- * @access public
* @param int $property Property.
* @return int
*/
- public function addProperty ( $property ) {
-
+ public function addProperty($property)
+ {
$old = $this->_property;
$this->_property |= $property;
@@ -127,12 +111,11 @@ class Is extends Clause {
/**
* Remove a property.
*
- * @access public
* @param int $property Property.
* @return int
*/
- public function removeProperty ( $property ) {
-
+ public function removeProperty($property)
+ {
$old = $this->_property;
$this->_property ^= $property;
@@ -142,26 +125,25 @@ class Is extends Clause {
/**
* Get the property value.
*
- * @access public
* @return int
*/
- public function getProperty ( ) {
-
+ public function getProperty()
+ {
return $this->_property;
}
/**
* Get property name.
*
- * @access public
* @return string
*/
- public function getPropertyName ( ) {
-
- $out = array();
+ public function getPropertyName()
+ {
+ $out = [];
- if(true === $this->is(static::PURE))
+ if (true === $this->is(static::PURE)) {
$out[] = 'pure';
+ }
return implode(', ', $out);
}
@@ -169,14 +151,12 @@ class Is extends Clause {
/**
* Get property value from a string.
*
- * @access public
* @param string $property Property name.
* @return int
*/
- public static function getPropertyValue ( $property ) {
-
- switch($property) {
-
+ public static function getPropertyValue($property)
+ {
+ switch ($property) {
case 'pure':
return static::PURE;
}
@@ -184,5 +164,3 @@ class Is extends Clause {
return 0;
}
}
-
-}
diff --git a/Model/Requires.php b/Model/Requires.php
index 4cd0727..9a7bdee 100644
--- a/Model/Requires.php
+++ b/Model/Requires.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,18 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Model\Declaration
- */
--> import('Praspel.Model.Declaration');
-
-}
-
-namespace Hoa\Praspel\Model {
+namespace Hoa\Praspel\Model;
/**
* Class \Hoa\Praspel\Model\Requires.
*
* Represent the @requires clause.
*
- * @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 Requires extends Declaration {
-
+class Requires extends Declaration
+{
/**
* Name.
*
@@ -66,5 +53,3 @@ class Requires extends Declaration {
*/
const NAME = 'requires';
}
-
-}
diff --git a/Model/Specification.php b/Model/Specification.php
index 47b1277..a352c8a 100644
--- a/Model/Specification.php
+++ b/Model/Specification.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,25 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Model;
from('Hoa')
/**
- * \Hoa\Praspel\Model\Behavior
- */
--> import('Praspel.Model.Behavior')
-
-/**
* \Hoa\Realdom\Disjunction
*/
-> import('Realdom.Disjunction', true);
-}
-
-namespace Hoa\Praspel\Model {
-
/**
* Class \Hoa\Praspel\Model\Specification.
*
* Represent a specification (contains all clauses).
*
- * @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 Specification extends Behavior {
-
+class Specification extends Behavior
+{
/**
* Name.
*
@@ -74,9 +63,9 @@ class Specification extends Behavior {
/**
* Allowed clauses.
*
- * @var \Hoa\Praspel\Model\Specification array
+ * @var array
*/
- protected static $_allowedClauses = array(
+ protected static $_allowedClauses = [
'is',
'invariant',
'requires',
@@ -85,19 +74,19 @@ class Specification extends Behavior {
'ensures',
'throwable',
'description'
- );
+ ];
/**
* Implicit variables.
*
- * @var \Hoa\Praspel\Model\Specification array
+ * @var array
*/
- protected $_implicitVariables = array();
+ protected $_implicitVariables = [];
/**
* Binded class.
*
- * @var \Hoa\Praspel\Model\Specification string
+ * @var string
*/
protected $_bindedClass = null;
@@ -106,39 +95,38 @@ class Specification extends Behavior {
/**
* Cancel the constructor from the parent.
*
- * @access public
* @return void
*/
- public function __construct ( ) {
-
+ public function __construct()
+ {
return;
}
/**
* Get an implicit variable.
*
- * @access public
* @param string $identifier Identifier.
* @return \Hoa\Praspel\Model\Variable\Implicit
*/
- public function getImplicitVariable ( $identifier ) {
-
- if(isset($this->_implicitVariables[$identifier]))
+ public function getImplicitVariable($identifier)
+ {
+ if (isset($this->_implicitVariables[$identifier])) {
return $this->_implicitVariables[$identifier];
+ }
- return $this->_implicitVariables[$identifier]
- = new Variable\Implicit($identifier, false, $this);
+ return
+ $this->_implicitVariables[$identifier] =
+ new Variable\Implicit($identifier, false, $this);
}
/**
* Bind this specification to a specific class.
* Obligatory for dynamic or static resolutions.
*
- * @access public
* @return string
*/
- public function bindToClass ( $classname ) {
-
+ public function bindToClass($classname)
+ {
$old = $this->_bindedClass;
$this->_bindedClass = ltrim($classname, '\\');
@@ -148,24 +136,20 @@ class Specification extends Behavior {
/**
* Get binded class.
*
- * @access public
* @return string
*/
- public function getBindedClass ( ) {
-
+ public function getBindedClass()
+ {
return $this->_bindedClass;
}
/**
* Get identifier (fallback).
*
- * @access protected
* @return string
*/
- protected function _getId ( ) {
-
+ protected function _getId()
+ {
return 'praspel';
}
}
-
-}
diff --git a/Model/Throwable.php b/Model/Throwable.php
index 11fbae8..17b787d 100644
--- a/Model/Throwable.php
+++ b/Model/Throwable.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,50 +34,24 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Model;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Model\Clause
- */
--> import('Praspel.Model.Clause')
-
-/**
- * \Hoa\Praspel\Model\Ensures
- */
--> import('Praspel.Model.Ensures')
-
-/**
- * \Hoa\Iterator\Aggregate
- */
--> import('Iterator.Aggregate')
-
-/**
- * \Hoa\Iterator\Map
- */
--> import('Iterator.Map');
-
-}
-
-namespace Hoa\Praspel\Model {
+use Hoa\Iterator;
/**
* Class \Hoa\Praspel\Model\Throwable.
*
* Represent the @throwable clause.
*
- * @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 Throwable
extends Clause
- implements \Hoa\Iterator\Aggregate,
+ implements Iterator\Aggregate,
\ArrayAccess,
- \Countable {
-
+ \Countable
+{
/**
* Name.
*
@@ -116,14 +90,14 @@ class Throwable
/**
* List of exception names.
*
- * @var \Hoa\Praspel\Model\Throwable array
+ * @var array
*/
- protected $_exceptions = array();
+ protected $_exceptions = [];
/**
* Current exception.
*
- * @var \Hoa\Praspel\Model\Throwable array
+ * @var array
*/
protected $_currentException = null;
@@ -132,26 +106,25 @@ class Throwable
/**
* Check if an exception identifier exists.
*
- * @access public
* @param string $identifier Exception identifier.
* @return bool
*/
- public function offsetExists ( $identifier ) {
-
+ public function offsetExists($identifier)
+ {
return isset($this->_exceptions[$identifier]);
}
/**
* Select an exception.
*
- * @access public
* @param string $identifier Exception identifier.
* @return \Hoa\Praspel\Model\Throwable
*/
- public function offsetGet ( $identifier ) {
-
- if(false === $this->offsetExists($identifier))
+ public function offsetGet($identifier)
+ {
+ if (false === $this->offsetExists($identifier)) {
return null;
+ }
unset($this->_currentException);
$this->_currentException = &$this->_exceptions[$identifier];
@@ -162,20 +135,19 @@ class Throwable
/**
* Add an exception.
*
- * @access public
* @param string $identifier Exception identifier.
* @param mixed $instanceName Exception instance name.
* @return mixed
*/
- public function offsetSet ( $identifier, $instanceName ) {
-
+ public function offsetSet($identifier, $instanceName)
+ {
$old = $this->offsetGet($identifier);
- $this->_exceptions[$identifier] = array(
+ $this->_exceptions[$identifier] = [
static::IDENTIFIER => $identifier,
static::INSTANCE_OF => $instanceName,
static::WITH => null,
static::DISJUNCTION => null
- );
+ ];
return $old;
}
@@ -183,12 +155,11 @@ class Throwable
/**
* Delete an exception.
*
- * @access public
* @param string $identifier Exception identifier.
* @return void
*/
- public function offsetUnset ( $identifier ) {
-
+ public function offsetUnset($identifier)
+ {
unset($this->_exceptions[$identifier]);
return;
@@ -197,13 +168,13 @@ class Throwable
/**
* Get instance name.
*
- * @access public
* @return string
*/
- public function getInstanceName ( ) {
-
- if(null === $this->_currentException)
+ public function getInstanceName()
+ {
+ if (null === $this->_currentException) {
return null;
+ }
return $this->_currentException[static::INSTANCE_OF];
}
@@ -212,25 +183,24 @@ class Throwable
* Create a new with instance (an Hoa\Praspel\Model\Ensures instance with
* this instance as parent).
*
- * @access public
* @return \Hoa\Praspel\Model\Ensures
*/
- public function newWith ( ) {
-
+ public function newWith()
+ {
return new Ensures($this);
}
/**
* Set with declaration.
*
- * @access public
* @param \Hoa\Praspel\Model\Ensures $with With.
* @return \Hoa\Praspel\Model\Throwable
*/
- public function setWith ( Ensures $with ) {
-
- if(null === $this->_currentException)
+ public function setWith(Ensures $with)
+ {
+ if (null === $this->_currentException) {
return $this;
+ }
$this->_currentException[static::WITH] = $with;
@@ -240,13 +210,13 @@ class Throwable
/**
* Get with declaration.
*
- * @access public
* @return \Hoa\Praspel\Model\Ensures
*/
- public function getWith ( ) {
-
- if(null === $this->_currentException)
+ public function getWith()
+ {
+ if (null === $this->_currentException) {
return null;
+ }
return $this->_currentException[static::WITH];
}
@@ -254,28 +224,30 @@ class Throwable
/**
* Declare that this exception is disjointed with another one.
*
- * @access public
* @param string $identifier Identifier.
* @return \Hoa\Praspel\Model\Throwable
*/
- public function disjunctionWith ( $identifier ) {
-
- if(null === $this->_currentException)
+ public function disjunctionWith($identifier)
+ {
+ if (null === $this->_currentException) {
return $this;
+ }
- if(false === isset($this[$identifier]))
+ if (false === isset($this[$identifier])) {
return $this;
+ }
$_identifier = &$this->_exceptions[$identifier];
$this->_currentException[static::WITH] = &$_identifier[static::WITH];
- if(true === is_array($_identifier[static::DISJUNCTION]))
+ if (true === is_array($_identifier[static::DISJUNCTION])) {
$_identifier[static::DISJUNCTION][] =
$this->_currentException[static::IDENTIFIER];
- else
- $_identifier[static::DISJUNCTION] = array(
+ } else {
+ $_identifier[static::DISJUNCTION] = [
$this->_currentException[static::IDENTIFIER]
- );
+ ];
+ }
$this->_currentException[static::DISJUNCTION] = $identifier;
@@ -285,11 +257,10 @@ class Throwable
/**
* Check if an exception is disjointed with another one.
*
- * @access public
* @return bool
*/
- public function isDisjointed ( ) {
-
+ public function isDisjointed()
+ {
return is_string($this->getDisjunction());
}
@@ -303,13 +274,13 @@ class Throwable
* If this method returns null, it means that the exception is not in a
* disjunction.
*
- * @access public
* @return mixed
*/
- public function getDisjunction ( ) {
-
- if(null === $this->_currentException)
+ public function getDisjunction()
+ {
+ if (null === $this->_currentException) {
return null;
+ }
return $this->_currentException[static::DISJUNCTION];
}
@@ -317,35 +288,30 @@ class Throwable
/**
* Get exceptions list.
*
- * @access public
* @return array
*/
- public function getExceptions ( ) {
-
+ public function getExceptions()
+ {
return $this->_exceptions;
}
/**
* Iterator over exceptions.
*
- * @access public
* @return \Hoa\Iterator\Map
*/
- public function getIterator ( ) {
-
- return new \Hoa\Iterator\Map(array_keys($this->getExceptions()));
+ public function getIterator()
+ {
+ return new Iterator\Map(array_keys($this->getExceptions()));
}
/**
* Count number of exceptions.
*
- * @access public
* @return int
*/
- public function count ( ) {
-
+ public function count()
+ {
return count($this->getExceptions());
}
}
-
-}
diff --git a/Model/Variable/Borrowing.php b/Model/Variable/Borrowing.php
index e90b291..a0351fe 100644
--- a/Model/Variable/Borrowing.php
+++ b/Model/Variable/Borrowing.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\Model\Variable;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Model
- */
--> import('Praspel.Exception.Model')
-
-/**
- * \Hoa\Praspel\Model\Variable
- */
--> import('Praspel.Model.Variable.~');
-
-}
-
-namespace Hoa\Praspel\Model\Variable {
+use Hoa\Math;
+use Hoa\Praspel;
/**
* Class \Hoa\Praspel\Model\Variable\Borrowing.
*
* Represent a borrowing variable.
*
- * @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 Borrowing extends Variable {
-
+class Borrowing extends Variable
+{
/**
* Type: \old(e).
*
@@ -97,16 +82,17 @@ class Borrowing extends Variable {
/**
* Build a variable.
*
- * @access public
* @param string $name Name.
* @param bool $local Local.
* @param \Hoa\Praspel\Model\Clause $clause Clause.
* @return void
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- public function __construct ( $name, $local,
- \Hoa\Praspel\Model\Clause $clause = null ) {
-
+ public function __construct(
+ $name,
+ $local,
+ Praspel\Model\Clause $clause = null
+ ) {
parent::__construct($name, $local, $clause);
$this->determineType();
@@ -116,22 +102,25 @@ class Borrowing extends Variable {
/**
* Determine type of the variable.
*
- * @access protected
* @return void
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- protected function determineType ( ) {
-
+ protected function determineType()
+ {
$name = $this->getName();
- if('\old(' === substr($name, 0, 5))
+ if ('\old(' === substr($name, 0, 5)) {
$this->computeOld(substr($name, 5, -1));
- elseif(false !== strpos($name, '>', 2))
+ } elseif (false !== strpos($name, '>', 2)) {
$this->computeDynamicResolution($name);
- else
- throw new \Hoa\Praspel\Exception\Model(
+ } else {
+ throw new Praspel\Exception\Model(
'Variable %s would be a borrowing one, but its type cannot ' .
- 'be determined.', 0, $name);
+ 'be determined.',
+ 0,
+ $name
+ );
+ }
return;
}
@@ -139,33 +128,37 @@ class Borrowing extends Variable {
/**
* Compute \old(…).
*
- * @access protected
* @param string $name Name.
* @return void
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- protected function computeOld ( $name ) {
-
+ protected function computeOld($name)
+ {
$clause = $this->getClause();
$this->_type = static::TYPE_OLD;
$parent = $clause->getParent();
- while( false === $parent->clauseExists('requires')
- && null !== $parent = $parent->getParent());
+ while (
+ false === $parent->clauseExists('requires') &&
+ null !== $parent = $parent->getParent()
+ );
- if( null === $parent
- || false === $parent->clauseExists('requires'))
- throw new \Hoa\Praspel\Exception\Model(
- 'No parent or no requires.', 1);
+ if (null === $parent ||
+ false === $parent->clauseExists('requires')) {
+ throw new Praspel\Exception\Model('No parent or no requires.', 1);
+ }
$requires = $parent->getClause('requires');
$inScopeVariables = $requires->getInScopeVariables();
- if(!isset($inScopeVariables[$name]))
- throw new \Hoa\Praspel\Exception\Model(
+ if (!isset($inScopeVariables[$name])) {
+ throw new Praspel\Exception\Model(
'Variable %s does not exist, cannot get its old value ' .
'(in @%s).',
- 2, array($name, $clause->getName()));
+ 2,
+ [$name, $clause->getName()]
+ );
+ }
$this->_variable = &$inScopeVariables[$name];
@@ -175,54 +168,65 @@ class Borrowing extends Variable {
/**
* Compute dynamic resolution.
*
- * @access protected
* @param string $name Name.
* @return void
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- protected function computeDynamicResolution ( $name ) {
-
+ protected function computeDynamicResolution($name)
+ {
$this->_type = static::TYPE_EXTERNAL;
$clause = $this->getClause();
$parts = explode('->', $name);
$head = array_shift($parts);
- if('this' !== $head)
- //$head = $clause->getVariable($parts[0]);
- throw new \Hoa\Praspel\Exception\Model('Not yet implemented!');
+ if ('this' !== $head) {
+ throw new Praspel\Exception\Model('Not yet implemented!');
+ }
- $registry = \Hoa\Praspel::getRegistry();
+ $registry = Praspel::getRegistry();
$root = $clause->getRoot();
$bindedClass = $root->getBindedClass();
- if(null === $bindedClass)
- throw new \Hoa\Praspel\Exception\Model(
+ if (null === $bindedClass) {
+ throw new Praspel\Exception\Model(
'Cannot resolve the dynamic identifier %s; ' .
'%s::getBindedClass returned null.',
- 3, array($name, get_class($root)));
+ 3,
+ [$name, get_class($root)]
+ );
+ }
$attribute = array_shift($parts);
$id = $bindedClass . '::$' . $attribute;
- if(!isset($registry[$id]))
- throw new \Hoa\Praspel\Exception\Model(
+ if (!isset($registry[$id])) {
+ throw new Praspel\Exception\Model(
'The contract identifier %s does not exist in the registry.',
- 4, $name);
+ 4,
+ $name
+ );
+ }
$entry = $registry[$id];
- if(false === $entry->clauseExists('invariant'))
- throw new \Hoa\Praspel\Exception\Model(
+ if (false === $entry->clauseExists('invariant')) {
+ throw new Praspel\Exception\Model(
'%s is not declared with an @invariant clause.',
- 5, $id);
+ 5,
+ $id
+ );
+ }
$targetedClause = $entry->getClause('invariant');
- if(!isset($targetedClause[$attribute]))
- throw new \Hoa\Praspel\Exception\Model(
+ if (!isset($targetedClause[$attribute])) {
+ throw new Praspel\Exception\Model(
'The identifier %s does not exist.',
- 6, $attribute);
+ 6,
+ $attribute
+ );
+ }
$variable = $targetedClause[$attribute];
$this->_variable = $variable;
@@ -233,22 +237,20 @@ class Borrowing extends Variable {
/**
* Get type.
*
- * @access public
* @return int
*/
- public function getType ( ) {
-
+ public function getType()
+ {
return $this->_type;
}
/**
* Get the borrowed variable.
*
- * @access public
* @return \Hoa\Praspel\Model\Variable
*/
- public function getBorrowedVariable ( ) {
-
+ public function getBorrowedVariable()
+ {
return $this->_variable;
}
@@ -256,14 +258,13 @@ class Borrowing extends Variable {
* Allow to write $variable->in = … to define domains (if $name is not equal
* to "in", then it is a normal behavior).
*
- * @access public
* @param string $name Name.
* @param mixed $value Value.
* @return void
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- public function __set ( $name, $value ) {
-
+ public function __set($name, $value)
+ {
return $this->getBorrowedVariable()->__set($name, $value);
}
@@ -274,127 +275,115 @@ class Borrowing extends Variable {
* @param mixed $q Sampled value.
* @return boolean
*/
- public function predicate ( $q = null ) {
-
+ public function predicate($q = null)
+ {
return $this->getBorrowedVariable()->predicate($q);
}
/**
* Call the sample() method on realistic domains.
*
- * @access public
* @param \Hoa\Math\Sampler $sampler Sampler.
* @return mixed
- * @throw \Hoa\Realdom\Exception
+ * @throws \Hoa\Realdom\Exception
*/
- public function sample ( \Hoa\Math\Sampler $sampler = null ) {
-
+ public function sample(Math\Sampler $sampler = null)
+ {
return $this->getBorrowedVariable()->sample($sampler);
}
/**
* Call the reset() method on realistic domains.
*
- * @access public
* @return void
*/
- public function reset ( ) {
-
+ public function reset()
+ {
return $this->getBorrowedVariable()->reset();
}
/**
* Define a “key” constraint. Use $variable->key(…)->in = …;
*
- * @access public
* @param mixed $scalar Value.
* @return \Hoa\Praspel\Model\Variable
*/
- public function key ( $scalar ) {
-
+ public function key($scalar)
+ {
return $this->getBorrowedVariable()->key($scalar);
}
/**
* Define a “contains” constraint.
*
- * @access public
* @param mixed $scalar Value.
* @return \Hoa\Praspel\Model\Variable
*/
- public function contains ( $scalar ) {
-
+ public function contains($scalar)
+ {
return $this->getBorrowedVariable()->contains($scalar);
}
/**
* Add an “is” constraint.
*
- * @access public
* @param string ... Keywords.
* @return \Hoa\Praspel\Model\Variable
*/
- public function is ( ) {
-
- throw new \Hoa\Praspel\Exception\Model('TODO');
+ public function is()
+ {
+ throw new Praspel\Exception\Model('TODO');
}
/**
* Declare a “domainof” (alias).
*
- * @access public
* @param \Hoa\Praspel\Model\Variable $variable Variable.
* @return \Hoa\Praspel\Model\Variable
- * @throw \Hoa\Realdom\Exception
+ * @throws \Hoa\Realdom\Exception
*/
- public function domainof ( $variable ) {
-
+ public function domainof($variable)
+ {
return $this->getBorrowedVariable()->domainof($variable);
}
/**
* Get domains.
*
- * @access public
* @return \Hoa\Realdom\Disjunction
*/
- public function &getDomains ( ) {
-
+ public function &getDomains()
+ {
return $this->getBorrowedVariable()->getDomains();
}
/**
* Get held realdoms.
*
- * @access public
* @return \Hoa\Realdom\Disjunction
*/
- public function &getHeld ( ) {
-
+ public function &getHeld()
+ {
return $this->getBorrowedVariable()->getHeld();
}
/**
* Check if the variable is local (let) or not.
*
- * @access public
* @return bool
*/
- public function isLocal ( ) {
-
+ public function isLocal()
+ {
return $this->getBorrowedVariable()->isLocal();
}
/**
* Get constraints.
*
- * @access public
* @return array
*/
- public function getConstraints ( ) {
-
+ public function getConstraints()
+ {
return $this->getBorrowedVariable()->getConstraints();
}
}
-
-}
diff --git a/Model/Variable/Implicit.php b/Model/Variable/Implicit.php
index d28e8a9..3877480 100644
--- a/Model/Variable/Implicit.php
+++ b/Model/Variable/Implicit.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,57 +34,49 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Model\Variable;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Model
- */
--> import('Praspel.Exception.Model')
+use Hoa\Praspel;
+use Hoa\Realdom;
-/**
- * \Hoa\Praspel\Model\Variable
- */
--> import('Praspel.Model.Variable.~')
+from('Hoa')
/**
* \Hoa\Realdom\Disjunction
*/
-> import('Realdom.Disjunction', true);
-}
-
-namespace Hoa\Praspel\Model\Variable {
-
/**
* Class \Hoa\Praspel\Model\Variable\Implicit.
*
* Represent an implicit variable.
*
- * @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 Implicit extends Variable {
-
+class Implicit extends Variable
+{
/**
* Build a variable.
*
- * @access public
* @param string $name Name.
* @param bool $local Local.
* @param \Hoa\Praspel\Model\Clause $clause Clause.
* @return void
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- public function __construct ( $name, $local,
- \Hoa\Praspel\Model\Clause $clause = null ) {
-
- if('this' !== $name)
- throw new \Hoa\Praspel\Exception\Model(
- 'Variable %s is not an implicit one.', 0, $name);
+ public function __construct(
+ $name,
+ $local,
+ Praspel\Model\Clause $clause = null
+ ) {
+ if ('this' !== $name) {
+ throw new Praspel\Exception\Model(
+ 'Variable %s is not an implicit one.',
+ 0,
+ $name
+ );
+ }
parent::__construct($name, $local, $clause);
@@ -96,18 +88,17 @@ class Implicit extends Variable {
/**
* Bind the variable to a specific value.
*
- * @access public
* @param mixed $value Value.
* @return void
*/
- public function bindTo ( $value ) {
-
- foreach($this->getDomains() as $domain)
- if($domain instanceof \Hoa\Realdom\Object)
+ public function bindTo($value)
+ {
+ foreach ($this->getDomains() as $domain) {
+ if ($domain instanceof Realdom\Object) {
$domain->setObject($value);
+ }
+ }
return;
}
}
-
-}
diff --git a/Model/Variable/Variable.php b/Model/Variable/Variable.php
index d50ff77..8c16410 100644
--- a/Model/Variable/Variable.php
+++ b/Model/Variable/Variable.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,104 +34,87 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Model\Variable;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Model
- */
--> import('Praspel.Exception.Model')
-
-/**
- * \Hoa\Visitor\Element
- */
--> import('Visitor.Element')
-
-/**
- * \Hoa\Realdom\IRealdom\Holder
- */
--> import('Realdom.I~.Holder');
-
-}
-
-namespace Hoa\Praspel\Model\Variable {
+use Hoa\Core;
+use Hoa\Math;
+use Hoa\Praspel;
+use Hoa\Realdom;
+use Hoa\Visitor;
/**
* Class \Hoa\Praspel\Model\Variable.
*
* Represent a variable.
*
- * @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 Variable
- implements \Hoa\Visitor\Element,
- \Hoa\Realdom\IRealdom\Holder {
-
+ implements Visitor\Element,
+ Realdom\IRealdom\Holder
+{
/**
* Variable name.
*
- * @var \Hoa\Praspel\Model\Variable string
+ * @var string
*/
protected $_name = null;
/**
* Local (let) or not.
*
- * @var \Hoa\Praspel\Model\Variable bool
+ * @var bool
*/
protected $_local = false;
/**
* Clause that contains this variable.
*
- * @var \Hoa\Praspel\Model\Clause object
+ * @var \Hoa\Praspel\Model\Clause
*/
protected $_clause = null;
/**
* Variable value.
*
- * @var \Hoa\Praspel\Model\Variable mixed
+ * @var mixed
*/
protected $_value = null;
/**
* Domains that describe the variable.
*
- * @var \Hoa\Realdom\Disjunction object
+ * @var \Hoa\Realdom\Disjunction
*/
protected $_domains = null;
/**
* References domains.
*
- * @var \Hoa\Realdom\Disjunction object
+ * @var \Hoa\Realdom\Disjunction
*/
protected $_refDomains = null;
/**
* Alias variable (please, see “domainof”).
*
- * @var \Hoa\Praspel\Model\Variable object
+ * @var \Hoa\Praspel\Model\Variable
*/
protected $_alias = null;
/**
* Constraints.
*
- * @var \Hoa\Praspel\Model\Variable array
+ * @var array
*/
- protected $_constraints = array();
+ protected $_constraints = [];
/**
* Temporary constraints type.
* Useful when propagate new constraints.
*
- * @var \Hoa\Praspel\Model\Variable string
+ * @var string
*/
protected $_tmpConstraintsType = null;
@@ -139,7 +122,7 @@ class Variable
* Temporary constraints index.
* Useful when propagate new constraints.
*
- * @var \Hoa\Praspel\Model\Variable string
+ * @var string
*/
protected $_tmpConstraintsIndex = null;
@@ -148,23 +131,27 @@ class Variable
/**
* Build a variable.
*
- * @access public
* @param string $name Name.
* @param bool $local Local.
* @param \Hoa\Praspel\Model\Clause $clause Clause.
* @return void
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- public function __construct ( $name, $local,
- \Hoa\Praspel\Model\Clause $clause = null ) {
-
- if( ('\old' === substr($name, 0, 4)
- || '\result' === $name)
- && !($clause instanceof \Hoa\Praspel\Model\Ensures))
- throw new \Hoa\Praspel\Exception\Model(
+ public function __construct(
+ $name,
+ $local,
+ Praspel\Model\Clause $clause = null
+ ) {
+ if (('\old' === substr($name, 0, 4) ||
+ '\result' === $name) &&
+ !($clause instanceof Praspel\Model\Ensures)) {
+ throw new Praspel\Exception\Model(
'\old(…) and \result are only allowed in @ensures, ' .
'given %s in @%s.',
- 0, array($name, $clause->getName()));
+ 0,
+ [$name, $clause->getName()]
+ );
+ }
$this->_name = $name;
$this->_local = $local;
@@ -177,12 +164,11 @@ class Variable
/**
* Set a value to the variable.
*
- * @access public
* @param mixed $value Value.
* @return mixed
*/
- public function setValue ( $value ) {
-
+ public function setValue($value)
+ {
$old = $this->_value;
$this->_value = $value;
@@ -192,11 +178,10 @@ class Variable
/**
* Get value of the variable.
*
- * @access public
* @return mixed
*/
- public function &getValue ( ) {
-
+ public function &getValue()
+ {
return $this->_value;
}
@@ -204,16 +189,14 @@ class Variable
* Allow to write $variable->in = … to define domains (if $name is not equal
* to "in", then it is a normal behavior).
*
- * @access public
* @param string $name Name.
* @param mixed $value Value.
* @return void
- * @throw \Hoa\Praspel\Exception\Model
+ * @throws \Hoa\Praspel\Exception\Model
*/
- public function __set ( $name, $value ) {
-
- if('in' !== $name) {
-
+ public function __set($name, $value)
+ {
+ if ('in' !== $name) {
$this->$name = $value;
return;
@@ -221,19 +204,22 @@ class Variable
$onDomains = $this->_domains === $this->_refDomains;
- if( true === $onDomains
- && !empty($this->_domains))
- throw new \Hoa\Praspel\Exception\Model(
+ if (true === $onDomains &&
+ !empty($this->_domains)) {
+ throw new Praspel\Exception\Model(
'Variable $%s has already declared domains.',
- 1, $this->getName());
+ 1,
+ $this->getName()
+ );
+ }
- if(!($value instanceof \Hoa\Realdom\Disjunction))
+ if (!($value instanceof Realdom\Disjunction)) {
$value = realdom()->const($value);
+ }
$this->_refDomains = $value;
- if(false === $onDomains) {
-
+ if (false === $onDomains) {
$this->_domains->propagateConstraints(
$this->_tmpConstraintsType,
$this->_tmpConstraintsIndex
@@ -248,8 +234,9 @@ class Variable
$this->_domains->setHolder($this);
- foreach($this->_domains as $domain)
+ foreach ($this->_domains as $domain) {
$domain->setConstraints($this->_constraints);
+ }
return;
}
@@ -261,10 +248,11 @@ class Variable
* @param mixed $q Sampled value.
* @return boolean
*/
- public function predicate ( $q = null ) {
-
- if(null === $q)
+ public function predicate($q = null)
+ {
+ if (null === $q) {
$q = $this->getValue();
+ }
return $this->getDomains()->predicate($q);
}
@@ -272,43 +260,41 @@ class Variable
/**
* Call the sample() method on realistic domains.
*
- * @access public
* @param \Hoa\Math\Sampler $sampler Sampler.
* @return mixed
- * @throw \Hoa\Realdom\Exception
+ * @throws \Hoa\Realdom\Exception
*/
- public function sample ( \Hoa\Math\Sampler $sampler = null ) {
-
+ public function sample(Math\Sampler $sampler = null)
+ {
return $this->getDomains()->sample($sampler);
}
/**
* Call the reset() method on realistic domains.
*
- * @access public
* @return void
*/
- public function reset ( ) {
-
+ public function reset()
+ {
return $this->getDomains()->reset();
}
/**
* Define a “key” constraint. Use $variable->key(…)->in = …;
*
- * @access public
* @param mixed $scalar Value.
* @return \Hoa\Praspel\Model\Variable
*/
- public function key ( $scalar ) {
-
- if(!isset($this->_constraints['key']))
- $this->_constraints['key'] = array();
+ public function key($scalar)
+ {
+ if (!isset($this->_constraints['key'])) {
+ $this->_constraints['key'] = [];
+ }
unset($this->_refDomains);
- $handle = &$this->_constraints['key'][];
- $handle[0] = realdom()->const($scalar);
- $this->_refDomains = &$handle[1];
+ $handle = &$this->_constraints['key'][];
+ $handle[0] = realdom()->const($scalar);
+ $this->_refDomains = &$handle[1];
end($this->_constraints['key']);
$this->_tmpConstraintsType = 'key';
@@ -320,14 +306,14 @@ class Variable
/**
* Define a “contains” constraint.
*
- * @access public
* @param mixed $scalar Value.
* @return \Hoa\Praspel\Model\Variable
*/
- public function contains ( $scalar ) {
-
- if(!isset($this->_constraints['contains']))
- $this->_constraints['contains'] = array();
+ public function contains($scalar)
+ {
+ if (!isset($this->_constraints['contains'])) {
+ $this->_constraints['contains'] = [];
+ }
$this->_constraints['contains'][] = realdom()->const($scalar);
@@ -337,14 +323,14 @@ class Variable
/**
* Add an “is” constraint.
*
- * @access public
* @param string ... Keywords.
* @return \Hoa\Praspel\Model\Variable
*/
- public function is ( ) {
-
- if(!isset($this->_constraints['is']))
- $this->_constraints['is'] = array();
+ public function is()
+ {
+ if (!isset($this->_constraints['is'])) {
+ $this->_constraints['is'] = [];
+ }
$this->_constraints['is'] = array_merge(
$this->_constraints['is'],
@@ -357,25 +343,30 @@ class Variable
/**
* Declare a “domainof” (alias).
*
- * @access public
* @param \Hoa\Praspel\Model\Variable $variable Variable.
* @return \Hoa\Praspel\Model\Variable
- * @throw \Hoa\Realdom\Exception
+ * @throws \Hoa\Realdom\Exception
*/
- public function domainof ( $variable ) {
-
+ public function domainof($variable)
+ {
$variables = $this->getClause()->getLocalVariables();
- if(!isset($variables[$variable]))
- throw new \Hoa\Praspel\Exception\Model(
+ if (!isset($variables[$variable])) {
+ throw new Praspel\Exception\Model(
'Variable $%s does not exist, cannot alias domains to $%s.',
- 2, array($variable, $this->getName()));
+ 2,
+ [$variable, $this->getName()]
+ );
+ }
- if(!empty($this->_domains))
- throw new \Hoa\Praspel\Exception\Model(
+ if (!empty($this->_domains)) {
+ throw new Praspel\Exception\Model(
'Variable $%s already has domains, cannot alias new domains ' .
'from $%s.',
- 3, array($this->getName(), $variable));
+ 3,
+ [$this->getName(), $variable]
+ );
+ }
$this->_alias = $variable;
$this->_domains = &$variables[$variable]->getDomains();
@@ -386,103 +377,91 @@ class Variable
/**
* Get domains.
*
- * @access public
* @return \Hoa\Realdom\Disjunction
*/
- public function &getDomains ( ) {
-
+ public function &getDomains()
+ {
return $this->_domains;
}
/**
* Get held realdoms.
*
- * @access public
* @return \Hoa\Realdom\Disjunction
*/
- public function &getHeld ( ) {
-
+ public function &getHeld()
+ {
return $this->getDomains();
}
/**
* Get variable name.
*
- * @access public
* @return string
*/
- public function getName ( ) {
-
+ public function getName()
+ {
return $this->_name;
}
/**
* Check if the variable is local (let) or not.
*
- * @access public
* @return bool
*/
- public function isLocal ( ) {
-
+ public function isLocal()
+ {
return $this->_local;
}
/**
* Get constraints.
*
- * @access public
* @return array
*/
- public function getConstraints ( ) {
-
+ public function getConstraints()
+ {
return $this->_constraints;
}
/**
* Get alias.
*
- * @access public
* @return \Hoa\Praspel\Model\Variable
*/
- public function getAlias ( ) {
-
+ public function getAlias()
+ {
return $this->_alias;
}
/**
* Get parent clause.
*
- * @access public
* @return \Hoa\Praspel\Model\Clause
*/
- public function getClause ( ) {
-
+ public function getClause()
+ {
return $this->_clause;
}
/**
* Accept a visitor.
*
- * @access public
* @param \Hoa\Visitor\Visit $visitor Visitor.
* @param mixed &$handle Handle (reference).
* @param mixed $eldnah Handle (no reference).
* @return mixed
*/
- public function accept ( \Hoa\Visitor\Visit $visitor,
- &$handle = null, $eldnah = null ) {
-
+ public function accept(
+ Visitor\Visit $visitor,
+ &$handle = null,
+ $eldnah = null
+ ) {
return $visitor->visit($this, $handle, $eldnah);
}
}
-}
-
-namespace {
-
/**
* Flex entity.
*/
-Hoa\Core\Consistency::flexEntity('Hoa\Praspel\Model\Variable\Variable');
-
-}
+Core\Consistency::flexEntity('Hoa\Praspel\Model\Variable\Variable');