Conditions | 17 |
Paths | 9 |
Total Lines | 63 |
Lines | 12 |
Ratio | 19.05 % |
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 |
||
21 | public function postPersist(LifecycleEventArgs $args) |
||
22 | { |
||
23 | $notification = $args->getEntity(); |
||
24 | |||
25 | if (!$notification instanceof Notification) |
||
26 | return; |
||
27 | |||
28 | $manager = $args->getEntityManager(); |
||
29 | $repo = $manager->getRepository('KIUserBundle:Device'); |
||
30 | $devices = $repo->findAll(); |
||
31 | $sendToAndroid = $sendToIOS = $sendToWP = []; |
||
32 | |||
33 | // Si le mode d'envoi est direct, on envoie aux utilisateurs qui ont |
||
34 | // enregistré un ou plusieurs Devices |
||
35 | if ($notification->getMode() == 'to') { |
||
36 | foreach ($notification->getRecipients() as $user) { |
||
37 | // Si l'utilisateur a indiqué ne pas vouloir recevoir la notification |
||
38 | if (!$user->getPreferences()[$notification->getReason()]) |
||
39 | continue; |
||
40 | |||
41 | foreach ($user->getDevices() as $device) { |
||
42 | View Code Duplication | if ($device->getType() == 'Android') |
|
43 | $sendToAndroid[] = $device; |
||
44 | else if ($device->getType() == 'iOS') |
||
45 | $sendToIOS[] = $device; |
||
46 | else if ($device->getType() == 'WP') |
||
47 | $sendToWP[] = $device; |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | |||
52 | // Si on est en mode exclusion, on parcourt les Devices enregistrés |
||
53 | // et on envoie à ceux qui ne sont pas dans la liste d'exclusion |
||
54 | if ($notification->getMode() == 'exclude') { |
||
55 | $list = $notification->getRecipients(); |
||
56 | foreach ($devices as $device) { |
||
57 | if (!$list->contains($device->getOwner())) { |
||
58 | // Si l'utilisateur a indiqué ne pas vouloir recevoir la notification |
||
59 | if (!$device->getOwner()->getPreferences()[$notification->getReason()]) |
||
60 | continue; |
||
61 | |||
62 | View Code Duplication | if ($device->getType() == 'Android') |
|
63 | $sendToAndroid[] = $device->getDevice(); |
||
64 | else if ($device->getType() == 'iOS') |
||
65 | $sendToIOS[] = $device->getDevice(); |
||
66 | else if ($device->getType() == 'WP') |
||
67 | $sendToWP[] = $device->getDevice(); |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | |||
72 | // Maintenant qu'on a la liste des appareils auxquels envoyer, on envoie |
||
73 | $this->pushAndroid($notification, $sendToAndroid); |
||
74 | $this->pushIOS($notification, $sendToIOS); |
||
75 | |||
76 | // Microsoft étant d'immense débiles, on ne peut pas envoyer à plein de |
||
77 | // destinataires en une fois. On est donc obligé de faire autant de |
||
78 | // requêtes vers l'extérieur que de destinataires. |
||
79 | // À corriger quand ils feront preuve d'intelligence chez Microsoft. |
||
80 | foreach ($sendToWP as $device) { |
||
81 | //pushWP |
||
82 | } |
||
83 | } |
||
84 | |||
142 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.