Passed
Push — feature/switch-to-configuratio... ( 74ae66 )
by Tomas Norre
07:20
created

ConfigurationRepository::createQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 3
cp 0.6667
crap 1.037
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Domain\Repository;
6
7
/*
8
 * (c) 2020 AOE GmbH <[email protected]>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21
22
use TYPO3\CMS\Backend\Utility\BackendUtility;
23
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
24
use TYPO3\CMS\Extbase\Persistence\Repository;
25
26
/**
27
 * Class ConfigurationRepository
28
 */
29
class ConfigurationRepository extends Repository
30
{
31
    /**
32
     * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
33
     */
34 1
    public function getCrawlerConfigurationRecords()
35
    {
36 1
        $query = $this->createQuery();
37 1
        $query->getQuerySettings()->setRespectStoragePage(false);
38 1
        $query->getQuerySettings()->setIncludeDeleted(false);
39 1
        return $query->execute();
40
    }
41
42
    /**
43
     * Traverses up the rootline of a page and fetches all crawler records.
44
     */
45
46
    /**
47
     * @param int $pageId
48
     * @return array|QueryInterface
49
     * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
50
     */
51 5
    public function getCrawlerConfigurationRecordsFromRootLine(int $pageId)
52
    {
53 5
        $pageIdsInRootLine = [];
54 5
        $rootLine = BackendUtility::BEgetRootLine($pageId);
55
56 5
        foreach ($rootLine as $pageInRootLine) {
57 4
            $pageIdsInRootLine[] = (int) $pageInRootLine['uid'];
58
        }
59
60 5
        if (empty($pageIdsInRootLine)) {
61 1
            return [];
62
        }
63
64 4
        $query = $this->createQuery();
65 4
        $query->getQuerySettings()->setRespectStoragePage(false);
66 4
        $query->getQuerySettings()->setIncludeDeleted(false);
67 4
        return $query->matching(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->matching(...InRootLine))->execute() also could return the type TYPO3\CMS\Extbase\Persistence\QueryResultInterface which is incompatible with the documented return type TYPO3\CMS\Extbase\Persistence\QueryInterface|array.
Loading history...
68 4
            $query->in('pid', $pageIdsInRootLine)
69 4
        )->execute();
70
    }
71
}
72