| Conditions | 10 |
| Paths | 10 |
| Total Lines | 30 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 11.0274 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 17 | 7 | public function segmentFromArray(array $rawArray): SegmentInterface |
|
| 18 | { |
||
| 19 | 7 | $customSegment = $this->customSegment($rawArray); |
|
| 20 | |||
| 21 | 7 | if ($customSegment) { |
|
| 22 | 1 | return $customSegment; |
|
| 23 | } |
||
| 24 | |||
| 25 | 7 | $name = $rawArray[0]; |
|
| 26 | |||
| 27 | 7 | switch ($name) { |
|
| 28 | 7 | case 'UNH': |
|
| 29 | 7 | return new UNHMessageHeader($rawArray); |
|
| 30 | 6 | case 'DTM': |
|
| 31 | return new DTMDateTimePeriod($rawArray); |
||
| 32 | 6 | case 'NAD': |
|
| 33 | return new NADNameAddress($rawArray); |
||
| 34 | 6 | case 'MEA': |
|
| 35 | return new MEADimensions($rawArray); |
||
| 36 | 6 | case 'CNT': |
|
| 37 | 3 | return new CNTControl($rawArray); |
|
| 38 | 6 | case 'PCI': |
|
| 39 | return new PCIPackageId($rawArray); |
||
| 40 | 6 | case 'BGM': |
|
| 41 | return new BGMBeginningOfMessage($rawArray); |
||
| 42 | 6 | case 'UNT': |
|
| 43 | 6 | return new UNTMessageFooter($rawArray); |
|
| 44 | } |
||
| 45 | |||
| 46 | 5 | return new UnknownSegment($rawArray); |
|
| 47 | } |
||
| 61 |