Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit a903f33

Browse files
committed
Move to PSR-1 and PSR-2.
1 parent 6516f70 commit a903f33

File tree

2 files changed

+88
-93
lines changed

2 files changed

+88
-93
lines changed

Exception.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* New BSD License
1010
*
11-
* Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
11+
* Copyright © 2007-2015, Hoa community. All rights reserved.
1212
*
1313
* Redistribution and use in source and binary forms, with or without
1414
* modification, are permitted provided that the following conditions are met:
@@ -43,9 +43,9 @@
4343
*
4444
* Extending the \Hoa\Core\Exception class.
4545
*
46-
* @author Ivan Enderlin <[email protected]>
47-
* @copyright Copyright © 2007-2015 Ivan Enderlin.
46+
* @copyright Copyright © 2007-2015 Hoa community
4847
* @license New BSD License
4948
*/
50-
51-
class Exception extends Core\Exception { }
49+
class Exception extends Core\Exception
50+
{
51+
}

Visitor/Isotropic.php

Lines changed: 83 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* New BSD License
1010
*
11-
* Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
11+
* Copyright © 2007-2015, Hoa community. All rights reserved.
1212
*
1313
* Redistribution and use in source and binary forms, with or without
1414
* modification, are permitted provided that the following conditions are met:
@@ -46,17 +46,15 @@
4646
*
4747
* Isotropic walk on the AST to generate a data.
4848
*
49-
* @author Ivan Enderlin <[email protected]>
50-
* @copyright Copyright © 2007-2015 Ivan Enderlin.
49+
* @copyright Copyright © 2007-2015 Hoa community
5150
* @license New BSD License
5251
*/
53-
54-
class Isotropic implements Visitor\Visit {
55-
52+
class Isotropic implements Visitor\Visit
53+
{
5654
/**
5755
* Numeric-sampler.
5856
*
59-
* @var \Hoa\Math\Sampler object
57+
* @var \Hoa\Math\Sampler
6058
*/
6159
protected $_sampler = null;
6260

@@ -65,12 +63,11 @@ class Isotropic implements Visitor\Visit {
6563
/**
6664
* Initialize numeric-sampler.
6765
*
68-
* @access public
6966
* @param \Hoa\Math\Sampler $sampler Numeric-sampler.
7067
* @return void
7168
*/
72-
public function __construct ( Math\Sampler $sampler ) {
73-
69+
public function __construct(Math\Sampler $sampler)
70+
{
7471
$this->_sampler = $sampler;
7572

7673
return;
@@ -79,128 +76,133 @@ public function __construct ( Math\Sampler $sampler ) {
7976
/**
8077
* Visit an element.
8178
*
82-
* @access public
8379
* @param \Hoa\Visitor\Element $element Element to visit.
8480
* @param mixed &$handle Handle (reference).
8581
* @param mixed $eldnah Handle (not reference).
8682
* @return mixed
8783
*/
88-
public function visit ( Visitor\Element $element,
89-
&$handle = null, $eldnah = null ) {
90-
91-
switch($element->getId()) {
92-
84+
public function visit(
85+
Visitor\Element $element,
86+
&$handle = null,
87+
$eldnah = null
88+
) {
89+
switch ($element->getId()) {
9390
case '#expression':
9491
case '#capturing':
9592
case '#noncapturing':
9693
case '#namedcapturing':
9794
return $element->getChild(0)->accept($this, $handle, $eldnah);
98-
break;
9995

10096
case '#alternation':
10197
case '#class':
10298
return $element->getChild($this->_sampler->getInteger(
10399
0,
104100
$element->getChildrenNumber() - 1
105101
))->accept($this, $handle, $eldnah);
106-
break;
107102

108103
case '#concatenation':
109104
$out = null;
110105

111-
foreach($element->getChildren() as $child)
106+
foreach ($element->getChildren() as $child) {
112107
$out .= $child->accept($this, $handle, $eldnah);
108+
}
113109

114110
return $out;
115-
break;
116111

117112
case '#quantification':
118113
$out = null;
119114
$xy = $element->getChild(1)->getValueValue();
120115
$x = 0;
121116
$y = 0;
122117

123-
switch($element->getChild(1)->getValueToken()) {
124-
118+
switch ($element->getChild(1)->getValueToken()) {
125119
case 'zero_or_one':
126120
$y = 1;
127-
break;
121+
122+
break;
128123

129124
case 'zero_or_more':
130125
$y = mt_rand(5, 8); // why not?
131-
break;
126+
127+
break;
132128

133129
case 'one_or_more':
134130
$x = 1;
135131
$y = mt_rand(5, 8); // why not?
136-
break;
132+
133+
break;
137134

138135
case 'exactly_n':
139136
$x = $y = (int) substr($xy, 1, -1);
140-
break;
137+
138+
break;
141139

142140
case 'n_to_m':
143141
$xy = explode(',', substr($xy, 1, -1));
144142
$x = (int) trim($xy[0]);
145143
$y = (int) trim($xy[1]);
146-
break;
144+
145+
break;
147146

148147
case 'n_or_more':
149148
$xy = explode(',', substr($xy, 1, -1));
150149
$x = (int) trim($xy[0]);
151150
$y = mt_rand($x + 5, $x + 8); // why not?
152-
break;
151+
152+
break;
153153
}
154154

155-
for($i = 0, $max = $this->_sampler->getInteger($x, $y);
156-
$i < $max; ++$i)
155+
for (
156+
$i = 0, $max = $this->_sampler->getInteger($x, $y);
157+
$i < $max;
158+
++$i
159+
) {
157160
$out .= $element->getChild(0)->accept(
158161
$this,
159162
$handle,
160163
$eldnah
161164
);
165+
}
162166

163167
return $out;
164-
break;
165168

166169
case '#negativeclass':
167170
$c = [];
168171

169-
foreach($element->getChildren() as $child)
172+
foreach ($element->getChildren() as $child) {
170173
$c[String::toCode(
171174
$child->accept($this, $handle, $eldnah)
172175
)] = true;
176+
}
173177

174178
do {
175-
176179
// all printable ASCII.
177180
$i = $this->_sampler->getInteger(32, 126);
178-
} while(isset($c[$i]));
181+
} while (isset($c[$i]));
179182

180183
return String::fromCode($i);
181-
break;
182184

183185
case '#range':
184186
$out = null;
185187
$left = $element->getChild(0)->accept($this, $handle, $eldnah);
186188
$right = $element->getChild(1)->accept($this, $handle, $eldnah);
187189

188-
return String::fromCode($this->_sampler->getInteger(
189-
String::toCode($left),
190-
String::toCode($right)
191-
));
192-
break;
190+
return
191+
String::fromCode(
192+
$this->_sampler->getInteger(
193+
String::toCode($left),
194+
String::toCode($right)
195+
)
196+
);
193197

194198
case 'token':
195199
$value = $element->getValueValue();
196200

197-
switch($element->getValueToken()) {
198-
201+
switch ($element->getValueToken()) {
199202
case 'character':
200203
$value = ltrim($value, '\\');
201204

202-
switch($value) {
203-
205+
switch ($value) {
204206
case 'a':
205207
return "\a";
206208

@@ -220,44 +222,45 @@ public function visit ( Visitor\Element $element,
220222
return "\t";
221223

222224
default:
223-
return String::fromCode(intval(
224-
substr($value, 1)
225-
));
225+
return
226+
String::fromCode(
227+
intval(
228+
substr($value, 1)
229+
)
230+
);
226231
}
227-
break;
232+
233+
break;
228234

229235
case 'dynamic_character':
230236
$value = ltrim($value, '\\');
231237

232-
switch($value[0]) {
233-
238+
switch ($value[0]) {
234239
case 'x':
235240
$value = trim($value, 'x{}');
241+
236242
return String::fromCode(
237243
hexdec($value)
238244
);
239-
break;
240245

241246
default:
242247
return String::fromCode(octdec($value));
243248
}
244-
break;
249+
250+
break;
245251

246252
case 'character_type':
247253
$value = ltrim($value, '\\');
248254

249-
switch($value) {
250-
255+
switch ($value) {
251256
case 'C':
252257
return $this->_sampler->getInteger(0, 127);
253258

254259
case 'd':
255260
return $this->_sampler->getInteger(0, 9);
256261

257262
case 's':
258-
$value = $this->_sampler->getInteger(0, 1)
259-
? 'h'
260-
: 'v';
263+
$value = $this->_sampler->getInteger(0, 1) ? 'h' : 'v';
261264

262265
case 'h':
263266
$h = [
@@ -266,10 +269,7 @@ public function visit ( Visitor\Element $element,
266269
chr(0x00a0)
267270
];
268271

269-
return $h[$this->_sampler->getInteger(
270-
0,
271-
count($h) -1
272-
)];
272+
return $h[$this->_sampler->getInteger(0, count($h) -1)];
273273

274274
case 'v':
275275
$v = [
@@ -279,10 +279,7 @@ public function visit ( Visitor\Element $element,
279279
chr(0x000d)
280280
];
281281

282-
return $v[$this->_sampler->getInteger(
283-
0,
284-
count($v) -1
285-
)];
282+
return $v[$this->_sampler->getInteger(0, count($v) -1)];
286283

287284
case 'w':
288285
$w = array_merge(
@@ -291,50 +288,48 @@ public function visit ( Visitor\Element $element,
291288
[0x5f]
292289
);
293290

294-
return chr($w[
295-
$this->_sampler->getInteger(
296-
0,
297-
count($w) - 1
298-
)
299-
]);
291+
return chr($w[$this->_sampler->getInteger(0, count($w) - 1)]);
300292

301293
default:
302294
return '?';
303295
}
304-
break;
305296

306-
case 'literal':
307-
if('.' === $value) {
297+
break;
308298

299+
case 'literal':
300+
if ('.' === $value) {
309301
$w = array_merge(
310302
range(0x41, 0x5a),
311303
range(0x61, 0x7a),
312304
[0x5f]
313305
);
314306

315-
return chr($w[
316-
$this->_sampler->getInteger(
317-
0,
318-
count($w) - 1
319-
)
320-
]);
307+
return chr($w[$this->_sampler->getInteger(0, count($w) - 1)]);
321308
}
322309

323-
return str_replace('\\\\', '\\', preg_replace(
324-
'#\\\(?!\\\)#',
325-
'',
326-
$value
327-
));
310+
return
311+
str_replace(
312+
'\\\\',
313+
'\\',
314+
preg_replace(
315+
'#\\\(?!\\\)#',
316+
'',
317+
$value
318+
)
319+
);
328320
}
329321

330-
break;
322+
break;
331323

332324
case '#internal_options':
333-
break;
325+
break;
334326

335327
default:
336328
throw new Regex\Exception(
337-
'Unsupported node: %s.', 0, $element->getId());
329+
'Unsupported node: %s.',
330+
0,
331+
$element->getId()
332+
);
338333
}
339334

340335
return;

0 commit comments

Comments
 (0)