Conditions | 19 |
Paths | 28 |
Total Lines | 62 |
Code Lines | 33 |
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 |
||
49 | public function onKernelRequest(GetResponseEvent $event) |
||
50 | { |
||
51 | if (!$event->isMasterRequest() || (is_array($this->cookie->getValue()) && !empty($this->cookie->getValue()))) { |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | $experiments = $this->settingsManager->getActiveExperiments(); |
||
56 | |||
57 | if (empty($experiments)) { |
||
58 | return; |
||
59 | } |
||
60 | |||
61 | $dd = new DeviceDetector($event->getRequest()->headers->get('User-Agent')); |
||
62 | $experimentalProfiles = []; |
||
63 | $dd->parse(); |
||
64 | |||
65 | foreach ($experiments as $experiment) { |
||
66 | $experiment = $this->settingsManager->getCachedExperiment($experiment); |
||
67 | $targets = json_decode($experiment['value'], true); |
||
68 | |||
69 | if (isset($targets['Clients'])) { |
||
70 | if (isset($targets['Clients']['types']) && |
||
71 | !in_array( |
||
72 | strtolower($dd->getClient()['type']), |
||
73 | array_map('strtolower', $targets['Clients']['types']) |
||
74 | ) |
||
75 | ) { |
||
76 | continue; |
||
77 | } |
||
78 | |||
79 | if (isset($targets['Clients']['clients']) && |
||
80 | !in_array($dd->getClient()['name'], $targets['Clients']['clients']) |
||
81 | ) { |
||
82 | continue; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | if (isset($targets['OS']['types']) && !in_array($dd->getOs()['name'], $targets['OS']['types'])) { |
||
87 | continue; |
||
88 | } |
||
89 | |||
90 | if (isset($targets['Devices'])) { |
||
91 | if (isset($targets['Devices']['types']) && |
||
92 | !in_array($dd->getDeviceName(), $targets['Devices']['types']) |
||
93 | ) { |
||
94 | continue; |
||
95 | } |
||
96 | |||
97 | if (isset($targets['Devices']['brands']) && !in_array($dd->getBrand(), $targets['Devices']['brands'])) { |
||
98 | continue; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | $experimentalProfiles = array_merge($experimentalProfiles, $experiment['profile']); |
||
103 | } |
||
104 | |||
105 | if (empty($experimentalProfiles)) { |
||
106 | return; |
||
107 | } |
||
108 | |||
109 | $this->cookie->setValue($experimentalProfiles); |
||
110 | } |
||
111 | } |
||
112 |