aboutsummaryrefslogtreecommitdiffstats
path: root/Model/Throwable.php
diff options
context:
space:
mode:
Diffstat (limited to 'Model/Throwable.php')
-rw-r--r--Model/Throwable.php154
1 files changed, 60 insertions, 94 deletions
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());
}
}
-
-}