| Conditions | 13 |
| Paths | 8 |
| Total Lines | 63 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 50 | public function parse(stdClass $object, array $restrictions, array $detours = []): Situation |
||
| 51 | { |
||
| 52 | if ($roadAuthority = $object->properties->roadAuthority ?? null) { |
||
| 53 | $roadAuthority = new RoadAuthority( |
||
| 54 | $roadAuthority->id, |
||
| 55 | RoadAuthorityType::from($roadAuthority->type), |
||
| 56 | $roadAuthority->name |
||
| 57 | ); |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($createdBy = $object->properties->createdBy ?? null) { |
||
| 61 | $createdBy = new Person( |
||
| 62 | $createdBy->firstName, |
||
| 63 | $createdBy->prefix, |
||
| 64 | $createdBy->lastName, |
||
| 65 | PersonType::from($createdBy->type) |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($lastChangedBy = $object->properties->lastChangedBy ?? null) { |
||
| 70 | $lastChangedBy = new Person( |
||
| 71 | $lastChangedBy->firstName, |
||
| 72 | $lastChangedBy->prefix, |
||
| 73 | $lastChangedBy->lastName, |
||
| 74 | PersonType::from($lastChangedBy->type) |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | |||
| 78 | $location = new Location( |
||
| 79 | $object->properties->location->city, |
||
| 80 | $object->properties->location->road, |
||
| 81 | $object->properties->location->district, |
||
| 82 | $object->properties->location->comment ?? '' |
||
| 83 | ); |
||
| 84 | |||
| 85 | return new Situation( |
||
| 86 | $object->id, |
||
| 87 | str_contains($object->properties->type, '_EXTERNAL'), |
||
| 88 | $this->geometryParser->parse($object->geometry), |
||
| 89 | $this->getName($object), |
||
| 90 | $this->getActivityType($object), |
||
| 91 | ($object->properties->workObject ?? '') ? WorkObject::from($object->properties->workObject) : null, |
||
| 92 | $object->properties->impact !== 'EMPTY' ? Impact::from($object->properties->impact) : null, |
||
| 93 | $object->properties->project, |
||
| 94 | Source::from($object->properties->source), |
||
| 95 | $object->properties->published, |
||
| 96 | $object->properties->url ?: null, |
||
| 97 | ($object->properties->urlDescription ?? '') ?: null, |
||
| 98 | Delay::from($object->properties->delay), |
||
| 99 | ($object->properties->workType ?? '') ? WorkType::from($object->properties->workType) : null, |
||
| 100 | ($object->properties->eventType ?? '') ? EventType::from($object->properties->eventType) : null, |
||
| 101 | ($object->properties->eventName ?? '') ?: null, |
||
| 102 | ($object->properties->addition ?? '') ?: null, |
||
| 103 | SituationStatus::from($object->properties->status), |
||
| 104 | $roadAuthority, |
||
| 105 | $location, |
||
| 106 | array_map([$this->periodParser, 'parse'], $object->properties->periods, array_keys($object->properties->periods)), |
||
| 107 | ($object->properties->createdAt ?? null) ? new DateTime($object->properties->createdAt) : null, |
||
| 108 | $createdBy, |
||
| 109 | $lastChangedBy, |
||
| 110 | array_map([$this->attachmentParser, 'parse'], $object->properties->attachments ?? [], array_keys($object->properties->attachments ?? [])), |
||
| 111 | array_map([$this->restrictionParser, 'parse'], $restrictions, array_keys($restrictions)), |
||
| 112 | array_map([$this->detourParser, 'parse'], $detours, array_keys($detours)) |
||
| 113 | ); |
||
| 167 |