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::collectInformation()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 8.7057
c 0
b 0
f 0
cc 6
nc 9
nop 2
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