ChildrenSubscriber   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 2 Features 0
Metric Value
c 4
b 2
f 0
dl 0
loc 40
wmc 4
lcom 1
cbo 3
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A handleHydrate() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Component\DocumentManager\Subscriber\Behavior\Mapping;
13
14
use Sulu\Component\DocumentManager\Behavior\Mapping\ChildrenBehavior;
15
use Sulu\Component\DocumentManager\Event\HydrateEvent;
16
use Sulu\Component\DocumentManager\Events;
17
use Sulu\Component\DocumentManager\ProxyFactory;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
/**
21
 * Set the children on the document.
22
 */
23
class ChildrenSubscriber implements EventSubscriberInterface
24
{
25
    /**
26
     * @var ProxyFactory
27
     */
28
    private $proxyFactory;
29
30
    /**
31
     * @param ProxyFactory $proxyFactory
32
     */
33
    public function __construct(ProxyFactory $proxyFactory)
34
    {
35
        $this->proxyFactory = $proxyFactory;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public static function getSubscribedEvents()
42
    {
43
        return [
44
            Events::HYDRATE => 'handleHydrate',
45
        ];
46
    }
47
48
    /**
49
     * @param HydrateEvent $event
50
     */
51
    public function handleHydrate(HydrateEvent $event)
52
    {
53
        $document = $event->getDocument();
54
55
        if (!$document instanceof ChildrenBehavior) {
56
            return;
57
        }
58
59
        $accessor = $event->getAccessor();
60
        $accessor->set('children', $this->proxyFactory->createChildrenCollection($document, $event->getOptions()));
0 ignored issues
show
Documentation introduced by
$event->getOptions() is of type object<Symfony\Component...solver\OptionsResolver>, but the function expects a array.

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...
61
    }
62
}
63