| Conditions | 6 |
| Paths | 14 |
| Total Lines | 35 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 19 |
| CRAP Score | 6 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 32 | 2 | public function parse(\SplFileObject $file): Section |
|
| 33 | { |
||
| 34 | 2 | $lineNumber = 'undefined'; |
|
| 35 | |||
| 36 | try { |
||
| 37 | 2 | $states = $this->strategy->createStates(); |
|
| 38 | 2 | $this->strategy->begin(); |
|
| 39 | |||
| 40 | 2 | foreach ($file as $lineNumber => $line) { |
|
| 41 | 2 | $line = new Line($line); |
|
|
|
|||
| 42 | |||
| 43 | 2 | if ($line->isEmpty()) { |
|
| 44 | 1 | continue; |
|
| 45 | } |
||
| 46 | |||
| 47 | 2 | $states->transitionTo($line->getTransactionCode()); |
|
| 48 | 2 | $handler = [$this->strategy, "on{$states->getState()}"]; |
|
| 49 | |||
| 50 | 2 | if (!method_exists(...$handler) || !is_callable($handler)) { |
|
| 51 | 1 | throw new Exception\LogicException("Missing handler for state {$states->getState()}"); |
|
| 52 | } |
||
| 53 | |||
| 54 | 1 | $handler($line); |
|
| 55 | } |
||
| 56 | |||
| 57 | 1 | $states->transitionTo(StateMachine::STATE_DONE); |
|
| 58 | 1 | return $this->strategy->done(); |
|
| 59 | 1 | } catch (\Exception $e) { |
|
| 60 | 1 | throw new Exception\InvalidFileException( |
|
| 61 | 1 | "{$e->getMessage()} on line $lineNumber in '{$file->getBasename()}'", |
|
| 62 | 1 | 0, |
|
| 63 | $e |
||
| 64 | ); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 |
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.