Conditions | 10 |
Paths | 20 |
Total Lines | 34 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 110 |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
22 | public function jsonSerialize(): array |
||
23 | { |
||
24 | $dsm = static::getDoctrineStaticMeta(); |
||
25 | $toSerialize = []; |
||
26 | $getters = $dsm->getGetters(); |
||
27 | foreach ($getters as $getter) { |
||
28 | /** @var mixed $got */ |
||
29 | $got = $this->$getter(); |
||
30 | if ($got instanceof EntityInterface) { |
||
31 | continue; |
||
32 | } |
||
33 | if ($got instanceof Collection) { |
||
34 | continue; |
||
35 | } |
||
36 | if ($got instanceof Proxy) { |
||
37 | continue; |
||
38 | } |
||
39 | if ($got instanceof UuidInterface) { |
||
40 | $got = $got->toString(); |
||
41 | } |
||
42 | if ($got instanceof DateTimeImmutable) { |
||
43 | $got = $got->format('Y-m-d H:i:s'); |
||
44 | } |
||
45 | if (method_exists($got, '__toString')) { |
||
46 | $got = (string)$got; |
||
47 | } |
||
48 | if (null !== $got && false === is_scalar($got)) { |
||
49 | continue; |
||
50 | } |
||
51 | $property = $dsm->getPropertyNameFromGetterName($getter); |
||
52 | $toSerialize[$property] = $got; |
||
53 | } |
||
54 | |||
55 | return $toSerialize; |
||
56 | } |
||
60 |