Skip to content

Commit 85a2da6

Browse files
committed
Merge pull request #14 from romainlittlemarket/master
PSR-2 + enhance phpdoc
2 parents f9d4e0b + be6b9e8 commit 85a2da6

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

src/VerbalExpressions/PHPVerbalExpressions/VerbalExpressions.php

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class VerbalExpressions
1515
public $suffixes = "";
1616
public $modifiers = "m"; // default to global multi line matching
1717
public $replaceLimit = 1; // the limit of preg_replace when g modifier is not set
18-
protected $lastAdded = false; // holds the last added regex
18+
protected $lastAdded = false; // holds the last added regex
1919

2020
/**
2121
* Sanitize
@@ -80,7 +80,7 @@ public function endOfLine($enable = true)
8080
}
8181

8282
/**
83-
* Add
83+
* Then
8484
*
8585
* Add a string to the expression
8686
*
@@ -90,10 +90,12 @@ public function endOfLine($enable = true)
9090
*/
9191
public function then($value)
9292
{
93-
return $this->add("(?:".self::sanitize($value).")");
93+
return $this->add("(?:" . self::sanitize($value) . ")");
9494
}
9595

9696
/**
97+
* Find
98+
*
9799
* alias for then()
98100
* @param string $value The string to be looked for
99101
* @return VerbalExpressions
@@ -106,15 +108,15 @@ public function find($value)
106108
/**
107109
* Maybe
108110
*
109-
* Add a string to the expression that might appear once (or not).
111+
* Add a string to the expression that might appear once (or not).
110112
*
111113
* @access public
112114
* @param string $value The string to be looked for
113115
* @return VerbalExpressions
114116
*/
115117
public function maybe($value)
116118
{
117-
return $this->add("(?:".self::sanitize($value).")?");
119+
return $this->add("(?:" . self::sanitize($value) . ")?");
118120
}
119121

120122
/**
@@ -141,7 +143,7 @@ public function anything()
141143
*/
142144
public function anythingBut($value)
143145
{
144-
return $this->add("(?:[^". self::sanitize($value) ."]*)");
146+
return $this->add("(?:[^" . self::sanitize($value) . "]*)");
145147
}
146148

147149
/**
@@ -168,7 +170,7 @@ public function something()
168170
*/
169171
public function somethingBut($value)
170172
{
171-
return $this->add("(?:[^". self::sanitize($value) ."]+)");
173+
return $this->add("(?:[^" . self::sanitize($value) . "]+)");
172174
}
173175

174176
/**
@@ -212,7 +214,7 @@ public function lineBreak()
212214
* Shorthand for lineBreak
213215
*
214216
* @access public
215-
* return VerbalExpressions
217+
* @return VerbalExpressions
216218
*/
217219
public function br()
218220
{
@@ -256,7 +258,7 @@ public function word()
256258
*/
257259
public function anyOf($value)
258260
{
259-
return $this->add("[". $value ."]");
261+
return $this->add("[" . $value . "]");
260262
}
261263

262264
/**
@@ -396,7 +398,6 @@ public function multiple($value)
396398
case '+':
397399
case '*':
398400
break;
399-
400401
default:
401402
$value .= '+';
402403
break;
@@ -409,18 +410,19 @@ public function multiple($value)
409410
* OR
410411
*
411412
* Wraps the current expression in an `or` with $value
413+
* Notice: OR is a reserved keyword in PHP, so this method is prefixed with "_"
412414
*
413415
* @access public
414416
* @param string $value new expression
415417
* @return VerbalExpressions
416418
*/
417419
public function _or($value)
418420
{
419-
if (strpos($this->prefixes,"(")===false) {
421+
if (strpos($this->prefixes, "(") === false) {
420422
$this->prefixes .= "(?:";
421423
}
422424

423-
if (strpos($this->suffixes, ")")===false) {
425+
if (strpos($this->suffixes, ")") === false) {
424426
$this->suffixes .= ")";
425427
}
426428

@@ -456,7 +458,7 @@ public function __toString()
456458
*/
457459
public function getRegex()
458460
{
459-
return "/".$this->prefixes.$this->source.$this->suffixes."/".$this->modifiers;
461+
return "/" . $this->prefixes . $this->source . $this->suffixes . "/" . $this->modifiers;
460462
}
461463

462464
/**
@@ -489,9 +491,9 @@ public function test($value)
489491
* @param array $options
490492
* @return VerbalExpressions
491493
*/
492-
public function clean($options = array())
494+
public function clean(array $options = array())
493495
{
494-
$options = array_merge(array("prefixes"=> "", "source"=>"", "suffixes"=>"", "modifiers"=>"gm","replaceLimit"=>"1"), $options);
496+
$options = array_merge(array("prefixes"=> "", "source"=>"", "suffixes"=>"", "modifiers"=>"gm", "replaceLimit"=>"1"), $options);
495497
$this->prefixes = $options['prefixes'];
496498
$this->source = $options['source'];
497499
$this->suffixes = $options['suffixes'];
@@ -503,36 +505,35 @@ public function clean($options = array())
503505

504506
/**
505507
* Limit
506-
*
507-
* Adds char limit to the last added expression.
508+
*
509+
* Adds char limit to the last added expression.
508510
* If $max is less then $min the limit will be: At least $min chars {$min,}
509511
* If $max is 0 the limit will be: exactly $min chars {$min}
510512
* If $max bigger then $min the limit will be: at least $min but not more then $max {$min, $max}
511-
*
513+
*
512514
* @access public
513515
* @param integer $min
514516
* @param integer $max
515517
* @return VerbalExpressions
516518
*/
517-
public function limit($min, $max = 0) {
518-
if($max == 0)
519-
$value = "{".$min."}";
520-
521-
else if($max < $min)
522-
$value = "{".$min.",}";
523-
524-
else
525-
$value = "{".$min.",".$max."}";
519+
public function limit($min, $max = 0)
520+
{
521+
if ($max == 0) {
522+
$value = "{" . $min . "}";
523+
} elseif ($max < $min) {
524+
$value = "{" . $min . ",}";
525+
} else {
526+
$value = "{" . $min . "," . $max . "}";
527+
}
526528

527529
// check if the expression has * or + for the last expression
528-
if(preg_match("/\*|\+/", $this->lastAdded)) {
530+
if (preg_match("/\*|\+/", $this->lastAdded)) {
529531
$l = 1;
530532
$this->source = strrev(str_replace(array('+','*'), strrev($value), strrev($this->source), $l));
533+
531534
return $this;
532535
}
533536

534537
return $this->add($value);
535-
536538
}
537-
538539
}

0 commit comments

Comments
 (0)