Completed
Pull Request — 2.x (#246)
by Christian
01:28
created

BaseBreadcrumbMenuBlockService::getRootMenu()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 25
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
rs 8.5806
cc 4
eloc 11
nc 8
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\SeoBundle\Block\Breadcrumb;
13
14
use Knp\Menu\FactoryInterface;
15
use Knp\Menu\Provider\MenuProviderInterface;
16
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
17
18
/**
19
 * Abstract class for breadcrumb menu services.
20
 *
21
 * @author Sylvain Deloux <[email protected]>
22
 *
23
 * @deprecated since 3.x, to be removed with 4.0.
24
 */
25
abstract class BaseBreadcrumbMenuBlockService extends AbstractBreadcrumbMenuService
26
{
27
    /**
28
     * @var string
29
     */
30
    protected $context;
31
32
    /**
33
     * @param string                $context
34
     * @param string                $name
35
     * @param EngineInterface       $templating
36
     * @param MenuProviderInterface $menuProvider
37
     * @param FactoryInterface      $factory
38
     */
39
    public function __construct($context, $name, EngineInterface $templating, MenuProviderInterface $menuProvider, FactoryInterface $factory)
0 ignored issues
show
Unused Code introduced by
The parameter $menuProvider is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
    {
41
        @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
42
            'The '.__CLASS__.' class is deprecated since 3.x, to be removed in 4.0. '.
43
            'Use '.AbstractBreadcrumbMenuService::class.' instead.',
44
            E_USER_DEPRECATED
45
        );
46
47
        parent::__construct($name, $context, $templating, $factory);
0 ignored issues
show
Documentation introduced by
$context is of type string, but the function expects a object<Symfony\Bundle\Fr...lating\EngineInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$templating is of type object<Symfony\Bundle\Fr...lating\EngineInterface>, but the function expects a object<Knp\Menu\FactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The call to AbstractBreadcrumbMenuService::__construct() has too many arguments starting with $factory.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
48
49
        $this->context = $context;
50
    }
51
52
    /**
53
     * Return true if current BlockService handles the given context.
54
     *
55
     * @param string $context
56
     *
57
     * @return bool
58
     */
59
    public function handleContext($context)
60
    {
61
        return $this->context === $context;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    protected function getContext()
68
    {
69
        return $this->context;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getName()
76
    {
77
        return sprintf('Breadcrumb %s', $this->getContext());
78
    }
79
}
80