Conditions | 10 |
Paths | 256 |
Total Lines | 45 |
Lines | 0 |
Ratio | 0 % |
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 |
||
47 | private function convertApsToArray(Aps $aps): array |
||
48 | { |
||
49 | $data = []; |
||
50 | |||
51 | if ($aps->getAlert()) { |
||
52 | $data['alert'] = $this->convertAlertToArray($aps->getAlert()); |
||
53 | } |
||
54 | |||
55 | if ($aps->getSound()) { |
||
56 | $sound = $aps->getSound(); |
||
57 | |||
58 | if ($sound instanceof Sound) { |
||
59 | $data['sound'] = [ |
||
60 | 'critical' => $sound->isCritical() ? 1 : 0, |
||
61 | 'name' => $sound->getName(), |
||
62 | 'volume' => $sound->getVolume(), |
||
63 | ]; |
||
64 | } else { |
||
65 | // Sound pass as string |
||
66 | $data['sound'] = $sound; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | if ($aps->getBadge() !== null) { |
||
71 | $data['badge'] = $aps->getBadge(); |
||
72 | } |
||
73 | |||
74 | if ($aps->getCategory()) { |
||
75 | $data['category'] = $aps->getCategory(); |
||
76 | } |
||
77 | |||
78 | if ($aps->isContentAvailable()) { |
||
79 | $data['content-available'] = 1; |
||
80 | } |
||
81 | |||
82 | if ($aps->isMutableContent()) { |
||
83 | $data['mutable-content'] = 1; |
||
84 | } |
||
85 | |||
86 | if ($aps->getThreadId()) { |
||
87 | $data['thread-id'] = $aps->getThreadId(); |
||
88 | } |
||
89 | |||
90 | return $data; |
||
91 | } |
||
92 | |||
133 |