Hoa central
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Hoa\Praspel\Model\Behavior Class Reference
Inheritance diagram for Hoa\Praspel\Model\Behavior:

Public Member Functions

 getClause ($clause)
 
 addClause (Clause $clause)
 
 clauseExists ($clause)
 
 setIdentifier ($identifier)
 
 getIdentifier ()
 
- Public Member Functions inherited from Hoa\Praspel\Model\Clause
 __construct (Clause $parent)
 
 getParent ()
 
 getRoot ()
 
 getName ()
 
 getId ()
 
 accept (Visitor\Visit $visitor, &$handle=null, $eldnah=null)
 
- Public Member Functions inherited from Hoa\Visitor\Element
 accept (Visit $visitor, &$handle=null, $eldnah=null)
 

Static Public Member Functions

static getAllowedClauses ()
 

Public Attributes

const NAME = 'behavior'
 

Protected Member Functions

 _getId ()
 
- Protected Member Functions inherited from Hoa\Praspel\Model\Clause
 setParent (Clause $parent)
 
 _getId ()
 

Protected Attributes

 $_clauses = []
 
 $_identifier = null
 
- Protected Attributes inherited from Hoa\Praspel\Model\Clause
 $_parent = null
 

Static Protected Attributes

static $_allowedClauses
 

Detailed Description

Class .

Represent the clause.

Definition at line 49 of file Behavior.php.

Member Function Documentation

Hoa\Praspel\Model\Behavior::_getId ( )
protected

Get identifier (fallback).

Returns
string

Definition at line 284 of file Behavior.php.

285  {
286  return $this->getName() . '_' . $this->getIdentifier();
287  }

Here is the call graph for this function:

Hoa\Praspel\Model\Behavior::addClause ( Clause  $clause)

Add a clause.

Parameters
\Hoa\Praspel\Model\Clause$clauseClause.
Returns

Definition at line 218 of file Behavior.php.

219  {
220  $name = $clause->getName();
221 
222  if (false === in_array($name, static::getAllowedClauses())) {
223  throw new Praspel\Exception\Model(
224  'Clause @%s is not allowed in @%s.',
225  7,
226  [$name, $this->getId()]
227  );
228  }
229 
230  $clause->setParent($this);
231 
232  return $this->_clauses[$name] = $clause;
233  }

Here is the call graph for this function:

Hoa\Praspel\Model\Behavior::clauseExists (   $clause)

Check if a clause already exists, i.e. has been declared.

Parameters
string$clauseClause (without leading arobase).
Returns
bool

Definition at line 241 of file Behavior.php.

242  {
243  return isset($this->_clauses[$clause]);
244  }

Here is the caller graph for this function:

static Hoa\Praspel\Model\Behavior::getAllowedClauses ( )
static

Get allowed clauses.

Returns
array

Definition at line 251 of file Behavior.php.

252  {
253  return static::$_allowedClauses;
254  }
Hoa\Praspel\Model\Behavior::getClause (   $clause)

Get or create a specific clause.

Parameters
string$clauseClause (without leading arobase).
Returns
Exceptions

Definition at line 95 of file Behavior.php.

96  {
97  if (isset($this->_clauses[$clause])) {
98  return $this->_clauses[$clause];
99  }
100 
101  $handle = null;
102 
103  if (false === in_array($clause, static::getAllowedClauses())) {
104  throw new Praspel\Exception\Model(
105  'Clause @%s is not allowed in @%s.',
106  0,
107  [$clause, $this->getId()]
108  );
109  }
110 
111  switch ($clause) {
112  case 'is':
113  $handle = new Is($this);
114 
115  break;
116 
117  case 'requires':
118  $handle = new Requires($this);
119 
120  break;
121 
122  case 'ensures':
123  if (true === $this->clauseExists('behavior')) {
124  throw new Praspel\Exception\Model(
125  'Cannot add the @ensures clause, since a @behavior ' .
126  'clause exists at the same level.',
127  1
128  );
129  }
130 
131  $handle = new Ensures($this);
132 
133  break;
134 
135  case 'throwable':
136  if (true === $this->clauseExists('behavior')) {
137  throw new Praspel\Exception\Model(
138  'Cannot add the @throwable clause, since a @behavior ' .
139  'clause exists at the same level.',
140  2
141  );
142  }
143 
144  $handle = new Throwable($this);
145 
146  break;
147 
148  case 'invariant':
149  $handle = new Invariant($this);
150 
151  break;
152 
153  case 'behavior':
154  if (true === $this->clauseExists('ensures') ||
155  true === $this->clauseExists('throwable')) {
156  throw new Praspel\Exception\Model(
157  'Cannot add the @behavior clause, since an @ensures ' .
158  'or a @throwable clause exists at the same level.',
159  3
160  );
161  }
162 
163  $handle = new Collection(
164  new self($this),
165  function (Behavior $clause, $identifier) {
166  $clause->setIdentifier($identifier);
167 
168  return;
169  }
170  );
171 
172  break;
173 
174  case 'default':
175  if (true === $this->clauseExists('ensures') ||
176  true === $this->clauseExists('throwable')) {
177  throw new Praspel\Exception\Model(
178  'Cannot add the @default clause, since an @ensures ' .
179  'or a @throwable clause exists at the same level.',
180  4
181  );
182  }
183 
184  if (false === $this->clauseExists('behavior')) {
185  throw new Praspel\Exception\Model(
186  'Cannot add a @default clause if at least one ' .
187  '@behavior clause has not been declared.',
188  5
189  );
190  }
191 
192  $handle = new DefaultBehavior($this);
193 
194  break;
195 
196  case 'description':
197  $handle = new Description($this);
198 
199  break;
200 
201  default:
202  throw new Praspel\Exception\Model(
203  'Clause @%s is unknown.',
204  6,
205  [$clause, $this->getName()]
206  );
207  }
208 
209  return $this->_clauses[$clause] = $handle;
210  }

Here is the call graph for this function:

Hoa\Praspel\Model\Behavior::getIdentifier ( )

Get identifier.

Returns
string

Definition at line 274 of file Behavior.php.

275  {
276  return $this->_identifier;
277  }

Here is the caller graph for this function:

Hoa\Praspel\Model\Behavior::setIdentifier (   $identifier)

Set identifier.

Returns
string

Definition at line 261 of file Behavior.php.

262  {
263  $old = $this->_identifier;
264  $this->_identifier = $identifier;
265 
266  return $old;
267  }

Here is the caller graph for this function:

Member Data Documentation

Hoa\Praspel\Model\Behavior::$_allowedClauses
staticprotected
Initial value:
= [
'requires',
'behavior',
'default',
'ensures',
'throwable',
'description'
]

Definition at line 63 of file Behavior.php.

Hoa\Praspel\Model\Behavior::$_clauses = []
protected

Definition at line 77 of file Behavior.php.

Hoa\Praspel\Model\Behavior::$_identifier = null
protected

Definition at line 84 of file Behavior.php.

const Hoa\Praspel\Model\Behavior::NAME = 'behavior'

Name.

string

Definition at line 56 of file Behavior.php.


The documentation for this class was generated from the following file: