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 ( 36acbf )
by Mario
11:02
created

updateByCollectionId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\InformationCollection\Doctrine\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
use Doctrine\ORM\NonUniqueResultException;
9
use Doctrine\ORM\NoResultException;
10
use Doctrine\ORM\ORMException;
11
use Doctrine\ORM\ORMInvalidArgumentException;
12
use eZ\Publish\API\Repository\Values\Content\Content;
13
use eZ\Publish\API\Repository\Values\Content\Field;
14
use Netgen\InformationCollection\API\Exception\RemoveAttributeFailedException;
15
use Netgen\InformationCollection\API\Exception\RetrieveCountException;
16
use Netgen\InformationCollection\API\Exception\StoringAttributeFailedException;
17
use Netgen\InformationCollection\API\Value\Attribute;
18
use Netgen\InformationCollection\API\Value\Filter\CollectionId;
19
use Netgen\InformationCollection\API\Value\Legacy\FieldValue;
20
use Netgen\InformationCollection\Doctrine\Entity\EzInfoCollection;
21
use Netgen\InformationCollection\Doctrine\Entity\EzInfoCollectionAttribute;
22
23
class EzInfoCollectionAttributeRepository extends EntityRepository
24
{
25
    /**
26
     * Get new \Netgen\InformationCollection\Doctrine\Entity\EzInfoCollectionAttribute instance.
27
     *
28
     * @return \Netgen\InformationCollection\Doctrine\Entity\EzInfoCollectionAttribute
29
     */
30
    public function getInstance()
31
    {
32
        return new EzInfoCollectionAttribute();
33
    }
34
35
    public function createNewFromValues(Content $content, EzInfoCollection $collection, FieldValue $fieldValue, string $fieldDefIdentifier): EzInfoCollectionAttribute
36
    {
37
        $ezInfoAttribute = $this->getInstance();
38
39
        $ezInfoAttribute->setContentObjectId($content->contentInfo->id);
40
        $ezInfoAttribute->setInformationCollectionId($collection->getId());
41
        $ezInfoAttribute->setContentClassAttributeId($fieldValue->getFieldDefinitionId());
42
43
        $field = $content->getField($fieldDefIdentifier);
44
        if ($field instanceof Field) {
0 ignored issues
show
Bug introduced by
The class eZ\Publish\API\Repository\Values\Content\Field does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
45
            $ezInfoAttribute->setContentObjectAttributeId($field->id);
46
        }
47
48
        $ezInfoAttribute->setDataInt($fieldValue->getDataInt());
49
        $ezInfoAttribute->setDataFloat($fieldValue->getDataFloat());
50
        $ezInfoAttribute->setDataText($fieldValue->getDataText());
51
52
        return $ezInfoAttribute;
53
    }
54
55
    /**
56
     * Save object.
57
     *
58
     * @param \Netgen\InformationCollection\Doctrine\Entity\EzInfoCollectionAttribute $infoCollectionAttribute
59
     *
60
     * @throws StoringAttributeFailedException
61
     */
62
    public function save(EzInfoCollectionAttribute $infoCollectionAttribute)
63
    {
64
        try {
65
            $this->_em->persist($infoCollectionAttribute);
66
            $this->_em->flush($infoCollectionAttribute);
67
        } catch (ORMException | ORMInvalidArgumentException $exception) {
0 ignored issues
show
Bug introduced by
The class Doctrine\ORM\ORMInvalidArgumentException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
68
            throw new StoringAttributeFailedException('', '');
69
        }
70
    }
71
72
    /**
73
     * @param \Netgen\InformationCollection\Doctrine\Entity\EzInfoCollectionAttribute[] $attributes
74
     *
75
     * @throws ORMException
76
     */
77
    public function remove(array $attributes)
78
    {
79
        try {
80
            foreach ($attributes as $attribute) {
81
                $this->_em->remove($attribute);
82
            }
83
84
            $this->_em->flush();
85
        } catch (ORMException | ORMInvalidArgumentException $exception) {
0 ignored issues
show
Bug introduced by
The class Doctrine\ORM\ORMInvalidArgumentException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
86
            throw  new RemoveAttributeFailedException('', '');
87
        }
88
    }
89
90
    public function findByCollectionIdAndFieldDefinitionIds($collectionId, $fieldDefinitionIds)
91
    {
92
        $qb = $this->createQueryBuilder('eica');
93
94
        return $qb->select('eica')
95
            ->where('eica.informationCollectionId = :collection-id')
96
            ->setParameter('collection-id', $collectionId)
97
            ->andWhere($qb->expr()->in('eica.contentClassAttributeId', ':fields'))
98
            ->setParameter('fields', $fieldDefinitionIds)
99
            ->getQuery()
100
            ->getResult();
101
    }
102
103
    public function updateByCollectionId(CollectionId $collectionId, Attribute $attribute)
104
    {
105
        $entity = $this->findOneBy([
106
            'informationCollectionId' => $collectionId->getCollectionId(),
107
            'id' => $attribute->getId(),
108
        ]);
109
110
        if (!$entity instanceof EzInfoCollectionAttribute) {
111
            throw new \InvalidArgumentException('Attribute not found.');
112
        }
113
114
        $entity->setDataFloat($attribute->getValue()->getDataFloat());
115
        $entity->setDataInt($attribute->getValue()->getDataInt());
116
        $entity->setDataText($attribute->getValue()->getDataText());
117
118
        $this->_em->persist($entity);
119
        $this->_em->flush();
120
    }
121
122
    public function findByCollectionId($collectionId)
123
    {
124
        $qb = $this->createQueryBuilder('eica');
125
126
        return $qb->select('eica')
127
            ->where('eica.informationCollectionId = :collection-id')
128
            ->setParameter('collection-id', $collectionId)
129
            ->getQuery()
130
            ->getResult();
131
    }
132
133
    public function getCountByContentId($contentId)
134
    {
135
        try {
136
            return (int) $this->createQueryBuilder('eica')
137
                ->andWhere('eica.contentObjectId = :contentId')
138
                ->setParameter('contentId', $contentId)
139
                ->select('COUNT(eica) as children_count')
140
                ->getQuery()
141
                ->getSingleScalarResult();
142
        } catch (NonUniqueResultException | NoResultException $exception) {
0 ignored issues
show
Bug introduced by
The class Doctrine\ORM\NoResultException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
143
            throw new RetrieveCountException('', '');
144
        }
145
    }
146
147
    public function search($contentId, $searchText)
148
    {
149
        $searchText = mb_strtolower($searchText);
150
151
        $qb = $this->createQueryBuilder('eica');
152
153
        $result = $qb->select('eica.informationCollectionId')
154
            ->where('eica.contentObjectId = :contentId')
155
            ->setParameter('contentId', $contentId)
156
            ->andWhere($qb->expr()->andX(
157
                $qb->expr()->like('LOWER(eica.dataText)', ':searchText')
158
            ))
159
            ->setParameter('searchText', '%' . $searchText . '%')
160
            ->getQuery()
161
            ->getScalarResult();
162
163
        return array_column($result, 'informationCollectionId');
164
    }
165
}
166