GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

InformationCollectionTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 50
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A collectInformation() 0 38 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\InformationCollection\API;
6
7
use eZ\Publish\Core\MVC\Symfony\View\ContentValueView;
8
use eZ\Publish\Core\MVC\Symfony\View\LocationValueView;
9
use Netgen\InformationCollection\API\Form\DynamicFormBuilderInterface;
10
use Netgen\InformationCollection\API\Value\DataTransfer\AdditionalContent;
11
use Netgen\InformationCollection\API\Value\Event\InformationCollected;
12
use Symfony\Component\HttpFoundation\Request;
13
14
trait InformationCollectionTrait
15
{
16
    /**
17
     * Builds Form, checks if Form is valid and dispatches InformationCollected event.
18
     *
19
     * @param \eZ\Publish\Core\MVC\Symfony\View\ContentValueView $view
20
     * @param \Symfony\Component\HttpFoundation\Request $request
21
     * @param \Netgen\InformationCollection\API\Value\DataTransfer\AdditionalContent $additionalContent
22
     *
23
     * @return array
24
     */
25
    protected function collectInformation(ContentValueView $view, Request $request, AdditionalContent $additionalContent): array
26
    {
27
        $isValid = false;
28
29
        if (!$view instanceof LocationValueView) {
30
            throw new \BadMethodCallException('eZ view needs to implement LocationValueView interface');
31
        }
32
33
        /** @var DynamicFormBuilderInterface $formBuilder */
34
        $formBuilder = $this->container
0 ignored issues
show
Bug introduced by
The property container does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
            ->get('netgen_information_collection.form.builder');
36
37
        $form = $formBuilder->createForm($view->getContent());
38
39
        $form->handleRequest($request);
40
41
        if ($form->isSubmitted() && $form->isValid()) {
42
            $isValid = true;
43
44
            $event = new InformationCollected(
45
                $form->getData(),
46
                $view->getLocation(),
47
                $additionalContent
48
            );
49
50
            /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */
51
            $dispatcher = $this->container
52
                ->get('event_dispatcher');
53
54
            $dispatcher->dispatch($event, Events::INFORMATION_COLLECTED);
0 ignored issues
show
Documentation introduced by
$event is of type object<Netgen\Informatio...t\InformationCollected>, but the function expects a object<Symfony\Contracts\EventDispatcher\object>.

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...
55
        }
56
57
        return [
58
            'is_valid' => $isValid,
59
            'form' => $form->createView(),
60
            'collected_fields' => $form->getData()->getFieldsData(),
61
        ];
62
    }
63
}
64