| Conditions | 5 |
| Paths | 14 |
| Total Lines | 36 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 26 | public function parse(\SplFileObject $file) |
||
| 27 | { |
||
| 28 | $lineNumber = 'undefined'; |
||
| 29 | |||
| 30 | try { |
||
| 31 | $states = $this->strategy->createStates(); |
||
| 32 | $this->strategy->begin(); |
||
| 33 | |||
| 34 | foreach ($file as $lineNumber => $line) { |
||
| 35 | $line = new Line($line); |
||
|
|
|||
| 36 | |||
| 37 | if ($line->isEmpty()) { |
||
| 38 | continue; |
||
| 39 | } |
||
| 40 | |||
| 41 | $states->transitionTo($line->getTransactionCode()); |
||
| 42 | $handler = [$this->strategy, "on{$states->getState()}"]; |
||
| 43 | |||
| 44 | if (!is_callable($handler)) { |
||
| 45 | throw new Exception\LogicException("Missing handler for state {$states->getState()}"); |
||
| 46 | } |
||
| 47 | |||
| 48 | $handler($line); |
||
| 49 | } |
||
| 50 | |||
| 51 | $states->transitionTo(StateMachine::STATE_DONE); |
||
| 52 | return $this->strategy->done(); |
||
| 53 | |||
| 54 | } catch (\Exception $e) { |
||
| 55 | throw new Exception\InvalidFileException( |
||
| 56 | "{$e->getMessage()} on line $lineNumber in '{$file->getBasename()}'", |
||
| 57 | 0, |
||
| 58 | $e |
||
| 59 | ); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.