| Conditions | 6 |
| Paths | 2 |
| Total Lines | 29 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 30 | public function parse($rules) |
||
| 31 | { |
||
| 32 | $this->raw = $rules; |
||
| 33 | |||
| 34 | $factory = new RuleFactory(); |
||
| 35 | $rulesArray = explode('|', $rules); |
||
| 36 | |||
| 37 | usort( |
||
| 38 | $rulesArray, |
||
| 39 | function ($a, $b) { |
||
| 40 | $aName = $this->getRuleName($a); |
||
| 41 | $aWeight = isset(self::RULE_ORDER[$aName]) ? self::RULE_ORDER[$aName] : 50; |
||
| 42 | $bName = $this->getRuleName($b); |
||
| 43 | $bWeight = isset(self::RULE_ORDER[$bName]) ? self::RULE_ORDER[$bName] : 50; |
||
| 44 | if ($aWeight == $bWeight) { |
||
| 45 | return 0; |
||
| 46 | } |
||
| 47 | return $aWeight > $bWeight ? 1 : -1; |
||
| 48 | } |
||
| 49 | ); |
||
| 50 | |||
| 51 | $ruleSet = new RuleCollection(); |
||
| 52 | foreach ($rulesArray as $rule) { |
||
| 53 | $ruleName = $this->getRuleName($rule); |
||
| 54 | $params = $this->getRuleParams($rule); |
||
| 55 | $ruleSet->push($factory->build($ruleName, $params)); |
||
| 56 | } |
||
| 57 | |||
| 58 | return $ruleSet; |
||
| 59 | } |
||
| 89 |