aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2015-05-28 12:10:30 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2015-05-28 12:10:30 +0200
commit0fce3078006928700d7e65660d49f693dc4293d2 (patch)
tree03636cd45b0422fc7558ef9d8c380c30e13b9069
parentf7801604c0631304547eee00b68ce3174d40ccdc (diff)
downloadPraspel-0fce3078006928700d7e65660d49f693dc4293d2.zip
Praspel-0fce3078006928700d7e65660d49f693dc4293d2.tar.gz
Praspel-0fce3078006928700d7e65660d49f693dc4293d2.tar.bz2
Move to PSR-1-2 & drop PHP5.3 & `from`/`import`.
-rw-r--r--AssertionChecker/AssertionChecker.php149
-rw-r--r--AssertionChecker/Runtime.php470
-rw-r--r--Bin/Shell.php301
-rw-r--r--Exception/AssertionChecker.php23
-rw-r--r--Exception/Compiler.php23
-rw-r--r--Exception/Exception.php20
-rw-r--r--Exception/Failure/Exceptional.php23
-rw-r--r--Exception/Failure/Failure.php30
-rw-r--r--Exception/Failure/InternalPrecondition.php23
-rw-r--r--Exception/Failure/Invariant.php23
-rw-r--r--Exception/Failure/Postcondition.php23
-rw-r--r--Exception/Failure/Precondition.php23
-rw-r--r--Exception/Generic.php23
-rw-r--r--Exception/Group.php23
-rw-r--r--Exception/Interpreter.php23
-rw-r--r--Exception/Model.php23
-rw-r--r--Exception/Preambler.php23
-rw-r--r--Iterator/Coverage/Coverage.php62
-rw-r--r--Iterator/Coverage/Domain.php95
-rw-r--r--Iterator/Coverage/Structural.php255
-rw-r--r--Iterator/Sampler.php110
-rw-r--r--Iterator/WeakStack.php38
-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
-rw-r--r--Praspel.php97
-rw-r--r--Preambler/EncapsulationShunter.php130
-rw-r--r--Preambler/Handler.php95
-rw-r--r--Trace.php23
-rw-r--r--Visitor/Compiler.php350
-rw-r--r--Visitor/Interpreter.php350
-rw-r--r--Visitor/Praspel.php246
44 files changed, 1957 insertions, 2792 deletions
diff --git a/AssertionChecker/AssertionChecker.php b/AssertionChecker/AssertionChecker.php
index 746a6fd..90c7f2d 100644
--- a/AssertionChecker/AssertionChecker.php
+++ b/AssertionChecker/AssertionChecker.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,46 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\AssertionChecker;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Preambler\Handler
- */
--> import('Praspel.Preambler.Handler')
-
-/**
- * \Hoa\Praspel\Visitor\Praspel
- */
--> import('Praspel.Visitor.Praspel');
-
-}
-
-namespace Hoa\Praspel\AssertionChecker {
+use Hoa\Core;
+use Hoa\Praspel;
/**
* Class \Hoa\Praspel\AssertionChecker.
*
* Generic assertion checker.
*
- * @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 AssertionChecker {
-
+abstract class AssertionChecker
+{
/**
* Specification.
*
- * @var \Hoa\Praspel\Model\Specification object
+ * @var \Hoa\Praspel\Model\Specification
*/
protected $_specification = null;
/**
* Data of the specification.
*
- * @var \Hoa\Praspel array
+ * @var array
*/
protected $_data = null;
/**
* Whether we are able to automatically generate data.
*
- * @var \Hoa\Praspel bool
+ * @var bool
*/
protected $_generateData = false;
/**
* Callable to validate and verify.
*
- * @var \Hoa\Core\Consistency\Xcallable object
+ * @var \Hoa\Core\Consistency\Xcallable
*/
protected $_callable = null;
@@ -97,16 +82,16 @@ abstract class AssertionChecker {
/**
* Construct.
*
- * @access public
* @param \Hoa\Praspel\Model\Specification $specification Specification.
* @param \Hoa\Core\Consistency\Xcallable $callable Callable.
* @param bool $genrateData Generate data.
* @return void
*/
- public function __construct ( \Hoa\Praspel\Model\Specification $specification,
- \Hoa\Core\Consistency\Xcallable $callable,
- $generateData = false ) {
-
+ public function __construct(
+ Praspel\Model\Specification $specification,
+ Core\Consistency\Xcallable $callable,
+ $generateData = false
+ ) {
$this->setSpecification($specification);
$this->setCallable($callable);
$this->automaticallyGenerateData($generateData);
@@ -118,13 +103,12 @@ abstract class AssertionChecker {
* Preamble: put the system under test into a specific state in order to be
* able to execute the test.
*
- * @access public
* @param mixed $preamble Preamble callable.
* @return void
*/
- public function preamble ( $preamble ) {
-
- $preambler = new \Hoa\Praspel\Preambler\Handler($this->getCallable());
+ public function preamble($preamble)
+ {
+ $preambler = new Praspel\Preambler\Handler($this->getCallable());
$preamble($preambler);
$this->setCallable($preambler->__getCallable());
@@ -134,48 +118,47 @@ abstract class AssertionChecker {
/**
* Assertion checker.
*
- * @access public
* @return bool
- * @throw \Hoa\Praspel\Exception\Generic
- * @throw \Hoa\Praspel\Exception\Group
+ * @throws \Hoa\Praspel\Exception\Generic
+ * @throws \Hoa\Praspel\Exception\Group
*/
- abstract public function evaluate ( );
+ abstract public function evaluate();
/**
* Generate data.
* Isotropic random generation of data from the @requires clause.
*
- * @access public
* @param \Hoa\Praspel\Model\Specification $specification Specification.
* @return array
*/
- public static function generateData ( \Hoa\Praspel\Model\Specification $specification ) {
-
- $data = array();
+ public static function generateData(Praspel\Model\Specification $specification)
+ {
+ $data = [];
$behavior = $specification;
do {
-
- if(true === $behavior->clauseExists('requires'))
- foreach($behavior->getClause('requires') as $name => $variable)
+ if (true === $behavior->clauseExists('requires')) {
+ foreach ($behavior->getClause('requires') as $name => $variable) {
$data[$name] = $variable->sample();
+ }
+ }
- if(false === $behavior->clauseExists('behavior'))
+ if (false === $behavior->clauseExists('behavior')) {
break;
+ }
$behaviors = $behavior->getClause('behavior');
$count = count($behaviors);
$i = mt_rand(0, $count);
- if($i === $count) {
-
- if(true === $behavior->clauseExists('default'))
+ if ($i === $count) {
+ if (true === $behavior->clauseExists('default')) {
$behavior = $behavior->getClause('default');
- }
- else
+ }
+ } else {
$behavior = $behaviors->getNth($i);
-
- } while(true);
+ }
+ } while (true);
return $data;
}
@@ -183,12 +166,11 @@ abstract class AssertionChecker {
/**
* Set specification.
*
- * @access protected
* @param \Hoa\Praspel\Model\Specification $specification Specification.
* @return \Hoa\Praspel\Model\Specification
*/
- protected function setSpecification ( \Hoa\Praspel\Model\Specification $specification ) {
-
+ protected function setSpecification(Praspel\Model\Specification $specification)
+ {
$old = $this->_specification;
$this->_specification = $specification;
@@ -198,23 +180,21 @@ abstract class AssertionChecker {
/**
* Get specification.
*
- * @access public
* @return \Hoa\Praspel\Model\Specification
*/
- public function getSpecification ( ) {
-
+ public function getSpecification()
+ {
return $this->_specification;
}
/**
* Enable or disable the automatic data generation.
*
- * @access public
* @param bool $generateData Generate data or not.
* @return bool
*/
- public function automaticallyGenerateData ( $generateData ) {
-
+ public function automaticallyGenerateData($generateData)
+ {
$old = $this->_generateData;
$this->_generateData = $generateData;
@@ -224,23 +204,21 @@ abstract class AssertionChecker {
/**
* Whether we are able to automatically generate data.
*
- * @access public
* @return bool
*/
- public function canGenerateData ( ) {
-
+ public function canGenerateData()
+ {
return $this->_generateData;
}
/**
* Set data.
*
- * @access public
* @param array $data Data.
* @return array
*/
- public function setData ( Array $data ) {
-
+ public function setData(Array $data)
+ {
$old = $this->_data;
$this->_data = $data;
@@ -250,23 +228,21 @@ abstract class AssertionChecker {
/**
* Get data.
*
- * @access public
* @return array
*/
- public function getData ( ) {
-
+ public function getData()
+ {
return $this->_data;
}
/**
* Set callable.
*
- * @access protected
* @param \Hoa\Core\Consistency\Xcallable $callable Callable.
* @return \Hoa\Core\Consistency\Xcallable
*/
- protected function setCallable ( \Hoa\Core\Consistency\Xcallable $callable ) {
-
+ protected function setCallable(Core\Consistency\Xcallable $callable)
+ {
$old = $this->_callable;
$this->_callable = $callable;
@@ -276,36 +252,29 @@ abstract class AssertionChecker {
/**
* Get callable.
*
- * @access public
* @return \Hoa\Core\Consistency\Xcallable
*/
- public function getCallable ( ) {
-
+ public function getCallable()
+ {
return $this->_callable;
}
/**
* Get visitor Praspel.
*
- * @access protected
* @return \Hoa\Praspel\Visitor\Praspel
*/
- protected function getVisitorPraspel ( ) {
-
- if(null === $this->_visitorPraspel)
- $this->_visitorPraspel = new \Hoa\Praspel\Visitor\Praspel();
+ protected function getVisitorPraspel()
+ {
+ if (null === $this->_visitorPraspel) {
+ $this->_visitorPraspel = new Praspel\Visitor\Praspel();
+ }
return $this->_visitorPraspel;
}
}
-}
-
-namespace {
-
/**
* Flex entity.
*/
-Hoa\Core\Consistency::flexEntity('Hoa\Praspel\AssertionChecker\AssertionChecker');
-
-}
+Core\Consistency::flexEntity('Hoa\Praspel\AssertionChecker\AssertionChecker');
diff --git a/AssertionChecker/Runtime.php b/AssertionChecker/Runtime.php
index 19e563c..4e4504a 100644
--- a/AssertionChecker/Runtime.php
+++ b/AssertionChecker/Runtime.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,70 +34,24 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\AssertionChecker;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\AssertionChecker
- */
--> import('Praspel.Exception.AssertionChecker')
-
-/**
- * \Hoa\Praspel\Exception\Group
- */
--> import('Praspel.Exception.Group')
-
-/**
- * \Hoa\Praspel\Exception\Failure\Precondition
- */
--> import('Praspel.Exception.Failure.Precondition')
-
-/**
- * \Hoa\Praspel\Exception\Failure\Postcondition
- */
--> import('Praspel.Exception.Failure.Postcondition')
-
-/**
- * \Hoa\Praspel\Exception\Failure\Exceptional
- */
--> import('Praspel.Exception.Failure.Exceptional')
-
-/**
- * \Hoa\Praspel\Exception\Failure\Invariant
- */
--> import('Praspel.Exception.Failure.Invariant')
-
-/**
- * \Hoa\Praspel\Exception\Failure\InternalPrecondition
- */
--> import('Praspel.Exception.Failure.InternalPrecondition')
-
-/**
- * \Hoa\Praspel\AssertionChecker
- */
--> import('Praspel.AssertionChecker.~');
-
-}
-
-namespace Hoa\Praspel\AssertionChecker {
+use Hoa\Praspel;
/**
* Class \Hoa\Praspel\AssertionChecker\Runtime.
*
* Assertion checker: runtime (so-called RAC).
*
- * @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 Runtime extends AssertionChecker {
-
+class Runtime extends AssertionChecker
+{
/**
* Visitor Praspel.
*
- * @var \Hoa\Praspel\Visitor\Praspel object
+ * @var \Hoa\Praspel\Visitor\Praspel
*/
protected $_visitorPraspel = null;
@@ -106,36 +60,35 @@ class Runtime extends AssertionChecker {
/**
* Runtime assertion checker.
*
- * @access public
* @param \Hoa\Praspel\Trace $trace Trace.
* @return bool
- * @throw \Hoa\Praspel\Exception\AssertionChecker
- * @throw \Hoa\Praspel\Exception\Group
+ * @throws \Hoa\Praspel\Exception\AssertionChecker
+ * @throws \Hoa\Praspel\Exception\Group
*/
- public function evaluate ( &$trace = false ) {
-
+ public function evaluate(&$trace = false)
+ {
// Start.
- $registry = \Hoa\Praspel::getRegistry();
+ $registry = Praspel::getRegistry();
$verdict = true;
$callable = $this->getCallable();
$reflection = $callable->getReflection();
$specification = $this->getSpecification();
- $exceptions = new \Hoa\Praspel\Exception\Group(
+ $exceptions = new Praspel\Exception\Group(
'The Runtime Assertion Checker has detected failures for %s.',
- 0, $callable
+ 0,
+ $callable
);
$classname = null;
$isConstructor = false;
- if($reflection instanceof \ReflectionMethod) {
-
+ if ($reflection instanceof \ReflectionMethod) {
$reflection->setAccessible(true);
- if('__construct' === $reflection->getName())
+ if ('__construct' === $reflection->getName()) {
$isConstructor = true;
+ }
- if(false === $reflection->isStatic()) {
-
+ if (false === $reflection->isStatic()) {
$_callback = $callable->getValidCallback();
$_object = $_callback[0];
$specification->getImplicitVariable('this')->bindTo($_object);
@@ -144,20 +97,24 @@ class Runtime extends AssertionChecker {
$classname = $reflection->getDeclaringClass()->getName();
}
- if(false !== $trace && !($trace instanceof Trace))
- $trace = new \Hoa\Praspel\Trace();
+ if (false !== $trace && !($trace instanceof Trace)) {
+ $trace = new Praspel\Trace();
+ }
// Prepare data.
- if(null === $data = $this->getData())
- if(true === $this->canGenerateData()) {
-
+ if (null === $data = $this->getData()) {
+ if (true === $this->canGenerateData()) {
$data = static::generateData($specification);
$this->setData($data);
- }
- else
- throw new \Hoa\Praspel\Exception\AssertionChecker(
+ } else {
+ throw new Praspel\Exception\AssertionChecker(
'No data were given. The System Under Test %s needs data ' .
- 'to be executed.', 1, $callable);
+ 'to be executed.',
+ 1,
+ $callable
+ );
+ }
+ }
$arguments = $this->getArgumentData(
$reflection,
@@ -169,22 +126,23 @@ class Runtime extends AssertionChecker {
$invariant = $specification->getClause('invariant');
$attributes = $this->getAttributeData($callable);
- foreach($attributes as $name => $_) {
-
+ foreach ($attributes as $name => $_) {
$entryName = $classname . '::$' . $name;
- if(!isset($registry[$entryName]))
+ if (!isset($registry[$entryName])) {
continue;
+ }
$entry = $registry[$entryName];
- if(true === $entry->clauseExists('invariant'))
- foreach($entry->getClause('invariant') as $variable)
+ if (true === $entry->clauseExists('invariant')) {
+ foreach ($entry->getClause('invariant') as $variable) {
$invariant->addVariable($variable->getName(), $variable);
+ }
+ }
}
- if(false === $isConstructor) {
-
+ if (false === $isConstructor) {
$verdict &= $this->checkClause(
$invariant,
$attributes,
@@ -194,8 +152,9 @@ class Runtime extends AssertionChecker {
$trace
);
- if(0 < count($exceptions))
+ if (0 < count($exceptions)) {
throw $exceptions;
+ }
}
// Check requires and behaviors.
@@ -208,31 +167,33 @@ class Runtime extends AssertionChecker {
$trace
);
- if(0 < count($exceptions))
+ if (0 < count($exceptions)) {
throw $exceptions;
+ }
- $rootBehavior = $behavior instanceof \Hoa\Praspel\Model\Specification;
+ $rootBehavior = $behavior instanceof Praspel\Model\Specification;
$numberOfArguments = count($arguments);
- if($numberOfArguments < $numberOfRequiredArguments) {
-
- $exceptions[] = new \Hoa\Praspel\Exception\Failure\Precondition(
+ if ($numberOfArguments < $numberOfRequiredArguments) {
+ $exceptions[] = new Praspel\Exception\Failure\Precondition(
'Callable %s needs %d arguments; %d given.',
- 2, array($callable, $numberOfRequiredArguments, $numberOfArguments)
+ 2,
+ [$callable, $numberOfRequiredArguments, $numberOfArguments]
);
throw $exceptions;
}
- $_exceptions = true === $rootBehavior
- ? $exceptions
- : new \Hoa\Praspel\Exception\Group(
- 'Behavior %s is broken.',
- 3, $behavior->getIdentifier()
- );
+ $_exceptions =
+ true === $rootBehavior
+ ? $exceptions
+ : new Praspel\Exception\Group(
+ 'Behavior %s is broken.',
+ 3,
+ $behavior->getIdentifier()
+ );
try {
-
// Invoke.
$return = $this->invoke(
$callable,
@@ -243,8 +204,7 @@ class Runtime extends AssertionChecker {
$arguments['\result'] = $return;
// Check normal postcondition.
- if(true === $behavior->clauseExists('ensures')) {
-
+ if (true === $behavior->clauseExists('ensures')) {
$ensures = $behavior->getClause('ensures');
$verdict &= $this->checkClause(
$ensures,
@@ -255,53 +215,57 @@ class Runtime extends AssertionChecker {
$trace
);
}
- }
- catch ( \Hoa\Praspel\Exception $internalException ) {
-
- $_exceptions[] = new \Hoa\Praspel\Exception\Failure\InternalPrecondition(
+ } catch (Praspel\Exception $internalException) {
+ $_exceptions[] = new Praspel\Exception\Failure\InternalPrecondition(
'The System Under Test has broken an internal contract.',
- 4, null, $internalException);
- }
- catch ( \Exception $exception ) {
-
+ 4,
+ null,
+ $internalException
+ );
+ } catch (\Exception $exception) {
$arguments['\result'] = $exception;
// Check exceptional postcondition.
- if(true === $behavior->clauseExists('throwable')) {
-
+ if (true === $behavior->clauseExists('throwable')) {
$throwable = $behavior->getClause('throwable');
$verdict &= $this->checkExceptionalClause(
$throwable,
$arguments
);
- if(false == $verdict)
- $_exceptions[] = new \Hoa\Praspel\Exception\Failure\Exceptional(
+ if (false == $verdict) {
+ $_exceptions[] = new Praspel\Exception\Failure\Exceptional(
'The exception %s has been unexpectedly thrown.',
- 5, get_class($arguments['\result']), $exception);
- }
- else {
-
+ 5,
+ get_class($arguments['\result']),
+ $exception
+ );
+ }
+ } else {
$verdict &= false;
- $_exceptions[] = new \Hoa\Praspel\Exception\Failure\Exceptional(
+ $_exceptions[] = new Praspel\Exception\Failure\Exceptional(
'The System Under Test cannot terminate exceptionally ' .
'because no exceptional postcondition has been specified ' .
'(there is no @throwable clause).',
- 6, array(), $exception);
+ 6,
+ [],
+ $exception
+ );
}
}
- if( 0 < count($_exceptions)
- && false === $rootBehavior) {
-
+ if (0 < count($_exceptions) &&
+ false === $rootBehavior) {
$_behavior = $behavior;
- while( (null !== $_behavior = $_behavior->getParent())
- && !($_behavior instanceof \Hoa\Praspel\Model\Specification)) {
-
- $handle = new \Hoa\Praspel\Exception\Group(
+ while (
+ (null !== $_behavior = $_behavior->getParent()) &&
+ !($_behavior instanceof Praspel\Model\Specification)
+ ) {
+ $handle = new Praspel\Exception\Group(
'Behavior %s is broken.',
- 7, $_behavior->getIdentifier()
+ 7,
+ $_behavior->getIdentifier()
);
$handle[] = $_exceptions;
$_exceptions = $handle;
@@ -310,8 +274,9 @@ class Runtime extends AssertionChecker {
$exceptions[] = $_exceptions;
}
- if(0 < count($exceptions))
+ if (0 < count($exceptions)) {
throw $exceptions;
+ }
// Check invariant.
$attributes = $this->getAttributeData($callable);
@@ -324,8 +289,9 @@ class Runtime extends AssertionChecker {
$trace
);
- if(0 < count($exceptions))
+ if (0 < count($exceptions)) {
throw $exceptions;
+ }
return (bool) $verdict;
}
@@ -333,7 +299,6 @@ class Runtime extends AssertionChecker {
/**
* Get argument data.
*
- * @access protected
* @param \ReflectionFunctionAbstract $reflection Reflection.
* @param array &$data Data.
* @param int $numberOfRequiredArguments Number of
@@ -341,29 +306,28 @@ class Runtime extends AssertionChecker {
* arguments.
* @return array
*/
- protected function getArgumentData ( \ReflectionFunctionAbstract $reflection,
- Array &$data,
- &$numberOfRequiredArguments ) {
-
- $arguments = array();
+ protected function getArgumentData(
+ \ReflectionFunctionAbstract $reflection,
+ Array &$data,
+ &$numberOfRequiredArguments
+ ) {
+ $arguments = [];
$numberOfRequiredArguments = 0;
- foreach($reflection->getParameters() as $parameter) {
-
+ foreach ($reflection->getParameters() as $parameter) {
$name = $parameter->getName();
- if(true === array_key_exists($name, $data)) {
-
+ if (true === array_key_exists($name, $data)) {
$arguments[$name] = &$data[$name];
- if(false === $parameter->isOptional())
+ if (false === $parameter->isOptional()) {
++$numberOfRequiredArguments;
+ }
continue;
}
- if(false === $parameter->isOptional()) {
-
+ if (false === $parameter->isOptional()) {
++$numberOfRequiredArguments;
// Let the error be caught by a @requires clause.
@@ -379,27 +343,27 @@ class Runtime extends AssertionChecker {
/**
* Get attribute data.
*
- * @access protected
* @param \Hoa\Core\Consistency\Xcallable $callable Callable.
* @return array
*/
- protected function getAttributeData ( \Hoa\Core\Consistency\Xcallable $callable ) {
-
+ protected function getAttributeData(Core\Consistency\Xcallable $callable)
+ {
$callback = $callable->getValidCallback();
- if($callback instanceof \Closure)
- return array();
+ if ($callback instanceof \Closure) {
+ return [];
+ }
$object = $callback[0];
- if(!is_object($object))
- return array();
+ if (!is_object($object)) {
+ return [];
+ }
$reflectionObject = new \ReflectionObject($object);
- $attributes = array();
-
- foreach($reflectionObject->getProperties() as $property) {
+ $attributes = [];
+ foreach ($reflectionObject->getProperties() as $property) {
$property->setAccessible(true);
$attributes[$property->getName()] = $property->getValue($object);
}
@@ -418,18 +382,19 @@ class Runtime extends AssertionChecker {
* it is a
* constructor.
* @return mixed
- * @throw \Exception
+ * @throws \Exception
*/
- protected function invoke ( \Hoa\Core\Consistency\Xcallable &$callable,
- \ReflectionFunctionAbstract &$reflection,
- Array &$arguments,
- $isConstructor ) {
-
- if($reflection instanceof \ReflectionFunction)
+ protected function invoke(
+ Core\Consistency\Xcallable &$callable,
+ \ReflectionFunctionAbstract &$reflection,
+ Array &$arguments,
+ $isConstructor
+ ) {
+ if ($reflection instanceof \ReflectionFunction) {
return $reflection->invokeArgs($arguments);
+ }
- if(false === $isConstructor) {
-
+ if (false === $isConstructor) {
$_callback = $callable->getValidCallback();
$_object = $_callback[0];
@@ -447,7 +412,6 @@ class Runtime extends AssertionChecker {
/**
* Check behavior clauses.
*
- * @access protected
* @param \Hoa\Praspel\Model\Behavior &$behavior Behavior clause.
* @param array &$data Data.
* @param \Hoa\Praspel\Exception\Group $exceptions Exceptions group.
@@ -455,19 +419,19 @@ class Runtime extends AssertionChecker {
* variable.
* @param \Hoa\Praspel\Trace $trace Trace.
* @return bool
- * @throw \Hoa\Praspel\Exception
+ * @throws \Hoa\Praspel\Exception
*/
- protected function checkBehavior ( \Hoa\Praspel\Model\Behavior &$behavior,
- Array &$data,
- \Hoa\Praspel\Exception\Group $exceptions,
- $assign = false,
- $trace = false ) {
-
+ protected function checkBehavior(
+ Praspel\Model\Behavior &$behavior,
+ Array &$data,
+ Praspel\Exception\Group $exceptions,
+ $assign = false,
+ $trace = false
+ ) {
$verdict = true;
// Check precondition.
- if(true === $behavior->clauseExists('requires')) {
-
+ if (true === $behavior->clauseExists('requires')) {
$requires = $behavior->getClause('requires');
$verdict = $this->checkClause(
$requires,
@@ -478,29 +442,28 @@ class Runtime extends AssertionChecker {
$trace
);
- if(false === $verdict)
+ if (false === $verdict) {
return false;
+ }
}
// Check behaviors.
- if(true === $behavior->clauseExists('behavior')) {
-
+ if (true === $behavior->clauseExists('behavior')) {
$_verdict = false;
$behaviors = $behavior->getClause('behavior');
$exceptions->beginTransaction();
- foreach($behaviors as $_behavior) {
-
- $_exceptions = new \Hoa\Praspel\Exception\Group(
+ foreach ($behaviors as $_behavior) {
+ $_exceptions = new Praspel\Exception\Group(
'Behavior %s is broken.',
- 8, $_behavior->getIdentifier()
+ 8,
+ $_behavior->getIdentifier()
);
$_trace = null;
- if(!empty($trace)) {
-
- $_trace = new \Hoa\Praspel\Model\Behavior($trace);
+ if (!empty($trace)) {
+ $_trace = new Praspel\Model\Behavior($trace);
$_trace->setIdentifier($_behavior->getIdentifier());
}
@@ -512,10 +475,10 @@ class Runtime extends AssertionChecker {
$_trace
);
- if(true === $_verdict) {
-
- if(!empty($trace))
+ if (true === $_verdict) {
+ if (!empty($trace)) {
$trace->addClause($_trace);
+ }
break;
}
@@ -524,19 +487,15 @@ class Runtime extends AssertionChecker {
unset($_trace);
}
- if(false === $_verdict) {
-
- if(true === $behavior->clauseExists('default')) {
-
+ if (false === $_verdict) {
+ if (true === $behavior->clauseExists('default')) {
$exceptions->rollbackTransaction();
$_verdict = true;
$behavior = $behavior->getClause('default');
- }
- else
+ } else {
$exceptions->commitTransaction();
- }
- else {
-
+ }
+ } else {
$exceptions->rollbackTransaction();
$behavior = $_behavior;
}
@@ -550,7 +509,6 @@ class Runtime extends AssertionChecker {
/**
* Check a clause.
*
- * @access protected
* @param \Hoa\Praspel\Model\Declaration $clause Clause.
* @param array &$data Data.
* @param \Hoa\Praspel\Exception\Group $exceptions Exceptions group.
@@ -560,28 +518,30 @@ class Runtime extends AssertionChecker {
* variable.
* @param \Hoa\Praspel\Trace $trace Trace.
* @return bool
- * @throw \Hoa\Praspel\Exception
+ * @throws \Hoa\Praspel\Exception
*/
- protected function checkClause ( \Hoa\Praspel\Model\Declaration $clause,
- Array &$data,
- \Hoa\Praspel\Exception\Group $exceptions,
- $exception,
- $assign = false,
- $trace = false ) {
-
+ protected function checkClause(
+ Praspel\Model\Declaration $clause,
+ Array &$data,
+ \Hoa\Praspel\Exception\Group $exceptions,
+ $exception,
+ $assign = false,
+ $trace = false
+ ) {
$verdict = true;
$traceClause = null;
- if(!empty($trace))
+ if (!empty($trace)) {
$traceClause = clone $clause;
+ }
- foreach($clause as $name => $variable) {
-
- if(false === array_key_exists($name, $data)) {
-
+ foreach ($clause as $name => $variable) {
+ if (false === array_key_exists($name, $data)) {
$exceptions[] = new $exception(
'Variable %s in @%s is required and has no value.',
- 9, array($name, $clause->getName()));
+ 9,
+ [$name, $clause->getName()]
+ );
continue;
}
@@ -590,45 +550,43 @@ class Runtime extends AssertionChecker {
$_verdict = false;
$traceVariable = null;
- if(null !== $traceClause) {
-
+ if (null !== $traceClause) {
$traceVariable = clone $variable;
$traceVariableDomains = $traceVariable->getDomains();
}
$i = 0;
- foreach($variable->getDomains() as $realdom) {
-
- if(false === $_verdict && true === $realdom->predicate($datum))
+ foreach ($variable->getDomains() as $realdom) {
+ if (false === $_verdict && true === $realdom->predicate($datum)) {
$_verdict = true;
- elseif(null !== $traceClause)
+ } elseif (null !== $traceClause) {
unset($traceVariableDomains[$i--]);
+ }
++$i;
}
- if(false === $_verdict) {
-
- if(null !== $traceClause)
+ if (false === $_verdict) {
+ if (null !== $traceClause) {
unset($traceClause[$name]);
+ }
$exceptions[] = new $exception(
'Variable %s does not verify the constraint @%s %s.',
10,
- array(
+ [
$name,
$clause->getName(),
$this->getVisitorPraspel()->visit($variable)
- ));
- }
- else {
-
- if(true === $assign)
+ ]
+ );
+ } else {
+ if (true === $assign) {
$variable->setValue($datum);
+ }
- if(null !== $traceClause) {
-
+ if (null !== $traceClause) {
unset($traceClause[$name]);
$traceClause->addVariable($name, $traceVariable);
}
@@ -637,15 +595,13 @@ class Runtime extends AssertionChecker {
$verdict &= $_verdict;
}
- $predicateEvaluator = function ( $__hoa_arguments, $__hoa_code ) {
-
+ $predicateEvaluator = function ($__hoa_arguments, $__hoa_code) {
extract($__hoa_arguments);
return true == eval('return ' . $__hoa_code . ';');
};
- foreach($clause->getPredicates() as $predicate) {
-
+ foreach ($clause->getPredicates() as $predicate) {
$_predicate = $predicate;
preg_match_all(
@@ -654,42 +610,52 @@ class Runtime extends AssertionChecker {
$matches
);
- $predicateArguments = array();
+ $predicateArguments = [];
- foreach($matches[1] as $variable)
- if(true === array_key_exists($variable, $data))
+ foreach ($matches[1] as $variable) {
+ if (true === array_key_exists($variable, $data)) {
$predicateArguments[$variable] = $data[$variable];
+ }
+ }
- if(false !== strpos($_predicate, '\result')) {
-
- if( !($clause instanceof \Hoa\Praspel\Model\Ensures)
- && !($clause instanceof \Hoa\Praspel\Model\Throwable)) {
-
+ if (false !== strpos($_predicate, '\result')) {
+ if (!($clause instanceof Praspel\Model\Ensures) &&
+ !($clause instanceof Praspel\Model\Throwable)) {
$verdict &= false;
$exceptions[] = new $exception(
'Illegal \result in the following predicate: %s.',
- 11, $predicate);
+ 11,
+ $predicate
+ );
continue;
}
$placeholder = '__hoa_praspel_' . uniqid();
- $_predicate = str_replace('\\result', '$' . $placeholder, $_predicate);
+ $_predicate = str_replace(
+ '\\result',
+ '$' . $placeholder,
+ $_predicate
+ );
$predicateArguments[$placeholder] = $data['\result'];
}
$_verdict = $predicateEvaluator($predicateArguments, $_predicate);
- if(false === $_verdict)
+ if (false === $_verdict) {
$exceptions[] = new $exception(
'Violation of the following predicate: %s.',
- 11, $predicate);
+ 11,
+ $predicate
+ );
+ }
$verdict &= $_verdict;
}
- if(!empty($trace))
+ if (!empty($trace)) {
$trace->addClause($traceClause);
+ }
return (bool) $verdict;
}
@@ -697,36 +663,34 @@ class Runtime extends AssertionChecker {
/**
* Check an exceptional clause.
*
- * @access protected
* @param \Hoa\Praspel\Model\Throwable $clause Clause.
* @param array &$data Data.
* @return bool
- * @throw \Hoa\Praspel\Exception
+ * @throws \Hoa\Praspel\Exception
*/
- protected function checkExceptionalClause ( \Hoa\Praspel\Model\Throwable $clause,
- Array &$data ) {
-
+ protected function checkExceptionalClause(
+ Praspel\Model\Throwable $clause,
+ Array &$data
+ ) {
$verdict = false;
- foreach($clause as $identifier) {
-
+ foreach ($clause as $identifier) {
$_exception = $clause[$identifier];
$instanceName = $_exception->getInstanceName();
- if($data['\result'] instanceof $instanceName) {
-
+ if ($data['\result'] instanceof $instanceName) {
$verdict = true;
+
break;
}
- foreach((array) $_exception->getDisjunction() as $_identifier) {
-
+ foreach ((array) $_exception->getDisjunction() as $_identifier) {
$__exception = $clause[$_identifier];
$_instanceName = $__exception->getInstanceName();
- if($exception instanceof $_instanceName) {
-
+ if ($exception instanceof $_instanceName) {
$verdict = true;
+
break;
}
}
@@ -735,5 +699,3 @@ class Runtime extends AssertionChecker {
return $verdict;
}
}
-
-}
diff --git a/Bin/Shell.php b/Bin/Shell.php
index 8b73dc6..8a338ec 100644
--- a/Bin/Shell.php
+++ b/Bin/Shell.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,224 +34,187 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Bin;
-from('Hoa')
-
-/**
- * \Hoa\File\Read
- */
--> import('File.Read')
-
-/**
- * \Hoa\Compiler\Llk
- */
--> import('Compiler.Llk.~')
-
-/**
- * \Hoa\Praspel\Visitor\Interpreter
- */
--> import('Praspel.Visitor.Interpreter')
-
-/**
- * \Hoa\Praspel\Visitor\Compiler
- */
--> import('Praspel.Visitor.Compiler')
-
-/**
- * \Hoa\Realdom
- */
--> import('Realdom.~')
-
-/**
- * \Hoa\Math\Sampler\Random
- */
--> import('Math.Sampler.Random')
-
-/**
- * \Hoa\Console\Cursor
- */
--> import('Console.Cursor')
-
-/**
- * \Hoa\Console\Readline
- */
--> import('Console.Readline.~')
-
-/**
- * \Hoa\Console\Readline\Autocompleter\Word
- */
--> import('Console.Readline.Autocompleter.Word');
-
-}
-
-namespace Hoa\Praspel\Bin {
+use Hoa\Compiler;
+use Hoa\Console;
+use Hoa\Core;
+use Hoa\File;
+use Hoa\Math;
+use Hoa\Praspel;
+use Hoa\Realdom;
/**
* Class \Hoa\Praspel\Bin\Shell.
*
* Interactive Praspel shell.
*
- * @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 Shell extends \Hoa\Console\Dispatcher\Kit {
-
+class Shell extends Console\Dispatcher\Kit
+{
/**
* Options description.
*
- * @var \Hoa\Praspel\Bin\Shell array
+ * @var array
*/
- protected $options = array(
- array('help', \Hoa\Console\GetOption::NO_ARGUMENT, 'h'),
- array('help', \Hoa\Console\GetOption::NO_ARGUMENT, '?')
- );
+ protected $options = [
+ ['help', Console\GetOption::NO_ARGUMENT, 'h'],
+ ['help', Console\GetOption::NO_ARGUMENT, '?']
+ ];
/**
* The entry method.
*
- * @access public
* @return int
*/
- public function main ( ) {
+ public function main()
+ {
+ while (false !== $c = $this->getOption($v)) {
+ switch ($c) {
+ case 'h':
+ case '?':
+ return $this->usage();
- while(false !== $c = $this->getOption($v)) switch($c) {
+ case '__ambiguous':
+ $this->resolveOptionAmbiguity($v);
- case 'h':
- case '?':
- return $this->usage();
- break;
-
- case '__ambiguous':
- $this->resolveOptionAmbiguity($v);
- break;
+ break;
+ }
}
- \Hoa\Realdom::setDefaultSampler(new \Hoa\Math\Sampler\Random());
+ Realdom::setDefaultSampler(new Math\Sampler\Random());
- $compiler = \Hoa\Compiler\Llk::load(
- new \Hoa\File\Read('hoa://Library/Praspel/Grammar.pp')
+ $compiler = Compiler\Llk::load(
+ new File\Read('hoa://Library/Praspel/Grammar.pp')
);
- $interpreter = new \Hoa\Praspel\Visitor\Interpreter();
- $dump = new \Hoa\Praspel\Visitor\Compiler();
+ $interpreter = new Praspel\Visitor\Interpreter();
+ $dump = new Praspel\Visitor\Compiler();
$interpreter->visit($compiler->parse('@requires;'));
- $words = array();
+ $words = [];
from('Hoathis or Hoa')
- -> foreachImport('Realdom.*', function ( $classname ) use ( &$words ) {
-
+ -> foreachImport('Realdom.*', function ($classname) use (&$words) {
$class = new \ReflectionClass($classname);
- if($class->isSubclassOf('\Hoa\Realdom'))
+ if ($class->isSubclassOf('\Hoa\Realdom')) {
$words[] = $classname::NAME;
+ }
return;
});
- $readline = new \Hoa\Console\Readline();
+ $readline = new Console\Readline();
$readline->setAutocompleter(
- new \Hoa\Console\Readline\Autocompleter\Word($words)
+ new Console\Readline\Autocompleter\Word($words)
);
$expression = '.h';
- do { try {
-
- if('.' === $expression[0])
- @list($expression, $tail) = explode(' ', $expression);
-
- switch($expression) {
-
- case '.h':
- case '.help':
- echo 'Usage:', "\n",
- ' .h[elp] to print this help;', "\n",
- ' .c[lear] to clear the screen;', "\n",
- ' .v[ariables] to print all variables;', "\n",
- ' .s[ample] to sample a value of a variable;', "\n",
- ' .u[nset] to unset a variable;', "\n",
- ' .d[ump] to dump the tree of the expression;', "\n",
- ' .q[uit] to quit.', "\n";
- break;
-
- case '.c':
- case '.clear':
- \Hoa\Console\Cursor::clear('↕');
- break;
-
- case '.v':
- case '.variables':
- foreach($interpreter->getClause() as $variable)
- echo $variable->getName(), ': ',
- $variable->getHeld()->toPraspel(), "\n";
- break;
-
- case '.s':
- case '.sample':
- if(null === $tail) {
-
- echo 'You must precise a variable name.', "\n";
- break;
+ do {
+ try {
+ if ('.' === $expression[0]) {
+ @list($expression, $tail) = explode(' ', $expression);
}
- $_clause = $interpreter->getClause();
+ switch ($expression) {
+ case '.h':
+ case '.help':
+ echo
+ 'Usage:', "\n",
+ ' .h[elp] to print this help;', "\n",
+ ' .c[lear] to clear the screen;', "\n",
+ ' .v[ariables] to print all variables;', "\n",
+ ' .s[ample] to sample a value of a variable;', "\n",
+ ' .u[nset] to unset a variable;', "\n",
+ ' .d[ump] to dump the tree of the expression;', "\n",
+ ' .q[uit] to quit.', "\n";
- if(!isset($_clause[$tail])) {
+ break;
- echo 'Variable ', $tail, ' does not exist.', "\n";
- break;
- }
+ case '.c':
+ case '.clear':
+ Console\Cursor::clear('↕');
- $_variable = $_clause[$tail];
- var_export($_variable->sample());
- echo "\n";
- $_variable->reset();
- break;
+ break;
- case '.u':
- case '.unset':
- if(null === $tail) {
+ case '.v':
+ case '.variables':
+ foreach ($interpreter->getClause() as $variable) {
+ echo
+ $variable->getName(), ': ',
+ $variable->getHeld()->toPraspel(), "\n";
+ }
- echo 'You must precise a variable name.', "\n";
- break;
- }
+ break;
- $_clause = $interpreter->getClause();
- unset($_clause[$tail]);
- break;
+ case '.s':
+ case '.sample':
+ if (null === $tail) {
+ echo 'You must precise a variable name.', "\n";
- case '.d':
- case '.dump':
- echo $dump->visit($interpreter->getRoot());
- break;
+ break;
+ }
- case '.q':
- case '.quit':
- break 2;
+ $_clause = $interpreter->getClause();
- default:
- if(null === $expression)
- break;
+ if (!isset($_clause[$tail])) {
+ echo 'Variable ', $tail, ' does not exist.', "\n";
- $interpreter->visit(
- $compiler->parse($expression, 'expression')
- );
- break;
+ break;
+ }
- } }
+ $_variable = $_clause[$tail];
+ var_export($_variable->sample());
+ echo "\n";
+ $_variable->reset();
- catch ( \Exception $e ) {
+ break;
- echo $e->getMessage(), "\n";
- }
+ case '.u':
+ case '.unset':
+ if (null === $tail) {
+ echo 'You must precise a variable name.', "\n";
- echo "\n";
+ break;
+ }
- } while(false !== $expression = $readline->readLine('> '));
+ $_clause = $interpreter->getClause();
+ unset($_clause[$tail]);
+
+ break;
+
+ case '.d':
+ case '.dump':
+ echo $dump->visit($interpreter->getRoot());
+
+ break;
+
+ case '.q':
+ case '.quit':
+ break 2;
+
+ default:
+ if (null === $expression) {
+ break;
+ }
+
+ $interpreter->visit(
+ $compiler->parse($expression, 'expression')
+ );
+
+ break;
+
+ }
+ } catch (\Exception $e) {
+ echo $e->getMessage(), "\n";
+ }
+
+ echo "\n";
+ } while (false !== $expression = $readline->readLine('> '));
return;
}
@@ -259,22 +222,20 @@ class Shell extends \Hoa\Console\Dispatcher\Kit {
/**
* The command usage.
*
- * @access public
* @return int
*/
- public function usage ( ) {
-
- echo 'Usage : praspel:shell <options> [expression]', "\n",
- 'Options :', "\n",
- $this->makeUsageOptionsList(array(
- 'help' => 'This help.'
- )), "\n";
+ public function usage()
+ {
+ echo
+ 'Usage : praspel:shell <options> [expression]', "\n",
+ 'Options :', "\n",
+ $this->makeUsageOptionsList([
+ 'help' => 'This help.'
+ ]), "\n";
return;
}
}
-}
-
__halt_compiler();
Interactive Praspel shell.
diff --git a/Exception/AssertionChecker.php b/Exception/AssertionChecker.php
index 29c4346..0842efe 100644
--- a/Exception/AssertionChecker.php
+++ b/Exception/AssertionChecker.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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Generic
- */
--> import('Praspel.Exception.Generic');
-
-}
-
-namespace Hoa\Praspel\Exception {
+namespace Hoa\Praspel\Exception;
/**
* Class \Hoa\Praspel\Exception\AssertionChecker.
*
* Extending the \Hoa\Praspel\Exception\Generic class.
*
- * @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 AssertionChecker extends Generic { }
-
+class AssertionChecker extends Generic
+{
}
diff --git a/Exception/Compiler.php b/Exception/Compiler.php
index 14382ad..e49e4d0 100644
--- a/Exception/Compiler.php
+++ b/Exception/Compiler.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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Generic
- */
--> import('Praspel.Exception.Generic');
-
-}
-
-namespace Hoa\Praspel\Exception {
+namespace Hoa\Praspel\Exception;
/**
* Class \Hoa\Praspel\Exception\Compiler.
*
* Extending the \Hoa\Praspel\Exception\Generic class.
*
- * @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 Compiler extends Generic { }
-
+class Compiler extends Generic
+{
}
diff --git a/Exception/Exception.php b/Exception/Exception.php
index dcece9c..ee837d8 100644
--- a/Exception/Exception.php
+++ b/Exception/Exception.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,27 +34,23 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace Hoa\Praspel\Exception {
+namespace Hoa\Praspel\Exception;
+
+use Hoa\Core;
/**
* Interface \Hoa\Praspel\Exception.
*
* Interface representing Hoa\Praspel exceptions.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
-interface Exception { }
-
+interface Exception
+{
}
-namespace {
-
/**
* Flex entity.
*/
-Hoa\Core\Consistency::flexEntity('Hoa\Praspel\Exception\Exception');
-
-}
+Core\Consistency::flexEntity('Hoa\Praspel\Exception\Exception');
diff --git a/Exception/Failure/Exceptional.php b/Exception/Failure/Exceptional.php
index 7debe44..586b111 100644
--- a/Exception/Failure/Exceptional.php
+++ b/Exception/Failure/Exceptional.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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Failure
- */
--> import('Praspel.Exception.Failure.~');
-
-}
-
-namespace Hoa\Praspel\Exception\Failure {
+namespace Hoa\Praspel\Exception\Failure;
/**
* Class \Hoa\Praspel\Exception\Failure\Exceptional.
*
* Extending the \Hoa\Praspel\Exception\Failure class.
*
- * @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 Exceptional extends Failure { }
-
+class Exceptional extends Failure
+{
}
diff --git a/Exception/Failure/Failure.php b/Exception/Failure/Failure.php
index f77c057..d26815e 100644
--- a/Exception/Failure/Failure.php
+++ b/Exception/Failure/Failure.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,38 +34,24 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Exception\Failure;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\AssertionChecker
- */
--> import('Praspel.Exception.AssertionChecker');
-
-}
-
-namespace Hoa\Praspel\Exception\Failure {
+use Hoa\Core;
+use Hoa\Praspel;
/**
* Class \Hoa\Praspel\Exception\Failure.
*
* Extending the \Hoa\Praspel\Exception\AssertionChecker class.
*
- * @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 Failure extends \Hoa\Praspel\Exception\AssertionChecker { }
-
+class Failure extends Praspel\Exception\AssertionChecker
+{
}
-namespace {
-
/**
* Flex entity.
*/
-Hoa\Core\Consistency::flexEntity('Hoa\Praspel\Exception\Failure\Failure');
-
-}
+Core\Consistency::flexEntity('Hoa\Praspel\Exception\Failure\Failure');
diff --git a/Exception/Failure/InternalPrecondition.php b/Exception/Failure/InternalPrecondition.php
index 9c9665b..786b3d8 100644
--- a/Exception/Failure/InternalPrecondition.php
+++ b/Exception/Failure/InternalPrecondition.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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Failure
- */
--> import('Praspel.Exception.Failure.~');
-
-}
-
-namespace Hoa\Praspel\Exception\Failure {
+namespace Hoa\Praspel\Exception\Failure;
/**
* Class \Hoa\Praspel\Exception\Failure\InternalPrecondition.
*
* Extending the \Hoa\Praspel\Exception\Failure class.
*
- * @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 InternalPrecondition extends Failure { }
-
+class InternalPrecondition extends Failure
+{
}
diff --git a/Exception/Failure/Invariant.php b/Exception/Failure/Invariant.php
index 02c0776..b383727 100644
--- a/Exception/Failure/Invariant.php
+++ b/Exception/Failure/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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Failure
- */
--> import('Praspel.Exception.Failure.~');
-
-}
-
-namespace Hoa\Praspel\Exception\Failure {
+namespace Hoa\Praspel\Exception\Failure;
/**
* Class \Hoa\Praspel\Exception\Failure\Invariant.
*
* Extending the \Hoa\Praspel\Exception\Failure class.
*
- * @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 Failure { }
-
+class Invariant extends Failure
+{
}
diff --git a/Exception/Failure/Postcondition.php b/Exception/Failure/Postcondition.php
index d9c4032..10e55a6 100644
--- a/Exception/Failure/Postcondition.php
+++ b/Exception/Failure/Postcondition.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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Failure
- */
--> import('Praspel.Exception.Failure.~');
-
-}
-
-namespace Hoa\Praspel\Exception\Failure {
+namespace Hoa\Praspel\Exception\Failure;
/**
* Class \Hoa\Praspel\Exception\Failure\Postcondition.
*
* Extending the \Hoa\Praspel\Exception\Failure class.
*
- * @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 Postcondition extends Failure { }
-
+class Postcondition extends Failure
+{
}
diff --git a/Exception/Failure/Precondition.php b/Exception/Failure/Precondition.php
index e9ea825..8b70421 100644
--- a/Exception/Failure/Precondition.php
+++ b/Exception/Failure/Precondition.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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Failure
- */
--> import('Praspel.Exception.Failure.~');
-
-}
-
-namespace Hoa\Praspel\Exception\Failure {
+namespace Hoa\Praspel\Exception\Failure;
/**
* Class \Hoa\Praspel\Exception\Failure\Precondition.
*
* Extending the \Hoa\Praspel\Exception\Failure class.
*
- * @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 Precondition extends Failure { }
-
+class Precondition extends Failure
+{
}
diff --git a/Exception/Generic.php b/Exception/Generic.php
index dbc3b58..803888e 100644
--- a/Exception/Generic.php
+++ b/Exception/Generic.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,29 +34,18 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Exception;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception
- */
--> import('Praspel.Exception.~');
-
-}
-
-namespace Hoa\Praspel\Exception {
+use Hoa\Core;
/**
* Class \Hoa\Praspel\Exception\Generic.
*
* Extending the \Hoa\Core\Exception class.
*
- * @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 Generic extends \Hoa\Core\Exception implements Exception { }
-
+class Generic extends Core\Exception implements Exception
+{
}
diff --git a/Exception/Group.php b/Exception/Group.php
index c8208fc..4ce8de3 100644
--- a/Exception/Group.php
+++ b/Exception/Group.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,29 +34,18 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Exception;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception
- */
--> import('Praspel.Exception.~');
-
-}
-
-namespace Hoa\Praspel\Exception {
+use Hoa\Core;
/**
* Class \Hoa\Praspel\Exception\Generic.
*
* Extending the \Hoa\Core\Exception\Group class.
*
- * @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 Group extends \Hoa\Core\Exception\Group implements Exception { }
-
+class Group extends Core\Exception\Group implements Exception
+{
}
diff --git a/Exception/Interpreter.php b/Exception/Interpreter.php
index 48c71fe..02f031a 100644
--- a/Exception/Interpreter.php
+++ b/Exception/Interpreter.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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Generic
- */
--> import('Praspel.Exception.Generic');
-
-}
-
-namespace Hoa\Praspel\Exception {
+namespace Hoa\Praspel\Exception;
/**
* Class \Hoa\Praspel\Exception\Interpreter.
*
* Extending the \Hoa\Praspel\Exception\Generic class.
*
- * @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 Interpreter extends Generic { }
-
+class Interpreter extends Generic
+{
}
diff --git a/Exception/Model.php b/Exception/Model.php
index 8c5c793..3c7e838 100644
--- a/Exception/Model.php
+++ b/Exception/Model.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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Generic
- */
--> import('Praspel.Exception.Generic');
-
-}
-
-namespace Hoa\Praspel\Exception {
+namespace Hoa\Praspel\Exception;
/**
* Class \Hoa\Praspel\Exception\Model.
*
* Extending the \Hoa\Praspel\Exception\Generic class.
*
- * @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 Model extends Generic { }
-
+class Model extends Generic
+{
}
diff --git a/Exception/Preambler.php b/Exception/Preambler.php
index b8b442e..7b65cd8 100644
--- a/Exception/Preambler.php
+++ b/Exception/Preambler.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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Generic
- */
--> import('Praspel.Exception.Generic');
-
-}
-
-namespace Hoa\Praspel\Exception {
+namespace Hoa\Praspel\Exception;
/**
* Class \Hoa\Praspel\Exception\Preambler.
*
* Extending the \Hoa\Praspel\Exception\Generic class.
*
- * @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 Preambler extends Generic { }
-
+class Preambler extends Generic
+{
}
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;
}
}
-
-}
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');
diff --git a/Praspel.php b/Praspel.php
index 7b047ed..bcfd444 100644
--- a/Praspel.php
+++ b/Praspel.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,26 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Trace
- */
--> import('Praspel.Trace')
-
-/**
- * \Hoa\Praspel\Visitor\Interpreter
- */
--> import('Praspel.Visitor.Interpreter')
-
-/**
- * \Hoa\Compiler\Llk
- */
--> import('Compiler.Llk.~')
-
-/**
- * \Hoa\File\Read
- */
--> import('File.Read');
-
-}
-
-namespace Hoa\Praspel {
+use Hoa\Compiler;
+use Hoa\Core;
+use Hoa\File;
/**
* Class \Hoa\Praspel\Praspel.
*
* Take a specification + data and validate/verify a callable.
*
- * @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 Praspel {
-
+class Praspel
+{
/**
* Registry of all contracts.
*
- * @var \ArrayObject object
+ * @var \ArrayObject
*/
protected static $_registry = null;
@@ -86,28 +62,30 @@ class Praspel {
/**
* Short interpreter.
*
- * @access public
* @param string $praspel Praspel.
* @param string $bindToClass Classname to bind.
* @return \Hoa\Praspel\Model\Clause
*/
- public static function interprete ( $praspel, $bindToClass = null ) {
-
+ public static function interprete($praspel, $bindToClass = null)
+ {
static $_compiler = null;
static $_interpreter = null;
- if(null === $_compiler)
- $_compiler = \Hoa\Compiler\Llk::load(
- new \Hoa\File\Read('hoa://Library/Praspel/Grammar.pp')
+ if (null === $_compiler) {
+ $_compiler = Compiler\Llk::load(
+ new File\Read('hoa://Library/Praspel/Grammar.pp')
);
+ }
- if(null === $_interpreter)
+ if (null === $_interpreter) {
$_interpreter = new Visitor\Interpreter();
+ }
$ast = $_compiler->parse($praspel);
- if(null !== $bindToClass)
+ if (null !== $bindToClass) {
$_interpreter->bindToClass($bindToClass);
+ }
return $_interpreter->visit($ast);
}
@@ -115,21 +93,22 @@ class Praspel {
/**
* Extract Praspel (as a string) from a comment.
*
- * @access public
* @param string $comment Comment.
* @return string
*/
- public static function extractFromComment ( $comment ) {
-
+ public static function extractFromComment($comment)
+ {
$i = preg_match('#/\*(.*?)\*/#s', $comment, $matches);
- if(0 === $i)
+ if (0 === $i) {
return '';
+ }
$i = preg_match_all('#^[\s\*]*\s*\*\s?([^\n]*)$#m', $matches[1], $maatches);
- if(0 === $i)
+ if (0 === $i) {
return '';
+ }
return trim(implode("\n", $maatches[1]));
}
@@ -137,38 +116,32 @@ class Praspel {
/**
* Get registry of all contracts.
*
- * @access public
* @return \ArrayObject
*/
- public static function getRegistry ( ) {
-
- if(null === static::$_registry)
+ public static function getRegistry()
+ {
+ if (null === static::$_registry) {
static::$_registry = new \ArrayObject();
+ }
return static::$_registry;
}
}
-}
-
-namespace {
-
/**
* Flex entity.
*/
-Hoa\Core\Consistency::flexEntity('Hoa\Praspel\Praspel');
+Core\Consistency::flexEntity('Hoa\Praspel\Praspel');
/**
* Alias of \Hoa\Praspel::interprete().
*
- * @access public
* @param string $praspel Praspel
* @return \Hoa\Praspel\Model\Clause
*/
-if(!function_exists('praspel')) {
-function praspel ( $praspel ) {
-
- return \Hoa\Praspel::interprete($praspel);
-}}
-
+if (!function_exists('praspel')) {
+ function praspel($praspel)
+ {
+ return Praspel::interprete($praspel);
+ }
}
diff --git a/Preambler/EncapsulationShunter.php b/Preambler/EncapsulationShunter.php
index dde863b..b3ebe16 100644
--- a/Preambler/EncapsulationShunter.php
+++ b/Preambler/EncapsulationShunter.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,28 +34,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Preambler;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Preambler
- */
--> import('Praspel.Exception.Preambler')
-
-/**
- * \Hoa\Praspel\AssertionChecker
- */
--> import('Praspel.AssertionChecker.~')
-
-/**
- * \Hoa\Praspel
- */
--> import('Praspel.~');
-
-}
-
-namespace Hoa\Praspel\Preambler {
+use Hoa\Praspel;
/**
* Class \Hoa\Praspel\Preambler\EncapsulationShunter.
@@ -63,19 +44,17 @@ namespace Hoa\Praspel\Preambler {
* Shunt encapsulation: instanciate a class and set its state by using
* invariants and not methods calls.
*
- * @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 EncapsulationShunter {
-
+class EncapsulationShunter
+{
/**
* Assertion checker.
* Needed to generate data for the constructor (when we need to instanciate
* an object).
*
- * @var \Hoa\Praspel\AssertionChecker object
+ * @var \Hoa\Praspel\AssertionChecker
*/
protected $_assertionChecker = null;
@@ -84,15 +63,15 @@ class EncapsulationShunter {
/**
* Constructor.
*
- * @access public
* @param \Hoa\Praspel\AssertionChecker $assertionChecker Assertion
* checker.
* @return void
*/
- public function __construct ( \Hoa\Praspel\AssertionChecker $assertionChecker = null ) {
-
- if(null !== $assertionChecker)
+ public function __construct(Praspel\AssertionChecker $assertionChecker = null)
+ {
+ if (null !== $assertionChecker) {
$this->setAssertionChecker($assertionChecker);
+ }
return;
}
@@ -100,58 +79,56 @@ class EncapsulationShunter {
/**
* Invoke the encapsulation shunter.
*
- * @access public
* @param \Hoa\Praspel\Preambler\Handler $preambler Preambler.
* @return void
- * @throw \Hoa\Praspel\Exception\Preambler
+ * @throws \Hoa\Praspel\Exception\Preambler
*/
- public function __invoke ( Handler $preambler ) {
-
+ public function __invoke(Handler $preambler)
+ {
$callable = $preambler->__getCallable();
$reflection = $callable->getReflection();
- $registry = \Hoa\Praspel::getRegistry();
-
- if($reflection instanceof \ReflectionClass) {
+ $registry = Praspel::getRegistry();
+ if ($reflection instanceof \ReflectionClass) {
$_object = $reflection->newInstance();
$preambler->__setCallable(xcallable($_object, '__construct'));
- }
- elseif(!($reflection instanceof \ReflectionMethod))
- throw new \Hoa\Praspel\Exception\Preambler(
- 'The callable must be a class and a (dynamic) method name.', 0);
- else {
-
+ } elseif (!($reflection instanceof \ReflectionMethod)) {
+ throw new Praspel\Exception\Preambler(
+ 'The callable must be a class and a (dynamic) method name.',
+ 0
+ );
+ } else {
$callback = $callable->getValidCallback();
- if(!is_object($callback[0])) {
-
+ if (!is_object($callback[0])) {
$reflectionClass = $reflection->getDeclaringClass();
$_reflectionClass = $reflectionClass;
- while(
- ( null === $constructor = $_reflectionClass->getConstructor())
- && (false !== $_reflectionClass = $_reflectionClass->getParentClass())
+ while (
+ (null === $constructor = $_reflectionClass->getConstructor()) &&
+ (false !== $_reflectionClass = $_reflectionClass->getParentClass())
);
- if(null === $constructor)
+ if (null === $constructor) {
$_object = $reflectionClass->newInstance();
- else {
-
+ } else {
$className = $_reflectionClass->getName();
$id = $className . '::__construct';
- if(!isset($registry[$id]))
- $registry[$id] = \Hoa\Praspel::interprete(
- \Hoa\Praspel::extractFromComment(
+ if (!isset($registry[$id])) {
+ $registry[$id] = Praspel::interprete(
+ Praspel::extractFromComment(
$constructor->getDocComment()
),
$className
);
+ }
$assertionChecker = $this->getAssertionChecker();
- if(null === $assertionChecker)
+ if (null === $assertionChecker) {
$assertionChecker = '\Hoa\Praspel\AssertionChecker';
+ }
$arguments = $assertionChecker::generateData($registry[$id]);
$_object = $reflectionClass->newInstanceArgs($arguments);
@@ -165,30 +142,35 @@ class EncapsulationShunter {
$className = $reflectionObject->getName();
$properties = $reflectionObject->getProperties();
- foreach($properties as $property) {
-
+ foreach ($properties as $property) {
$propertyName = $property->getName();
$id = $className . '::$' . $propertyName;
- if(false === isset($registry[$id]))
- $registry[$id] = \Hoa\Praspel::interprete(
- \Hoa\Praspel::extractFromComment(
+ if (false === isset($registry[$id])) {
+ $registry[$id] = Praspel::interprete(
+ Praspel::extractFromComment(
$property->getDocComment()
),
$className
);
+ }
$specification = $registry[$id];
- if(false === $specification->clauseExists('invariant'))
- throw new \Hoa\Praspel\Exception\Preambler(
+ if (false === $specification->clauseExists('invariant')) {
+ throw new Praspel\Exception\Preambler(
'Cannot generate a value from %s because it has no ' .
'@invariant clause.',
- 1, $id);
+ 1,
+ $id
+ );
+ }
- $preambler->$propertyName = $specification->getClause('invariant')
- ->getVariable($propertyName)
- ->sample();
+ $preambler->$propertyName =
+ $specification
+ ->getClause('invariant')
+ ->getVariable($propertyName)
+ ->sample();
}
return;
@@ -197,13 +179,12 @@ class EncapsulationShunter {
/**
* Set an assertion checker.
*
- * @access public
* @param \Hoa\Praspel\AssertionChecker $assertionChecker Assertion
* checker.
* @return \Hoa\Praspel\AssertionChecker
*/
- public function setAssertionChecker ( \Hoa\Praspel\AssertionChecker $assertionChecker ) {
-
+ public function setAssertionChecker(Praspel\AssertionChecker $assertionChecker)
+ {
$old = $this->_assertionChecker;
$this->_assertionChecker = $assertionChecker;
@@ -213,13 +194,10 @@ class EncapsulationShunter {
/**
* Get the assertion checker.
*
- * @access public
* @return \Hoa\Praspel\AssertionChecker
*/
- public function getAssertionChecker ( ) {
-
+ public function getAssertionChecker()
+ {
return $this->_assertionChecker;
}
}
-
-}
diff --git a/Preambler/Handler.php b/Preambler/Handler.php
index 05fa016..64877fa 100644
--- a/Preambler/Handler.php
+++ b/Preambler/Handler.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,35 +34,25 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Preambler;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Preambler
- */
--> import('Praspel.Exception.Preambler');
-
-}
-
-namespace Hoa\Praspel\Preambler {
+use Hoa\Core;
+use Hoa\Praspel;
/**
* Class \Hoa\Praspel\Preambler\Handler.
*
* Handle a class and ease to run a preamble.
*
- * @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 Handler {
-
+class Handler
+{
/**
* Callable to validate and verify.
*
- * @var \Hoa\Core\Consistency\Xcallable object
+ * @var \Hoa\Core\Consistency\Xcallable
*/
protected $__callable = null;
@@ -71,12 +61,11 @@ class Handler {
/**
* Construct.
*
- * @access public
* @param \Hoa\Core\Consistency\Xcallable $callable Callable.
* @return void
*/
- public function __construct ( \Hoa\Core\Consistency\Xcallable $callable ) {
-
+ public function __construct(Core\Consistency\Xcallable $callable)
+ {
$this->__setCallable($callable);
return;
@@ -85,23 +74,25 @@ class Handler {
/**
* Get reflection object.
*
- * @access public
* @param object &$object Object.
* @return \ReflectionObject
- * @throw \Hoa\Praspel\Exception\Preambler
+ * @throws \Hoa\Praspel\Exception\Preambler
*/
- public function __getReflectionObject ( &$object ) {
-
+ public function __getReflectionObject(&$object)
+ {
static $_out = null;
static $_object = null;
- if(null === $_out) {
-
+ if (null === $_out) {
$callback = $this->__getCallable()->getValidCallback();
- if(!is_object($callback[0]))
- throw new \Hoa\Praspel\Exception\Preambler(
- 'Callable %s is not an object.', 0, $this->__getCallable());
+ if (!is_object($callback[0])) {
+ throw new Praspel\Exception\Preambler(
+ 'Callable %s is not an object.',
+ 0,
+ $this->__getCallable()
+ );
+ }
$_object = $callback[0];
$_out = new \ReflectionObject($_object);
@@ -115,20 +106,22 @@ class Handler {
/**
* Set an attribute.
*
- * @access public
* @param string $name Name.
* @param mixed $value Value.
* @return \Hoa\Praspel\Preambler\Handler
- * @throw \Hoa\Praspel\Exception\Preambler
+ * @throws \Hoa\Praspel\Exception\Preambler
*/
- public function __set ( $name, $value ) {
-
+ public function __set($name, $value)
+ {
$reflectionObject = $this->__getReflectionObject($object);
- if(false === $reflectionObject->hasProperty($name))
- throw new \Hoa\Praspel\Exception\Preambler(
+ if (false === $reflectionObject->hasProperty($name)) {
+ throw new Praspel\Exception\Preambler(
'Attribute %s on object %s does not exist, cannot set it.',
- 1, array($name, $reflectionObject->getName()));
+ 1,
+ [$name, $reflectionObject->getName()]
+ );
+ }
$attribute = $reflectionObject->getProperty($name);
$attribute->setAccessible(true);
@@ -140,19 +133,21 @@ class Handler {
/**
* Get an attribute.
*
- * @access public
* @param string $name Name.
* @return mixed
- * @throw \Hoa\Praspel\Exception\Preambler
+ * @throws \Hoa\Praspel\Exception\Preambler
*/
- public function __get ( $name ) {
-
+ public function __get($name)
+ {
$reflectionObject = $this->__getReflectionObject($object);
- if(false === $reflectionObject->hasProperty($name))
- throw new \Hoa\Praspel\Exception\Preambler(
+ if (false === $reflectionObject->hasProperty($name)) {
+ throw new Praspel\Exception\Preambler(
'Attribute %s on object %s does not exist, cannot get it.',
- 2, array($name, $reflectionObject->getName()));
+ 2,
+ [$name, $reflectionObject->getName()]
+ );
+ }
$attribute = $reflectionObject->getProperty($name);
$attribute->setAccessible(true);
@@ -163,12 +158,11 @@ class Handler {
/**
* Set callable.
*
- * @access public
* @param \Hoa\Core\Consistency\Xcallable $callable Callable.
* @return \Hoa\Core\Consistency\Xcallable
*/
- public function __setCallable ( \Hoa\Core\Consistency\Xcallable $callable ) {
-
+ public function __setCallable(Core\Consistency\Xcallable $callable)
+ {
$old = $this->__callable;
$this->__callable = $callable;
@@ -178,13 +172,10 @@ class Handler {
/**
* Get callable.
*
- * @access public
* @return \Hoa\Core\Consistency\Xcallable
*/
- public function __getCallable ( ) {
-
+ public function __getCallable()
+ {
return $this->__callable;
}
}
-
-}
diff --git a/Trace.php b/Trace.php
index 6b3ea6f..3c277a2 100644
--- a/Trace.php
+++ b/Trace.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,29 +34,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Model\Specification
- */
--> import('Praspel.Model.Specification');
-
-}
-
-namespace Hoa\Praspel {
+namespace Hoa\Praspel;
/**
* Class \Hoa\Praspel\Trace.
*
* A trace is a derivated specification.
*
- * @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 Trace extends Model\Specification { }
-
+class Trace extends Model\Specification
+{
}
diff --git a/Visitor/Compiler.php b/Visitor/Compiler.php
index eb033ce..ebf4192 100644
--- a/Visitor/Compiler.php
+++ b/Visitor/Compiler.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,246 +34,240 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Visitor;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Compiler
- */
--> import('Praspel.Exception.Compiler')
-
-/**
- * \Hoa\Visitor\Visit
- */
--> import('Visitor.Visit');
-
-}
-
-namespace Hoa\Praspel\Visitor {
+use Hoa\Praspel;
+use Hoa\Realdom;
+use Hoa\Visitor;
/**
* Class \Hoa\Praspel\Visitor\Compiler.
*
* Compile the model to PHP code.
*
- * @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 Compiler implements \Hoa\Visitor\Visit {
-
+class Compiler implements Visitor\Visit
+{
/**
* Visit an element.
*
- * @access public
* @param \Hoa\Visitor\Element $element Element to visit.
* @param mixed &$handle Handle (reference).
* @param mixed $eldnah Handle (not reference).
* @return mixed
*/
- public function visit ( \Hoa\Visitor\Element $element,
- &$handle = null, $eldnah = null ) {
-
+ public function visit(
+ Visitor\Element $element,
+ &$handle = null,
+ $eldnah = null
+ ) {
$out = null;
// Hoa\Praspel.
- if($element instanceof \Hoa\Praspel\Model\Specification) {
-
+ if ($element instanceof Praspel\Model\Specification) {
$variable = '$' . $element->getId();
$out = $variable . ' = new \Hoa\Praspel\Model\Specification();' . "\n";
- foreach($element::getAllowedClauses() as $clause)
- if(true === $element->clauseExists($clause))
+ foreach ($element::getAllowedClauses() as $clause) {
+ if (true === $element->clauseExists($clause)) {
$out .= $element->getClause($clause)->accept(
$this,
$handle,
$eldnah
);
- }
- elseif($element instanceof \Hoa\Praspel\Model\Is) {
-
+ }
+ }
+ } elseif ($element instanceof Praspel\Model\Is) {
$variable = '$' . $element->getParent()->getId();
- $out = "\n" .
- $variable . '->getClause(\'is\')->setProperty(' .
- $element->getProperty() .
- ');' . "\n";
- }
- elseif($element instanceof \Hoa\Praspel\Model\Declaration) {
-
+ $out =
+ "\n" .
+ $variable . '->getClause(\'is\')->setProperty(' .
+ $element->getProperty() .
+ ');' . "\n";
+ } elseif ($element instanceof Praspel\Model\Declaration) {
$variable = '$' . ($eldnah ?: $element->getId());
- $out = "\n" .
- $variable . ' = $' . $element->getParent()->getId() .
- '->getClause(\'' . $element->getName() . '\');' . "\n";
+ $out =
+ "\n" .
+ $variable . ' = $' . $element->getParent()->getId() .
+ '->getClause(\'' . $element->getName() . '\');' . "\n";
- foreach($element->getLocalVariables() as $var)
+ foreach ($element->getLocalVariables() as $var) {
$out .= $var->accept($this, $handle, $eldnah);
+ }
- foreach($element->getPredicates() as $predicate)
+ foreach ($element->getPredicates() as $predicate) {
$out .= $variable . '->predicate(\'' . $predicate . '\');' . "\n";
- }
- elseif($element instanceof \Hoa\Praspel\Model\Variable) {
-
+ }
+ } elseif ($element instanceof Praspel\Model\Variable) {
$variable = '$' . ($eldnah ?: $element->getClause()->getId());
$name = $element->getName();
$start = $variable . '[\'' . $name . '\']';
- if(true === $element->isLocal())
+ if (true === $element->isLocal()) {
$out .= $variable . '->let[\'' . $name . '\']';
- else
+ } else {
$out .= $start;
+ }
- if(null !== $alias = $element->getAlias())
+ if (null !== $alias = $element->getAlias()) {
$out .= '->domainof(\'' . $alias . '\');' . "\n";
- else
- $out .= '->in = ' .
- $element->getDomains()->accept($this, $handle, $eldnah) .
- ';' . "\n";
+ } else {
+ $out .=
+ '->in = ' .
+ $element->getDomains()->accept($this, $handle, $eldnah) .
+ ';' . "\n";
+ }
$constraints = $element->getConstraints();
- if(isset($constraints['is']))
- $out .= $start . '->is(\'' .
- implode('\', \'', $constraints['is']) . '\');' .
- "\n";
+ if (isset($constraints['is'])) {
+ $out .=
+ $start . '->is(\'' .
+ implode('\', \'', $constraints['is']) . '\');' .
+ "\n";
+ }
- if(isset($constraints['contains']))
- foreach($constraints['contains'] as $contains)
+ if (isset($constraints['contains'])) {
+ foreach ($constraints['contains'] as $contains) {
$out .= $start . '->contains(' . $contains . ');' . "\n";
+ }
+ }
- if(isset($constraints['key']))
- foreach($constraints['key'] as $pairs)
- $out .= $start . '->key(' . $pairs[0] . ')->in = ' .
- $pairs[1] . ';' . "\n";
- }
- elseif($element instanceof \Hoa\Praspel\Model\Throwable) {
-
+ if (isset($constraints['key'])) {
+ foreach ($constraints['key'] as $pairs) {
+ $out .=
+ $start . '->key(' . $pairs[0] . ')->in = ' .
+ $pairs[1] . ';' . "\n";
+ }
+ }
+ } elseif ($element instanceof Praspel\Model\Throwable) {
$parent = '$' . $element->getParent()->getId();
$_variable = $element->getId();
$variable = '$' . $_variable;
- $out = "\n" .
- $variable . ' = ' . $parent .
- '->getClause(\'throwable\');' . "\n";
-
- foreach($element as $identifier) {
+ $out =
+ "\n" .
+ $variable . ' = ' . $parent .
+ '->getClause(\'throwable\');' . "\n";
+ foreach ($element as $identifier) {
$exception = $element[$identifier];
$start = $variable . '[\'' . $identifier . '\']';
- $out .= $start . ' = \'' . $exception->getInstanceName() .
- '\';' . "\n";
-
- if(false === $element->isDisjointed()) {
-
- if(null !== $with = $element->getWith()) {
+ $out .= $start . ' = \'' . $exception->getInstanceName() . '\';' . "\n";
+ if (false === $element->isDisjointed()) {
+ if (null !== $with = $element->getWith()) {
$temp = $_variable . '_' . $identifier . '_with';
- $out .= '$' . $temp . ' = ' .
- $variable . '->newWith();' . "\n";
+ $out .=
+ '$' . $temp . ' = ' .
+ $variable . '->newWith();' . "\n";
- foreach($with->getLocalVariables() as $var)
+ foreach ($with->getLocalVariables() as $var) {
$out .= $var->accept($this, $handle, $temp);
+ }
- foreach($with->getPredicates() as $predicate)
- $out .= '$' . $temp . '->predicate(\'' . $predicate .
- '\');' . "\n";
+ foreach ($with->getPredicates() as $predicate) {
+ $out .=
+ '$' . $temp . '->predicate(\'' . $predicate .
+ '\');' . "\n";
+ }
$out .= $start . '->setWith($' . $temp . ');' . "\n";
}
+ } else {
+ $out .=
+ $start . '->disjunctionWith(\'' .
+ $exception->getDisjunction() . '\');' . "\n";
}
- else
- $out .= $start . '->disjunctionWith(\'' .
- $exception->getDisjunction() . '\');' . "\n";
}
- }
- elseif($element instanceof \Hoa\Praspel\Model\DefaultBehavior) {
-
- $out = "\n" .
- '$' . $element->getId() . ' = $' .
- $element->getParent()->getId() .
- '->getClause(\'default\')' . "\n";
-
- foreach($element::getAllowedClauses() as $clause)
- if(true === $element->clauseExists($clause))
+ } elseif ($element instanceof Praspel\Model\DefaultBehavior) {
+ $out =
+ "\n" .
+ '$' . $element->getId() . ' = $' .
+ $element->getParent()->getId() .
+ '->getClause(\'default\')' . "\n";
+
+ foreach ($element::getAllowedClauses() as $clause) {
+ if (true === $element->clauseExists($clause)) {
$out .= $element->getClause($clause)->accept(
$this,
$handle,
$eldnah
);
- }
- elseif($element instanceof \Hoa\Praspel\Model\Behavior) {
-
- $out = "\n" .
- '$' . $element->getId() . ' = $' .
- $element->getParent()->getId() .
- '->getClause(\'behavior\')' .
- '->get(\'' . $element->getIdentifier() . '\');' . "\n";
-
- foreach($element::getAllowedClauses() as $clause)
- if(true === $element->clauseExists($clause))
+ }
+ }
+ } elseif ($element instanceof Praspel\Model\Behavior) {
+ $out =
+ "\n" .
+ '$' . $element->getId() . ' = $' .
+ $element->getParent()->getId() .
+ '->getClause(\'behavior\')' .
+ '->get(\'' . $element->getIdentifier() . '\');' . "\n";
+
+ foreach ($element::getAllowedClauses() as $clause) {
+ if (true === $element->clauseExists($clause)) {
$out .= $element->getClause($clause)->accept(
$this,
$handle,
$eldnah
);
- }
- elseif($element instanceof \Hoa\Praspel\Model\Description) {
-
+ }
+ }
+ } elseif ($element instanceof Praspel\Model\Description) {
$parent = '$' . $element->getParent()->getId();
$variable = '$' . $element->getId();
- $out = "\n" .
- $variable . ' = ' . $parent .
- '->getClause(\'description\');' . "\n";
-
- foreach($element as $example)
- $out .= $variable . '[] = \'' .
- preg_replace('#(?<!\\\)\'#', '\\\'', $example) .
- '\';' . "\n";
- }
- elseif($element instanceof \Hoa\Praspel\Model\Collection)
- foreach($element as $el)
+ $out =
+ "\n" .
+ $variable . ' = ' . $parent .
+ '->getClause(\'description\');' . "\n";
+
+ foreach ($element as $example) {
+ $out .=
+ $variable . '[] = \'' .
+ preg_replace('#(?<!\\\)\'#', '\\\'', $example) .
+ '\';' . "\n";
+ }
+ } elseif ($element instanceof Praspel\Model\Collection) {
+ foreach ($element as $el) {
$out .= $el->accept($this, $handle, $eldnah);
+ }
+ }
// Hoa\Realdom.
- elseif($element instanceof \Hoa\Realdom\Disjunction) {
-
+ elseif ($element instanceof Realdom\Disjunction) {
$realdoms = $element->getUnflattenedRealdoms();
- if(!empty($realdoms)) {
-
- $oout = array();
+ if (!empty($realdoms)) {
+ $oout = [];
- foreach($realdoms as $realdom) {
-
- if($realdom instanceof \Hoa\Realdom\IRealdom\Constant)
- $oout[] = 'const(' .
- $realdom->accept($this, $handle, $eldnah) .
- ')';
- else
+ foreach ($realdoms as $realdom) {
+ if ($realdom instanceof Realdom\IRealdom\Constant) {
+ $oout[] =
+ 'const(' .
+ $realdom->accept($this, $handle, $eldnah) .
+ ')';
+ } else {
$oout[] = $realdom->accept($this, $handle, $eldnah);
+ }
}
$out .= 'realdom()->' . implode('->or->', $oout);
}
- }
- elseif($element instanceof \Hoa\Realdom) {
-
- if($element instanceof \Hoa\Realdom\IRealdom\Constant) {
-
- if($element instanceof \Hoa\Realdom\_Array) {
-
- $oout = array();
-
- foreach($element['pairs'] as $pair) {
+ } elseif ($element instanceof Realdom) {
+ if ($element instanceof Realdom\IRealdom\Constant) {
+ if ($element instanceof Realdom\_Array) {
+ $oout = [];
+ foreach ($element['pairs'] as $pair) {
$_oout = null;
- foreach($pair as $_pair) {
-
- if(null !== $_oout)
+ foreach ($pair as $_pair) {
+ if (null !== $_oout) {
$_oout .= ', ';
+ }
$_oout .= $_pair->accept($this, $handle, $eldnah);
}
@@ -282,47 +276,47 @@ class Compiler implements \Hoa\Visitor\Visit {
}
$out .= 'array(' . implode(', ', $oout) . ')';
- }
- else
+ } else {
$out .= $element->getConstantRepresentation();
- }
- else {
-
- $oout = array();
+ }
+ } else {
+ $oout = [];
- foreach($element->getArguments() as $argument)
+ foreach ($element->getArguments() as $argument) {
$oout[] = $argument->accept($this, $handle, $eldnah);
+ }
- $out .= $element->getName() .
- '(' . implode(', ', $oout) . ')';
+ $out .=
+ $element->getName() .
+ '(' . implode(', ', $oout) . ')';
}
- }
- elseif($element instanceof \Hoa\Realdom\Crate\Constant) {
-
+ } elseif ($element instanceof Realdom\Crate\Constant) {
$holder = $element->getHolder();
$praspel = $element->getPraspelRepresentation();
- $out .= '$' . $element->getDeclaration()->getId() .
- '[\'' . $praspel() . '\']';
- }
- elseif($element instanceof \Hoa\Realdom\Crate\Variable) {
-
+ $out .=
+ '$' . $element->getDeclaration()->getId() .
+ '[\'' . $praspel() . '\']';
+ } elseif ($element instanceof Realdom\Crate\Variable) {
$holder = $element->getVariable();
- if($holder instanceof \Hoa\Praspel\Model\Variable\Implicit)
- $out .= 'variable($' . $holder->getClause()->getId() .
- '->getImplicitVariable(\'' . $holder->getName() .
- '\'))';
- else
- $out .= 'variable($' . $holder->getClause()->getId() .
- '->getVariable(\'' . $holder->getName() . '\', true))';
+ if ($holder instanceof Praspel\Model\Variable\Implicit) {
+ $out .=
+ 'variable($' . $holder->getClause()->getId() .
+ '->getImplicitVariable(\'' . $holder->getName() .
+ '\'))';
+ } else {
+ $out .=
+ 'variable($' . $holder->getClause()->getId() .
+ '->getVariable(\'' . $holder->getName() . '\', true))';
+ }
+ } else {
+ throw new Praspel\Exception\Compiler(
+ '%s is not yet implemented.',
+ 0,
+ get_class($element)
+ );
}
- else
- throw new \Hoa\Praspel\Exception\Compiler(
- '%s is not yet implemented.', 0, get_class($element));
-
return $out;
}
}
-
-}
diff --git a/Visitor/Interpreter.php b/Visitor/Interpreter.php
index 3c00144..e12b20c 100644
--- a/Visitor/Interpreter.php
+++ b/Visitor/Interpreter.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,71 +34,55 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Visitor;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Interpreter
- */
--> import('Praspel.Exception.Interpreter')
-
-/**
- * \Hoa\Praspel\Model\Specification
- */
--> import('Praspel.Model.Specification')
+use Hoa\Praspel;
+use Hoa\Realdom;
+use Hoa\String;
+use Hoa\Visitor;
-/**
- * \Hoa\Visitor\Visit
- */
--> import('Visitor.Visit')
+from('Hoa')
/**
- * \Hoa\String
+ * \Hoa\Realdom\Disjunction
*/
--> import('String.~');
-
-}
-
-namespace Hoa\Praspel\Visitor {
+-> import('Realdom.Disjunction', true);
/**
* Class \Hoa\Praspel\Visitor\Interpreter.
*
* Compile Praspel to model.
*
- * @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 Interpreter implements \Hoa\Visitor\Visit {
-
+class Interpreter implements Visitor\Visit
+{
/**
* Root.
*
- * @var \Hoa\Praspel\Model\Specification object
+ * @var \Hoa\Praspel\Model\Specification
*/
protected $_root = null;
/**
* Current clause.
*
- * @var \Hoa\Praspel\Model\Clause object
+ * @var \Hoa\Praspel\Model\Clause
*/
protected $_clause = null;
/**
* Current object.
*
- * @var \Hoa\Praspel\Model object
+ * @var \Hoa\Praspel\Model
*/
protected $_current = null;
/**
* Classname to bind to the specification.
*
- * @var \Hoa\Praspel\Visitor\Interpreter string
+ * @var string
*/
protected $_classnameToBind = null;
@@ -107,53 +91,59 @@ class Interpreter implements \Hoa\Visitor\Visit {
/**
* Visit an element.
*
- * @access public
* @param \Hoa\Visitor\Element $element Element to visit.
* @param mixed &$handle Handle (reference).
* @param mixed $eldnah Handle (not reference).
* @return mixed
- * @throw \Hoa\Praspel\Exception\Interpreter
+ * @throws \Hoa\Praspel\Exception\Interpreter
*/
- public function visit ( \Hoa\Visitor\Element $element,
- &$handle = null, $eldnah = null ) {
-
+ public function visit(
+ Visitor\Element $element,
+ &$handle = null,
+ $eldnah = null
+ ) {
$id = $element->getId();
- switch($id) {
-
+ switch ($id) {
case '#specification':
- $this->_clause = $this->_current
- = $this->_root
- = new \Hoa\Praspel\Model\Specification();
+ $this->_clause =
+ $this->_current =
+ $this->_root =
+ new Praspel\Model\Specification();
- if(null !== $classname = $this->getBindedClass())
+ if (null !== $classname = $this->getBindedClass()) {
$this->_root->bindToClass($classname);
+ }
- foreach($element->getChildren() as $child)
+ foreach ($element->getChildren() as $child) {
$child->accept($this, $handle, $eldnah);
+ }
return $this->_root;
- break;
case '#is':
$this->_clause = $this->_root->getClause('is');
- foreach($element->getChildren() as $child)
+ foreach ($element->getChildren() as $child) {
$this->_clause->addProperty(
$this->_clause->getPropertyValue(
$child->accept($this, $handle, $eldnah)
)
);
- break;
+ }
+
+ break;
case '#requires':
case '#ensures':
case '#invariant':
$this->_clause = $this->_current->getClause(substr($id, 1));
- foreach($element->getChildren() as $child)
+ foreach ($element->getChildren() as $child) {
$child->accept($this, $handle, $eldnah);
- break;
+ }
+
+ break;
case '#behavior':
$children = $element->getChildren();
@@ -161,38 +151,44 @@ class Interpreter implements \Hoa\Visitor\Visit {
$identifier = $child0->accept($this, $handle, false);
$previous = $this->_current;
- $this->_clause = $this->_current
- = $this->_current
- ->getClause('behavior')
- ->get($identifier);
+ $this->_clause =
+ $this->_current =
+ $this
+ ->_current
+ ->getClause('behavior')
+ ->get($identifier);
- foreach($children as $child)
+ foreach ($children as $child) {
$child->accept($this, $handle, $eldnah);
+ }
$this->_current = $previous;
- break;
+
+ break;
case '#default':
$children = $element->getChildren();
$previous = $this->_current;
- $this->_clause = $this->_current
- = $this->_current
- ->getClause('default');
+ $this->_clause =
+ $this->_current =
+ $this
+ ->_current
+ ->getClause('default');
- foreach($children as $child)
+ foreach ($children as $child) {
$child->accept($this, $handle, $eldnah);
+ }
$this->_current = $previous;
- break;
+
+ break;
case '#throwable':
$this->_clause = $this->_current->getClause('throwable');
$identifier = null;
- foreach($element->getChildren() as $child) {
-
- switch($child->getId()) {
-
+ foreach ($element->getChildren() as $child) {
+ switch ($child->getId()) {
case '#exception_identifier':
$_identifier = $child->getChild(1)->accept(
$this,
@@ -207,27 +203,32 @@ class Interpreter implements \Hoa\Visitor\Visit {
$this->_clause[$_identifier] = $_instanceof;
- if(null === $identifier)
+ if (null === $identifier) {
$identifier = $_identifier;
- else
+ } else {
$this->_clause[$_identifier]->disjunctionWith(
$identifier
);
- break;
+ }
+
+ break;
case '#exception_with':
$old = $this->_clause;
$this->_clause = $old->newWith();
- foreach($child->getChildren() as $_child)
+ foreach ($child->getChildren() as $_child) {
$_child->accept($this, $handle, $eldnah);
+ }
$old[$identifier]->setWith($this->_clause);
$this->_clause = $old;
- break;
+
+ break;
}
}
- break;
+
+ break;
case '#description':
$this->_clause = $this->_root->getClause('description');
@@ -236,7 +237,8 @@ class Interpreter implements \Hoa\Visitor\Visit {
$handle,
$eldnah
);
- break;
+
+ break;
case '#declaration':
$left = $element->getChild(0)->accept($this, $handle, false);
@@ -244,11 +246,13 @@ class Interpreter implements \Hoa\Visitor\Visit {
$variable = $left;
- if($right instanceof \Hoa\Praspel\Model\Variable)
+ if ($right instanceof Praspel\Model\Variable) {
$right = realdom()->variable($right);
+ }
$this->_clause[$variable]->in = $right;
- break;
+
+ break;
case '#local_declaration':
$left = $element->getChild(0)->accept($this, $handle, false);
@@ -256,11 +260,13 @@ class Interpreter implements \Hoa\Visitor\Visit {
$variable = $left;
- if($right instanceof \Hoa\Praspel\Model\Variable)
+ if ($right instanceof Praspel\Model\Variable) {
$right = realdom()->variable($right);
+ }
$this->_clause->let[$variable]->in = $right;
- break;
+
+ break;
case '#qualification':
$children = $element->getChildren();
@@ -270,60 +276,62 @@ class Interpreter implements \Hoa\Visitor\Visit {
false
)];
- foreach($children as $child)
+ foreach ($children as $child) {
$variable->is($child->accept($this, $handle, false));
- break;
+ }
+
+ break;
case '#contains':
$variable = $element->getChild(0)->accept($this, $handle, false);
$value = $element->getChild(1)->accept($this, $handle, false);
$this->_clause[$variable]->contains($value);
- break;
+
+ break;
case '#domainof':
$left = $element->getChild(0)->accept($this, $handle, false);
$right = $element->getChild(1)->accept($this, $handle, false);
$this->_clause[$left]->domainof($right);
- break;
+
+ break;
case '#predicate':
$this->_clause->predicate(
$element->getChild(0)->accept($this, $handle, $eldnah)
);
- break;
+
+ break;
case '#disjunction':
$disjunction = realdom();
- foreach($element->getChildren() as $child) {
-
+ foreach ($element->getChildren() as $child) {
$value = $child->accept($this, $handle, $eldnah);
- if($value instanceof \Hoa\Realdom\Disjunction)
+ if ($value instanceof Realdom\Disjunction) {
$disjunction[] = $value;
- elseif($value instanceof \Hoa\Praspel\Model\Variable)
+ } elseif ($value instanceof Praspel\Model\Variable) {
$disjunction->variable($value);
- else
+ } else {
$disjunction->const($value);
+ }
}
return $disjunction;
- break;
case '#realdom':
$children = $element->getChildren();
$child0 = array_shift($children);
$name = $child0->accept($this, $handle, false);
- $arguments = array();
-
- foreach($children as $child) {
+ $arguments = [];
+ foreach ($children as $child) {
$argument = $child->accept($this, $handle, $eldnah);
- if($argument instanceof \Hoa\Realdom\Disjunction) {
-
+ if ($argument instanceof Realdom\Disjunction) {
$realdoms = $argument->getRealdoms();
$argument = $realdoms[0];
}
@@ -332,71 +340,65 @@ class Interpreter implements \Hoa\Visitor\Visit {
}
return realdom()->_call($name, $arguments);
- break;
case '#concatenation':
$string = null;
- foreach($element->getChildren() as $child)
+ foreach ($element->getChildren() as $child) {
$string .= $child->accept($this, $handle, $eldnah);
+ }
return $string;
- break;
case '#array':
- $array = array();
-
- foreach($element->getChildren() as $child) {
-
- if('#pair' === $child->getId()) {
+ $array = [];
- $key = $child->getChild(0)
- ->accept($this, $handle, $eldnah);
- $value = $child->getChild(1)
- ->accept($this, $handle, $eldnah);
- $array[] = array($key, $value);
+ foreach ($element->getChildren() as $child) {
+ if ('#pair' === $child->getId()) {
+ $key = $child->getChild(0)->accept($this, $handle, $eldnah);
+ $value = $child->getChild(1)->accept($this, $handle, $eldnah);
+ $array[] = [$key, $value];
continue;
}
$key = realdom()->natural(0, 1);
$value = $child->accept($this, $handle, $eldnah);
- $array[] = array($key, $value);
+ $array[] = [$key, $value];
}
return $array;
- break;
case '#range':
$left = $element->getChild(0)->accept($this, $handle, $eldnah);
$right = $element->getChild(1)->accept($this, $handle, $eldnah);
- if(is_float($left) || is_float($right))
+ if (is_float($left) || is_float($right)) {
return realdom()->boundfloat(
floatval($left),
floatval($right)
);
+ }
return realdom()->boundinteger(intval($left), intval($right));
- break;
case '#left_range':
$left = $element->getChild(0)->accept($this, $handle, $eldnah);
- if(is_float($left))
+ if (is_float($left)) {
return realdom()->boundfloat($left);
+ }
return realdom()->boundinteger($left);
- break;
case '#right_range':
$right = $element->getChild(0)->accept($this, $handle, $eldnah);
- if(is_float($right))
+ if (is_float($right)) {
return realdom()->boundfloat(null, $right);
+ }
return realdom()->boundinteger(null, $right);
- break;
case '#arrayaccessbykey':
$variable = $element->getChild(0)->accept($this, $handle, $eldnah);
@@ -405,95 +407,93 @@ class Interpreter implements \Hoa\Visitor\Visit {
$this->_clause[$variable]->key($key);
return $variable;
- break;
case '#dynamic_resolution':
$value = null;
- foreach($element->getChildren() as $child) {
-
- if(null !== $value)
+ foreach ($element->getChildren() as $child) {
+ if (null !== $value) {
$value .= '->';
+ }
$value .= $child->accept($this, $handle, false);
}
- if(false !== $eldnah)
+ if (false !== $eldnah) {
return $this->_clause->getVariable($value, true);
+ }
return $value;
- break;
case '#self_identifier':
case '#static_identifier':
case '#parent_identifier':
$identifier = substr($id, 1, strpos($id, '_', 1) - 1);
- foreach($element->getChildren() as $child)
+ foreach ($element->getChildren() as $child) {
$identifier .= '::' . $child->accept($this, $handle, $eldnah);
+ }
return $identifier;
- break;
case '#old':
- $value = '\old(' .
- $element->getChild(0)->accept($this, $handle, false) .
- ')';
+ $value =
+ '\old(' .
+ $element->getChild(0)->accept($this, $handle, false) .
+ ')';
- if(false !== $eldnah)
+ if (false !== $eldnah) {
return $this->_clause->getVariable($value);
+ }
return $value;
- break;
case '#result':
return '\result';
- break;
case '#classname':
- $classname = array();
+ $classname = [];
- foreach($element->getChildren() as $child)
+ foreach ($element->getChildren() as $child) {
$classname[] = $child->accept($this, $handle, $eldnah);
+ }
return implode('\\', $classname);
- break;
case '#nowdoc':
case '#heredoc':
return $element->getChild(1)->accept($this, $handle, $eldnah);
- break;
case '#regex':
- $regex = $element->getChild(0)->accept($this, $handle, $eldnah);
+ $regex = $element->getChild(0)->accept($this, $handle, $eldnah);
- if(true === $element->childExists(1))
+ if (true === $element->childExists(1)) {
$length = $element->getChild(1)->accept($this, $handle, $eldnah);
+ }
return realdom()->regex($regex);
- break;
case '#class':
- $classname = $element->getChild(0)->accept($this, $handle, false);
+ $classname = $element->getChild(0)->accept($this, $handle, false);
return realdom()->class($classname);
- break;
case 'token':
$tId = $element->getValueToken();
$value = $element->getValueValue();
- switch($tId) {
-
+ switch ($tId) {
case 'identifier':
- if(false !== $eldnah)
+ if (false !== $eldnah) {
return $this->getIdentifier($value);
+ }
return $value;
case 'this':
- if(false !== $eldnah)
+ if (false !== $eldnah) {
return $this->_root->getImplicitVariable($value);
+ }
return $value;
@@ -517,16 +517,18 @@ class Interpreter implements \Hoa\Visitor\Visit {
case 'binary':
$int = intval(substr($value, strpos($value, 'b') + 1), 2);
- if('-' === $value[0])
+ if ('-' === $value[0]) {
return -$int;
+ }
return $int;
case 'octal':
$int = intval(substr($value, strpos($value, '0') + 1), 8);
- if('-' === $value[0])
+ if ('-' === $value[0]) {
return -$int;
+ }
return $int;
@@ -534,20 +536,21 @@ class Interpreter implements \Hoa\Visitor\Visit {
$value = strtolower($value);
$int = intval(substr($value, strpos($value, 'x') + 1), 16);
- if('-' === $value[0])
+ if ('-' === $value[0]) {
return -$int;
+ }
return $int;
case 'decimal':
- if(true === ctype_digit(ltrim($value, '+-')))
+ if (true === ctype_digit(ltrim($value, '+-'))) {
return intval($value);
+ }
return floatval($value);
case 'escaped':
- switch($value[1]) {
-
+ switch ($value[1]) {
case 'n':
return "\n";
@@ -570,13 +573,13 @@ class Interpreter implements \Hoa\Visitor\Visit {
return "\033[D";
case 'x':
- return \Hoa\String::fromCode(hexdec($value));
+ return String::fromCode(hexdec($value));
case '\\':
return $value[1];
default:
- return \Hoa\String::fromCode(octdec($value));
+ return String::fromCode(octdec($value));
}
case 'accepted':
@@ -585,30 +588,39 @@ class Interpreter implements \Hoa\Visitor\Visit {
return $value;
default:
- throw new \Hoa\Praspel\Exception\Interpreter(
- 'Token %s is not yet implemented.', 1, $tId);
+ throw new Praspel\Exception\Interpreter(
+ 'Token %s is not yet implemented.',
+ 1,
+ $tId
+ );
}
- break;
+
+ break;
default:
- throw new \Hoa\Praspel\Exception\Interpreter(
- 'Element %s is unknown.', 2, $id);
+ throw new Praspel\Exception\Interpreter(
+ 'Element %s is unknown.',
+ 2,
+ $id
+ );
}
}
/**
* Get identifier object.
*
- * @access public
* @param string $identifier Identifier.
* @return \Hoa\Praspel\Model\Variable
*/
- public function getIdentifier ( $identifier ) {
-
- if(!isset($this->_clause[$identifier]))
- throw new \Hoa\Praspel\Exception\Interpreter(
+ public function getIdentifier($identifier)
+ {
+ if (!isset($this->_clause[$identifier])) {
+ throw new Praspel\Exception\Interpreter(
'The identifier %s does not exist on clause %s.',
- 3, array($identifier, $this->_clause->getName()));
+ 3,
+ [$identifier, $this->_clause->getName()]
+ );
+ }
return $this->_clause[$identifier];
}
@@ -616,34 +628,31 @@ class Interpreter implements \Hoa\Visitor\Visit {
/**
* Get root.
*
- * @access public
* @return \Hoa\Praspel\Model\Specification
*/
- public function getRoot ( ) {
-
+ public function getRoot()
+ {
return $this->_root;
}
/**
* Get current clause.
*
- * @access public
* @return \Hoa\Praspel\Model\Clause
*/
- public function getClause ( ) {
-
+ public function getClause()
+ {
return $this->_clause;
}
/**
* Set classname to bind.
*
- * @access public
* @param string $classname Classname.
* @return string
*/
- public function bindToClass ( $classname ) {
-
+ public function bindToClass($classname)
+ {
$old = $this->_classnameToBind;
$this->_classnameToBind = $classname;
@@ -653,13 +662,10 @@ class Interpreter implements \Hoa\Visitor\Visit {
/**
* Get classname to bind.
*
- * @access public
* @return string
*/
- public function getBindedClass ( ) {
-
+ public function getBindedClass()
+ {
return $this->_classnameToBind;
}
}
-
-}
diff --git a/Visitor/Praspel.php b/Visitor/Praspel.php
index 350c7b0..6242422 100644
--- a/Visitor/Praspel.php
+++ b/Visitor/Praspel.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,147 +34,142 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Praspel\Visitor;
-from('Hoa')
-
-/**
- * \Hoa\Praspel\Exception\Compiler
- */
--> import('Praspel.Exception.Compiler')
-
-/**
- * \Hoa\Visitor\Visit
- */
--> import('Visitor.Visit');
-
-}
-
-namespace Hoa\Praspel\Visitor {
+use Hoa\Praspel as HoaPraspel;
+use Hoa\Realdom;
+use Hoa\Visitor;
/**
* Class \Hoa\Praspel\Visitor\Praspel.
*
* Compile the model to Praspel code.
*
- * @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 Praspel implements \Hoa\Visitor\Visit {
-
+class Praspel implements Visitor\Visit
+{
/**
* Visit an element.
*
- * @access public
* @param \Hoa\Visitor\Element $element Element to visit.
* @param mixed &$handle Handle (reference).
* @param mixed $eldnah Handle (not reference).
* @return mixed
*/
- public function visit ( \Hoa\Visitor\Element $element,
- &$handle = null, $eldnah = null ) {
-
+ public function visit(
+ Visitor\Element $element,
+ &$handle = null,
+ $eldnah = null
+ ) {
$out = null;
// Hoa\Praspel.
- if($element instanceof \Hoa\Praspel\Model\Specification) {
-
- $oout = array();
+ if ($element instanceof HoaPraspel\Model\Specification) {
+ $oout = [];
- foreach($element::getAllowedClauses() as $clause)
- if(true === $element->clauseExists($clause))
+ foreach ($element::getAllowedClauses() as $clause) {
+ if (true === $element->clauseExists($clause)) {
$oout[] = $element->getClause($clause)->accept(
$this,
$handle,
$eldnah
);
+ }
+ }
$out = implode("\n", $oout);
- }
- elseif($element instanceof \Hoa\Praspel\Model\Is) {
-
+ } elseif ($element instanceof HoaPraspel\Model\Is) {
$out = '@is ' . $element->getPropertyName() . ';';
- }
- elseif($element instanceof \Hoa\Praspel\Model\Declaration) {
-
+ } elseif ($element instanceof HoaPraspel\Model\Declaration) {
$clause = $element->getName();
$out = '@' . $clause;
- $oout = array();
+ $oout = [];
- foreach($element->getLocalVariables() as $name => $var)
+ foreach ($element->getLocalVariables() as $name => $var) {
$oout[] = ' ' . $var->accept($this, $handle, $eldnah);
+ }
- foreach($element->getPredicates() as $predicate)
+ foreach ($element->getPredicates() as $predicate) {
$oout[] = ' \pred(\'' . $predicate . '\')';
+ }
$out .= implode(' and', $oout) . ';';
- }
- elseif($element instanceof \Hoa\Praspel\Model\Variable) {
-
+ } elseif ($element instanceof HoaPraspel\Model\Variable) {
$name = $element->getName();
- if(true === $element->isLocal())
+ if (true === $element->isLocal()) {
$out = 'let ';
+ }
$out .= $name;
- if(null === $alias = $element->getAlias())
- $out .= ': ' .
- $element->getDomains()->accept($this, $handle, $eldnah);
- else
+ if (null === $alias = $element->getAlias()) {
+ $out .=
+ ': ' .
+ $element->getDomains()->accept($this, $handle, $eldnah);
+ } else {
$out .= ' domainof ' . $alias;
+ }
$constraints = $element->getConstraints();
- if(isset($constraints['is']))
- $out .= ' and ' . $name . ' is ' .
- implode(', ', $constraints['is']);
-
- if(isset($constraints['contains']))
- foreach($constraints['contains'] as $contains)
- $out .= ' and ' . $name . ' contains ' .
- $contains->accept($this, $handle, $eldnah);
-
- if(isset($constraints['key']))
- foreach($constraints['key'] as $pairs)
- $out .= ' and ' . $name . '[' .
- $pairs[0]->accept($this, $handle, $eldnah) .
- ']: ' . $pairs[1]->accept($this, $handle, $eldnah);
- }
- elseif($element instanceof \Hoa\Praspel\Model\Throwable) {
+ if (isset($constraints['is'])) {
+ $out .=
+ ' and ' . $name . ' is ' .
+ implode(', ', $constraints['is']);
+ }
- $oout = array();
+ if (isset($constraints['contains'])) {
+ foreach ($constraints['contains'] as $contains) {
+ $out .=
+ ' and ' . $name . ' contains ' .
+ $contains->accept($this, $handle, $eldnah);
+ }
+ }
- foreach($element as $identifier) {
+ if (isset($constraints['key'])) {
+ foreach ($constraints['key'] as $pairs) {
+ $out .=
+ ' and ' . $name . '[' .
+ $pairs[0]->accept($this, $handle, $eldnah) .
+ ']: ' . $pairs[1]->accept($this, $handle, $eldnah);
+ }
+ }
+ } elseif ($element instanceof HoaPraspel\Model\Throwable) {
+ $oout = [];
+ foreach ($element as $identifier) {
$exception = $element[$identifier];
- if(true === $exception->isDisjointed())
+ if (true === $exception->isDisjointed()) {
continue;
+ }
- $line = ' ' . $exception->getInstanceName() . ' ' .
- $identifier;
-
- foreach((array) $exception->getDisjunction() as $_identifier) {
+ $line =
+ ' ' . $exception->getInstanceName() . ' ' .
+ $identifier;
+ foreach ((array) $exception->getDisjunction() as $_identifier) {
$_exception = $element[$_identifier];
- $line .= ' or ' . $_exception->getInstanceName() . ' ' .
- $_identifier;
+ $line .=
+ ' or ' . $_exception->getInstanceName() . ' ' .
+ $_identifier;
}
- if(null !== $with = $exception->getWith()) {
-
+ if (null !== $with = $exception->getWith()) {
$line .= ' with ';
- $liine = array();
+ $liine = [];
- foreach($with as $var)
+ foreach ($with as $var) {
$liine[] = $var->accept($this, $handle, $eldnah);
+ }
- foreach($with->getPredicates() as $predicate)
+ foreach ($with->getPredicates() as $predicate) {
$liine[] = '\pred(\'' . $predicate . '\')';
+ }
$line .= implode(' and ', $liine);
}
@@ -183,14 +178,12 @@ class Praspel implements \Hoa\Visitor\Visit {
}
$out = '@throwable' . implode(' or', $oout) . ';';
- }
- elseif($element instanceof \Hoa\Praspel\Model\DefaultBehavior) {
-
+ } elseif ($element instanceof HoaPraspel\Model\DefaultBehavior) {
$out = '@default {' . "\n";
- $oout = array();
+ $oout = [];
- foreach($element::getAllowedClauses() as $clause)
- if(true === $element->clauseExists($clause))
+ foreach ($element::getAllowedClauses() as $clause) {
+ if (true === $element->clauseExists($clause)) {
$oout[] = ' ' . str_replace(
"\n",
"\n" . ' ',
@@ -200,16 +193,16 @@ class Praspel implements \Hoa\Visitor\Visit {
$eldnah
)
);
+ }
+ }
$out .= implode("\n", $oout) . "\n" . '}';
- }
- elseif($element instanceof \Hoa\Praspel\Model\Behavior) {
-
+ } elseif ($element instanceof HoaPraspel\Model\Behavior) {
$out = '@behavior ' . $element->getIdentifier() . ' {' . "\n";
- $oout = array();
+ $oout = [];
- foreach($element::getAllowedClauses() as $clause)
- if(true === $element->clauseExists($clause))
+ foreach ($element::getAllowedClauses() as $clause) {
+ if (true === $element->clauseExists($clause)) {
$oout[] = ' ' . str_replace(
"\n",
"\n" . ' ',
@@ -219,71 +212,66 @@ class Praspel implements \Hoa\Visitor\Visit {
$eldnah
)
);
+ }
+ }
$out .= implode("\n", $oout) . "\n" . '}';
-
- }
- elseif($element instanceof \Hoa\Praspel\Model\Description) {
-
- $oout = array();
-
- foreach($element as $example)
- $oout[] = '@description \'' .
- preg_replace('#(?<!\\\)\'#', '\\\'', $example) .
- '\';';
+ } elseif ($element instanceof HoaPraspel\Model\Description) {
+ $oout = [];
+
+ foreach ($element as $example) {
+ $oout[] =
+ '@description \'' .
+ preg_replace('#(?<!\\\)\'#', '\\\'', $example) .
+ '\';';
+ }
$out = implode("\n", $oout);
- }
- elseif($element instanceof \Hoa\Praspel\Model\Collection)
- foreach($element as $el)
+ } elseif ($element instanceof HoaPraspel\Model\Collection) {
+ foreach ($element as $el) {
$out .= $el->accept($this, $handle, $eldnah);
+ }
+ }
// Hoa\Realdom.
- elseif($element instanceof \Hoa\Realdom\Disjunction) {
-
+ elseif ($element instanceof Realdom\Disjunction) {
$realdoms = $element->getUnflattenedRealdoms();
- if(!empty($realdoms)) {
-
- $oout = array();
+ if (!empty($realdoms)) {
+ $oout = [];
- foreach($realdoms as $realdom)
+ foreach ($realdoms as $realdom) {
$oout[] = $realdom->accept($this, $handle, $eldnah);
+ }
$out .= implode(' or ', $oout);
}
- }
- elseif($element instanceof \Hoa\Realdom) {
-
- if($element instanceof \Hoa\Realdom\IRealdom\Constant)
+ } elseif ($element instanceof Realdom) {
+ if ($element instanceof Realdom\IRealdom\Constant) {
$out .= $element->getConstantRepresentation();
- else {
-
- $oout = array();
+ } else {
+ $oout = [];
- foreach($element->getArguments() as $argument)
+ foreach ($element->getArguments() as $argument) {
$oout[] = $argument->accept($this, $handle, $eldnah);
+ }
$out .= $element->getName() . '(' . implode(', ', $oout) . ')';
}
- }
- elseif($element instanceof \Hoa\Realdom\Crate\Constant) {
-
+ } elseif ($element instanceof Realdom\Crate\Constant) {
$praspel = $element->getPraspelRepresentation();
$out .= $praspel();
- }
- elseif($element instanceof \Hoa\Realdom\Crate\Variable) {
-
+ } elseif ($element instanceof Realdom\Crate\Variable) {
$out .= $element->getVariable()->getName();
+ } else {
+ throw new HoaPraspel\Exception\Compiler(
+ '%s is not yet implemented.',
+ 0,
+ get_class($element)
+ );
}
- else
- throw new \Hoa\Praspel\Exception\Compiler(
- '%s is not yet implemented.', 0, get_class($element));
-
return $out;
}
}
-
-}