Passed
Push — master ( 278ea8...c94f37 )
by Romain
03:40
created

findByIdentifierForce()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Domain\Repository;
18
19
use CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\EventDefinition;
20
use CuyZ\Notiz\Domain\Notification\EntityNotification;
21
use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
22
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
23
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
24
use TYPO3\CMS\Extbase\Persistence\Repository;
25
26
class EntityNotificationRepository extends Repository
27
{
28
    /**
29
     * Initializes the query settings.
30
     */
31
    public function initializeObject()
32
    {
33
        /** @var $querySettings QuerySettingsInterface */
34
        $querySettings = $this->objectManager->get(QuerySettingsInterface::class);
35
36
        $querySettings->setRespectStoragePage(false);
37
38
        $this->setDefaultQuerySettings($querySettings);
39
    }
40
41
    /**
42
     * @param EventDefinition $eventDefinition
43
     * @return QueryResultInterface
44
     */
45
    public function findFromEventDefinition(EventDefinition $eventDefinition)
46
    {
47
        $query = $this->createQuery();
48
49
        $query->matching(
50
            $query->equals('event', $eventDefinition->getFullIdentifier())
51
        );
52
53
        return $query->execute();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->execute() also could return the type array which is incompatible with the documented return type TYPO3\CMS\Extbase\Persistence\QueryResultInterface.
Loading history...
54
    }
55
56
    /**
57
     * Returns the wanted notification even if it was disabled.
58
     *
59
     * @param mixed $identifier
60
     * @return EntityNotification|object
61
     */
62
    public function findByIdentifierForce($identifier)
63
    {
64
        $query = $this->createQueryWithoutEnableStatement();
65
66
        $query->matching(
67
            $query->logicalAnd(
68
                $query->equals('uid', $identifier),
69
                $query->equals('deleted', false)
1 ignored issue
show
Unused Code introduced by
The call to TYPO3\CMS\Extbase\Persis...Interface::logicalAnd() has too many arguments starting with $query->equals('deleted', false). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
            $query->/** @scrutinizer ignore-call */ 
70
                    logicalAnd(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
70
            )
71
        );
72
73
        return $query->execute()->getFirst();
74
    }
75
76
    /**
77
     * @return QueryInterface
78
     */
79
    protected function createQueryWithoutEnableStatement()
80
    {
81
        $query = $this->createQuery();
82
        $query->getQuerySettings()
83
            ->setIgnoreEnableFields(true);
84
85
        return $query;
86
    }
87
}
88