Conditions | 20 |
Paths | 3080 |
Total Lines | 84 |
Code Lines | 42 |
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 |
||
128 | public function getIpAddress($ip = null) |
||
129 | { |
||
130 | static $ipAddresses = []; |
||
131 | |||
132 | if (null === $ip) { |
||
133 | $ip = $this->getIpAddressFromRequest(); |
||
134 | } |
||
135 | |||
136 | if (empty($ip) || !$this->ipIsValid($ip)) { |
||
137 | //assume local as the ip is empty |
||
138 | $ip = '127.0.0.1'; |
||
139 | } |
||
140 | |||
141 | $this->realIp = $ip; |
||
142 | |||
143 | if ($this->coreParametersHelper->get('anonymize_ip')) { |
||
144 | $ip = preg_replace(['/\.\d*$/', '/[\da-f]*:[\da-f]*$/'], ['.***', '****:****'], $ip); |
||
145 | } |
||
146 | |||
147 | if (empty($ipAddresses[$ip])) { |
||
148 | $repo = $this->em->getRepository('MauticCoreBundle:IpAddress'); |
||
149 | $ipAddress = $repo->findOneByIpAddress($ip); |
||
|
|||
150 | $saveIp = (null === $ipAddress); |
||
151 | |||
152 | if (null === $ipAddress) { |
||
153 | $ipAddress = new IpAddress(); |
||
154 | $ipAddress->setIpAddress($ip); |
||
155 | } |
||
156 | |||
157 | // Ensure the do not track list is inserted |
||
158 | if (!is_array($this->doNotTrackIps)) { |
||
159 | $this->doNotTrackIps = []; |
||
160 | } |
||
161 | |||
162 | if (!is_array($this->doNotTrackBots)) { |
||
163 | $this->doNotTrackBots = []; |
||
164 | } |
||
165 | |||
166 | if (!is_array($this->doNotTrackInternalIps)) { |
||
167 | $this->doNotTrackInternalIps = []; |
||
168 | } |
||
169 | |||
170 | $doNotTrack = array_merge($this->doNotTrackIps, $this->doNotTrackInternalIps); |
||
171 | if ('prod' === MAUTIC_ENV) { |
||
172 | // Do not track internal IPs |
||
173 | $doNotTrack = array_merge($doNotTrack, ['127.0.0.1', '::1']); |
||
174 | } |
||
175 | |||
176 | $ipAddress->setDoNotTrackList($doNotTrack); |
||
177 | |||
178 | if ($ipAddress->isTrackable() && $this->request) { |
||
179 | $userAgent = $this->request->headers->get('User-Agent'); |
||
180 | foreach ($this->doNotTrackBots as $bot) { |
||
181 | if (false !== strpos($userAgent, $bot)) { |
||
182 | $doNotTrack[] = $ip; |
||
183 | $ipAddress->setDoNotTrackList($doNotTrack); |
||
184 | continue; |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | |||
189 | $details = $ipAddress->getIpDetails(); |
||
190 | if ($ipAddress->isTrackable() && empty($details['city']) && !$this->coreParametersHelper->get('anonymize_ip')) { |
||
191 | // Get the IP lookup service |
||
192 | |||
193 | // Fetch the data |
||
194 | if ($this->ipLookup) { |
||
195 | $details = $this->getIpDetails($ip); |
||
196 | |||
197 | $ipAddress->setIpDetails($details); |
||
198 | |||
199 | // Save new details |
||
200 | $saveIp = true; |
||
201 | } |
||
202 | } |
||
203 | |||
204 | if ($saveIp) { |
||
205 | $repo->saveEntity($ipAddress); |
||
206 | } |
||
207 | |||
208 | $ipAddresses[$ip] = $ipAddress; |
||
209 | } |
||
210 | |||
211 | return $ipAddresses[$ip]; |
||
212 | } |
||
283 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.