Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

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.
Passed
Pull Request — dev-extbase-fluid (#754)
by Alexander
03:00
created

CollectionRepository::getCollections()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 56
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 39
c 0
b 0
f 0
nc 8
nop 3
dl 0
loc 56
rs 8.9848

1 Method

Rating   Name   Duplication   Size   Complexity  
A CollectionRepository::getCollectionForMetadata() 0 8 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Domain\Repository;
14
15
use Kitodo\Dlf\Common\Helper;
16
use TYPO3\CMS\Core\Database\ConnectionPool;
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
19
20
class CollectionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
21
{
22
    /**
23
     * Set the default ordering. This is applied to findAll(), too.
24
     *
25
     * @var array
26
     */
27
    protected $defaultOrderings = [
28
        'label' => QueryInterface::ORDER_ASCENDING,
29
    ];
30
31
    /**
32
     * Finds all collections
33
     *
34
     * @param string $uids separated by comma
35
     *
36
     * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
37
     */
38
    public function findAllByUids($uids)
39
    {
40
        $query = $this->createQuery();
41
42
        $constraints = [];
43
        $constraints[] = $query->in('uid', $uids);
44
45
        if (count($constraints)) {
46
            $query->matching($query->logicalAnd($constraints));
47
        }
48
49
        return $query->execute();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->execute() also could return the type array<mixed,object> which is incompatible with the documented return type TYPO3\CMS\Extbase\Persistence\QueryResultInterface.
Loading history...
50
    }
51
52
    public function getCollectionForMetadata($pages)
53
    {
54
        // Get list of collections to show.
55
        $query = $this->createQuery();
56
57
        $query->matching($query->equals('pid', $pages));
58
59
        return $query->execute();
60
    }
61
62
    /**
63
     * Finds all collection for the given settings
64
     *
65
     * @param array $settings
66
     *
67
     * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
68
     */
69
    public function findCollectionsBySettings($settings = [])
70
    {
71
        $query = $this->createQuery();
72
73
        $constraints = [];
74
75
        if ($settings['collections']) {
76
            $constraints[] = $query->in('uid', GeneralUtility::intExplode(',', $settings['collections']));
77
        }
78
79
        if ($settings['index_name']) {
80
            $constraints[] = $query->in('index_name', $settings['index_name']);
81
        }
82
83
        // do not find user created collections (used by oai-pmh plugin)
84
        if (!$settings['show_userdefined']) {
85
            $constraints[] = $query->equals('fe_cruser_id', 0);
86
        }
87
88
        // do not find collections without oai_name set (used by oai-pmh plugin)
89
        if ($settings['hideEmptyOaiNames']) {
90
            $constraints[] = $query->logicalNot($query->equals('oai_name', ''));
91
        }
92
93
        if (count($constraints)) {
94
            $query->matching(
95
                $query->logicalAnd($constraints)
96
            );
97
        }
98
99
        // order by oai_name
100
        $query->setOrderings(
101
            array('oai_name' => QueryInterface::ORDER_ASCENDING)
102
        );
103
104
        return $query->execute();
105
    }
106
107
    public function getIndexNameForSolr($settings, $set)
108
    {
109
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
110
            ->getQueryBuilderForTable('tx_dlf_collections');
111
112
        $where = '';
113
        if (!$settings['show_userdefined']) {
114
            $where = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0);
115
        }
116
        // For SOLR we need the index_name of the collection,
117
        // For DB Query we need the UID of the collection
118
        $result = $queryBuilder
119
            ->select(
120
                'tx_dlf_collections.index_name AS index_name',
121
                'tx_dlf_collections.uid AS uid',
122
                'tx_dlf_collections.index_search as index_query'
123
            )
124
            ->from('tx_dlf_collections')
125
            ->where(
126
                $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])),
127
                $queryBuilder->expr()->eq('tx_dlf_collections.oai_name',
128
                    $queryBuilder->expr()->literal($set)),
129
                $where,
130
                Helper::whereExpression('tx_dlf_collections')
131
            )
132
            ->setMaxResults(1)
133
            ->execute();
134
135
        return $result;
136
    }
137
138
}
139