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.
Completed
Pull Request — master (#73)
by
unknown
14:32
created

InformationCollectionTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 48
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B collectInformation() 0 37 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\InformationCollection\API;
6
7
use eZ\Publish\Core\MVC\Symfony\View\BaseView;
8
use eZ\Publish\Core\MVC\Symfony\View\CachableView;
9
use eZ\Publish\Core\MVC\Symfony\View\ContentValueView;
10
use eZ\Publish\Core\MVC\Symfony\View\LocationValueView;
11
use Netgen\InformationCollection\Handler;
12
use Symfony\Component\HttpFoundation\RequestStack;
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 array $options
21
     *
22
     * @return array
23
     */
24
    protected function collectInformation(ContentValueView $view, array $options): ContentValueView
25
    {
26
        $isValid = false;
27
28
        if (!$view instanceof LocationValueView) {
29
            throw new \BadMethodCallException('eZ view needs to implement LocationValueView interface');
30
        }
31
32
        /** @var Handler $handler */
33
        $handler = $this->container->get('netgen_information_collection.handler');
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...
34
        /** @var RequestStack $requestStack */
35
        $requestStack = $this->container->get('request_stack');
36
37
        $form = $handler->getForm($view->getContent(), $view->getLocation());
38
        $request = $requestStack->getCurrentRequest();
39
        $form->handleRequest($request);
40
41
        if ($form->isSubmitted() && $form->isValid()) {
42
            $isValid = true;
43
44
            $handler->handle($form->getData(), $options);
45
        }
46
47
        if ($view instanceof BaseView) {
48
            $view->addParameters([
49
                'is_valid' => $isValid,
50
                'form' => $form->createView(),
51
                'collected_fields' => $form->getData()->getFieldsData(),
52
            ]);
53
        }
54
55
        if ($view instanceof CachableView) {
56
            $view->setCacheEnabled(false);
57
        }
58
59
        return $view;
60
    }
61
}
62