Completed
Push — master ( db079f...ae1003 )
by Thomas
06:44 queued 04:24
created

IpCheckEventHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
namespace example\components;
4
5
use Tebe\Pvc\Application;
6
use Tebe\Pvc\Event\Event;
7
use Tebe\Pvc\Event\EventHandler;
8
9
class IpCheckEventHandler implements EventHandler
10
{
11
12
    protected $blockedIps;
13
14
    public function __construct($blockedIps)
15
    {
16
        $this->blockedIps = $blockedIps;
17
    }
18
19
    public function handle(Event $event) : void
20
    {
21
        $request  = Application::instance()->getRequest();
22
        $ipAdress = $request->getRemoteAddress();
0 ignored issues
show
Bug introduced by
The method getRemoteAddress() does not exist on Psr\Http\Message\ServerRequestInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        /** @scrutinizer ignore-call */ 
23
        $ipAdress = $request->getRemoteAddress();

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.

Loading history...
23
24
        if (in_array($ipAdress, $this->blockedIps)) {
25
            $event->cancel();
26
        }
27
    }
28
}
29