Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13:37
created

AdminBundle/Helper/AdminPanel/AdminPanel.php (3 issues)

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
namespace Kunstmaan\AdminBundle\Helper\AdminPanel;
4
5
class AdminPanel 
6
{
7
    /**
8
     * @var AdminPanelAdaptorInterface[]
9
     */
10
    private $adaptors = array();
11
12
    /**
13
     * @var AdminPanelAdaptorInterface[]
14
     */
15
    private $sorted = array();
16
17
    /**
18
     * @var AdminPanelActionInterface[]
19
     */
20
    private $actions = null;
21
22
    /**
23
     * Add admin panel adaptor
24
     *
25
     * @param AdminPanelAdaptorInterface $adaptor
26
     */
27
    public function addAdminPanelAdaptor(AdminPanelAdaptorInterface $adaptor, $priority = 0)
28
    {
29
        $this->adaptors[$priority][] = $adaptor;
30
        unset($this->sorted);
31
    }
32
33
    /**
34
     * Return current admin panel actions
35
     */
36
    public function getAdminPanelActions()
37
    {
38
        if (!$this->actions) {
39
            $this->actions = array();
40
            $adaptors = $this->getAdaptors();
41
            foreach ($adaptors as $adaptor) {
42
                $this->actions = array_merge($this->actions, $adaptor->getAdminPanelActions());
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($this->actio...getAdminPanelActions()) of type array is incompatible with the declared type array<integer,object<Kun...nPanelActionInterface>> of property $actions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
            }
44
        }
45
46
        return $this->actions;
47
    }
48
49
    /**
50
     * Get adaptors sorted by priority.
51
     *
52
     * @return \Kunstmaan\AdminBundle\Helper\AdminPanel\AdminPanelAdaptorInterface[]
0 ignored issues
show
Should the return type not be null|AdminPanelAdaptorInterface[]?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
53
     */
54
    private function getAdaptors()
55
    {
56
        if (!isset($this->sorted)) {
57
            $this->sortAdaptors();
58
        }
59
60
        return $this->sorted;
61
    }
62
63
    /**
64
     * Sorts the internal list of adaptors by priority.
65
     */
66 View Code Duplication
    private function sortAdaptors()
67
    {
68
        $this->sorted = array();
69
70
        if (isset($this->adaptors)) {
71
            krsort($this->adaptors);
72
            $this->sorted = call_user_func_array('array_merge', $this->adaptors);
0 ignored issues
show
Documentation Bug introduced by
It seems like call_user_func_array('ar...erge', $this->adaptors) of type * is incompatible with the declared type array<integer,object<Kun...PanelAdaptorInterface>> of property $sorted.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
73
        }
74
    }
75
}
76