Completed
Pull Request — master (#6194)
by Vincent
05:04
created

ChildrenVoter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Menu\Matcher\Voter;
15
16
use Knp\Menu\ItemInterface;
17
use Knp\Menu\Matcher\MatcherInterface;
18
use Knp\Menu\Matcher\Voter\VoterInterface;
19
20
@trigger_error(sprintf('"%s" is deprecated since 3.28, will be removed in 4.0.', ChildrenVoter::class));
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...
21
22
/**
23
 * Children menu voter based on children items.
24
 *
25
 * @author Samusev Andrey <[email protected]>
26
 *
27
 * @deprecated since sonata-project/admin-bundle 3.28, will be removed in 4.0.
28
 */
29
class ChildrenVoter implements VoterInterface
30
{
31
    /**
32
     * @var MatcherInterface
33
     */
34
    private $matcher;
35
36
    /**
37
     * ChildrenVoter constructor.
38
     */
39
    public function __construct(MatcherInterface $matcher)
40
    {
41
        $this->matcher = $matcher;
42
    }
43
44
    public function matchItem(ItemInterface $item)
45
    {
46
        if (!$item->getExtra('sonata_admin', false)) {
47
            return null;
48
        }
49
50
        $children = $item->getChildren();
51
        $match = null;
52
        foreach ($children as $child) {
53
            if ($this->matcher->isCurrent($child)) {
54
                $match = true;
55
56
                break;
57
            }
58
        }
59
60
        return $match;
61
    }
62
}
63