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
Push — master ( dba612...b06310 )
by Mario
05:16
created

DatabaseAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 11
c 1
b 0
f 0
rs 9.4285
cc 1
eloc 9
nc 1
nop 4
1
<?php
2
3
namespace Netgen\Bundle\InformationCollectionBundle\Action;
4
5
use Doctrine\DBAL\DBALException;
6
use eZ\Publish\API\Repository\Repository;
7
use eZ\Publish\API\Repository\Values\User\User;
8
use eZ\Publish\Core\Repository\Values\Content\Content;
9
use Netgen\Bundle\InformationCollectionBundle\Entity\EzInfoCollection;
10
use Netgen\Bundle\InformationCollectionBundle\Event\InformationCollected;
11
use Netgen\Bundle\InformationCollectionBundle\Exception\ActionFailedException;
12
use Netgen\Bundle\InformationCollectionBundle\Factory\FieldDataFactory;
13
use Netgen\Bundle\InformationCollectionBundle\Repository\EzInfoCollectionAttributeRepository;
14
use Netgen\Bundle\InformationCollectionBundle\Repository\EzInfoCollectionRepository;
15
use Netgen\Bundle\InformationCollectionBundle\Value\LegacyData;
16
17
class DatabaseAction implements ActionInterface, CrucialActionInterface
18
{
19
    /**
20
     * @var FieldDataFactory
21
     */
22
    protected $factory;
23
24
    /**
25
     * @var EzInfoCollectionRepository
26
     */
27
    protected $infoCollectionRepository;
28
29
    /**
30
     * @var EzInfoCollectionAttributeRepository
31
     */
32
    protected $infoCollectionAttributeRepository;
33
34
    /**
35
     * @var Repository
36
     */
37
    protected $repository;
38
39
    /**
40
     * PersistToDatabaseAction constructor.
41
     *
42
     * @param FieldDataFactory $factory
43
     * @param EzInfoCollectionRepository $infoCollectionRepository
44
     * @param EzInfoCollectionAttributeRepository $infoCollectionAttributeRepository
45
     * @param Repository $repository
46
     */
47
    public function __construct(
48
        FieldDataFactory $factory,
49
        EzInfoCollectionRepository $infoCollectionRepository,
50
        EzInfoCollectionAttributeRepository $infoCollectionAttributeRepository,
51
        Repository $repository
52
    ) {
53
        $this->factory = $factory;
54
        $this->infoCollectionRepository = $infoCollectionRepository;
55
        $this->infoCollectionAttributeRepository = $infoCollectionAttributeRepository;
56
        $this->repository = $repository;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function act(InformationCollected $event)
63
    {
64
        $struct = $event->getInformationCollectionStruct();
65
        $contentType = $event->getContentType();
66
        $location = $event->getLocation();
67
68
        /** @var Content $content */
69
        $content = $this->repository->getContentService()->loadContent($location->contentInfo->id);
70
71
        /** @var User $currentUser */
72
        $currentUser = $this->repository->getCurrentUser();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
73
74
        /** @var EzInfoCollection $ezInfo */
75
        $ezInfo = $this->infoCollectionRepository->createWithValues($location, $currentUser);
76
77
        try {
78
            $this->infoCollectionRepository->save($ezInfo);
79
        } catch (DBALException $e) {
80
            throw new ActionFailedException('database', $e->getMessage());
81
        }
82
83
        /**
84
         * @var string
85
         * @var \eZ\Publish\Core\FieldType\Value $value
86
         */
87
        foreach ($struct->getCollectedFields() as $fieldDefIdentifier => $value) {
88
            /** @var LegacyData $value */
89
            $value = $this->factory->getLegacyValue($value, $contentType->getFieldDefinition($fieldDefIdentifier));
0 ignored issues
show
Documentation introduced by
$value is of type object<Netgen\Bundle\Inf...undle\Value\LegacyData>, but the function expects a object<eZ\Publish\Core\FieldType\Value>.

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...
90
91
            $ezInfoAttribute = $this->infoCollectionAttributeRepository
92
                ->createWithValues($location, $ezInfo, $content->getField($fieldDefIdentifier)->id, $value);
93
94
            try {
95
                $this->infoCollectionAttributeRepository->save($ezInfoAttribute);
96
            } catch (DBALException $e) {
97
                throw new ActionFailedException('database', $e->getMessage());
98
            }
99
        }
100
    }
101
}
102