Completed
Push — develop ( 535d10...221f93 )
by Peter
21:59
created

src/WebinoDraw/Listener/AjaxFragmentListener.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
6
 * @copyright   Copyright (c) 2012-2017 Webino, s. r. o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoDraw\Listener;
12
13
use WebinoDraw\Event\AjaxEvent;
14
use WebinoDraw\Service\DrawService;
15
use Zend\EventManager\SharedEventManagerInterface;
16
use Zend\EventManager\SharedListenerAggregateInterface;
17
use Zend\Http\Request;
18
19
/**
20
 * Class AjaxFragmentListener
21
 */
22
class AjaxFragmentListener implements SharedListenerAggregateInterface
23
{
24
    /**
25
     * @var \Zend\Stdlib\CallbackHandler[]
26
     */
27
    protected $listeners = [];
28
29
    /**
30
     * @var Request
31
     */
32
    protected $request;
33
34
    /**
35
     * @param Request|object $request
36
     */
37
    public function __construct(Request $request)
38
    {
39
        $this->request = $request;
40
    }
41
42
    /**
43
     * @param SharedEventManagerInterface $events
44
     */
45
    public function attachShared(SharedEventManagerInterface $events)
46
    {
47
        $this->listeners[] = $events->attach(
48
            DrawService::SERVICE,
49
            AjaxEvent::EVENT_AJAX,
50
            [$this, 'ajaxFragment']
51
        );
52
    }
53
54
    /**
55
     * @param SharedEventManagerInterface $events
56
     */
57
    public function detachShared(SharedEventManagerInterface $events)
58
    {
59
        foreach ($this->listeners as $index => $listener) {
60
            if ($events->detach(DrawService::SERVICE, $listener)) {
61
                unset($this->listeners[$index]);
62
            }
63
        }
64
    }
65
66
    /**
67
     * @param AjaxEvent $event
68
     */
69
    public function ajaxFragment(AjaxEvent $event)
70
    {
71
        $id = $this->request->getQuery()->fragmentId;
0 ignored issues
show
Accessing fragmentId on the interface Zend\Stdlib\ParametersInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
72
        empty($id) or $event->setFragmentXpath('//*[@id="' . $id . '"]');
73
    }
74
}
75