Completed
Push — develop ( 725207...6c2664 )
by
unknown
16:33 queued 08:34
created

DefaultNavigationFactory::injectComponents()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 16
rs 9.2
c 1
b 0
f 1
cc 4
eloc 10
nc 3
nop 4
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Core\Factory\Navigation;
12
13
use Zend\Mvc\Router\RouteMatch;
14
use Zend\Mvc\Router\RouteStackInterface as Router;
15
use Zend\Navigation\Service\DefaultNavigationFactory as ZfDefaultNavigationFactory;
16
17
/**
18
 * Extends the ZF DefaultNavigationFactory to let it set
19
 * active flags on pages when the route matches an entry
20
 * in the "active_on" option.
21
 * 
22
 * @author Mathias Gelhausen <[email protected]>
23
 * @since 0.26
24
 */
25
class DefaultNavigationFactory extends ZfDefaultNavigationFactory
26
{
27
28
    /**
29
     * Inject components into the pages.
30
     *
31
     * @internal
32
     *      Parses the pages options for the "active_on" property and
33
     *      sets the active flag if one of the routes match.
34
     *
35
     * @param array      $pages
36
     * @param RouteMatch $routeMatch
0 ignored issues
show
Documentation introduced by
Should the type for parameter $routeMatch not be null|RouteMatch?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
37
     * @param Router     $router
0 ignored issues
show
Documentation introduced by
Should the type for parameter $router not be null|Router?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
38
     * @param null       $request
39
     *
40
     * @return array
41
     */
42
    protected function injectComponents(
43
        array $pages,
44
        RouteMatch $routeMatch = null,
45
        Router $router = null,
46
        $request = null
47
    ) {
48
        $routeName = $routeMatch->getMatchedRouteName();
0 ignored issues
show
Bug introduced by
It seems like $routeMatch is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
49
50
        foreach ($pages as &$page) {
51
            if (isset($page['active_on']) && in_array($routeName, (array) $page['active_on'])) {
52
                $page['active'] = true;
53
            }
54
        }
55
56
        return parent::injectComponents($pages, $routeMatch, $router, $request);
57
    }
58
59
60
}