EntityNotificationRepository   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 26
c 4
b 0
f 0
dl 0
loc 113
rs 10
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A countFromEventDefinition() 0 3 1
A findAllWithDisabled() 0 3 1
A findFromEventDefinitionWithDisabled() 0 3 1
A createQuery() 0 7 2
A findByIdentifierForce() 0 16 1
A findFromEventDefinition() 0 3 1
A initializeObject() 0 8 1
A getQueryForEvent() 0 9 1
A createQueryWithoutEnableStatement() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * Copyright (C)
6
 * Nathan Boiron <[email protected]>
7
 * Romain Canon <[email protected]>
8
 *
9
 * This file is part of the TYPO3 NotiZ project.
10
 * It is free software; you can redistribute it and/or modify it
11
 * under the terms of the GNU General Public License, either
12
 * version 3 of the License, or any later version.
13
 *
14
 * For the full copyright and license information, see:
15
 * http://www.gnu.org/licenses/gpl-3.0.html
16
 */
17
18
namespace CuyZ\Notiz\Domain\Repository;
19
20
use CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\EventDefinition;
21
use CuyZ\Notiz\Domain\Notification\EntityNotification;
22
use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Persis...\QuerySettingsInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Persistence\QueryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Persistence\QueryResultInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use TYPO3\CMS\Extbase\Persistence\Repository;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Persistence\Repository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
27
class EntityNotificationRepository extends Repository
28
{
29
    /**
30
     * Initializes the query settings.
31
     */
32
    public function initializeObject()
33
    {
34
        /** @var $querySettings QuerySettingsInterface */
35
        $querySettings = $this->objectManager->get(QuerySettingsInterface::class);
36
37
        $querySettings->setRespectStoragePage(false);
38
39
        $this->setDefaultQuerySettings($querySettings);
40
    }
41
42
    /**
43
     * @return QueryResultInterface
44
     */
45
    public function findAllWithDisabled(): QueryResultInterface
46
    {
47
        return $this->createQueryWithoutEnableStatement()->execute();
48
    }
49
50
    /**
51
     * @param EventDefinition $eventDefinition
52
     * @return QueryResultInterface
53
     */
54
    public function findFromEventDefinition(EventDefinition $eventDefinition): QueryResultInterface
55
    {
56
        return $this->getQueryForEvent($eventDefinition)->execute();
57
    }
58
59
    /**
60
     * @param EventDefinition $eventDefinition
61
     * @return QueryResultInterface
62
     */
63
    public function findFromEventDefinitionWithDisabled(EventDefinition $eventDefinition): QueryResultInterface
64
    {
65
        return $this->getQueryForEvent($eventDefinition, true)->execute();
66
    }
67
68
    /**
69
     * @param EventDefinition $eventDefinition
70
     * @return int
71
     */
72
    public function countFromEventDefinition(EventDefinition $eventDefinition): int
73
    {
74
        return $this->getQueryForEvent($eventDefinition)->count();
75
    }
76
77
    /**
78
     * Returns the wanted notification even if it was disabled.
79
     *
80
     * @param mixed $identifier
81
     * @return EntityNotification
82
     */
83
    public function findByIdentifierForce($identifier): EntityNotification
84
    {
85
        $query = $this->createQueryWithoutEnableStatement();
86
87
        // Do not force the language so the correct notification is returned.
88
        $query->getQuerySettings()->setRespectSysLanguage(false);
89
90
        $query->matching(
91
            $query->logicalAnd(
92
                $query->equals('uid', $identifier),
93
                $query->equals('deleted', false)
94
            )
95
        );
96
97
        /** @noinspection PhpIncompatibleReturnTypeInspection */
98
        return $query->execute()->getFirst();
99
    }
100
101
    /**
102
     * @return QueryInterface
103
     */
104
    protected function createQueryWithoutEnableStatement(): QueryInterface
105
    {
106
        $query = $this->createQuery();
107
        $query->getQuerySettings()
108
            ->setIgnoreEnableFields(true);
109
110
        return $query;
111
    }
112
113
    /**
114
     * @param EventDefinition $eventDefinition
115
     * @param bool $withDisabled
116
     * @return QueryInterface
117
     */
118
    protected function getQueryForEvent(EventDefinition $eventDefinition, bool $withDisabled = false): QueryInterface
119
    {
120
        $query = $this->createQuery($withDisabled);
121
122
        $query->matching(
123
            $query->equals('event', $eventDefinition->getFullIdentifier())
124
        );
125
126
        return $query;
127
    }
128
129
    /**
130
     * @param bool $withDisabled
131
     * @return QueryInterface
132
     */
133
    public function createQuery(bool $withDisabled = false): QueryInterface
134
    {
135
        if (true === $withDisabled) {
136
            return $this->createQueryWithoutEnableStatement();
137
        }
138
139
        return parent::createQuery();
140
    }
141
}
142