Passed
Push — issue/634 ( 5d93e0 )
by Tomas Norre
08:32
created

DataHandlerHook::getCrawlerApi()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 2
cts 3
cp 0.6667
crap 1.037
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Hooks;
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 AOE\Crawler\Api\CrawlerApi;
23
use AOE\Crawler\Domain\Repository\QueueRepository;
24
use TYPO3\CMS\Core\Utility\GeneralUtility;
25
use TYPO3\CMS\Extbase\Object\ObjectManager;
26
use TYPO3\CMS\Frontend\Page\PageRepository;
27
28
class DataHandlerHook
29
{
30 3
    public function addFlushedPagesToCrawlerQueue(array $parameters, \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler): void
0 ignored issues
show
Unused Code introduced by
The parameter $dataHandler is not used and could be removed. ( Ignorable by Annotation )

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

30
    public function addFlushedPagesToCrawlerQueue(array $parameters, /** @scrutinizer ignore-unused */ \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32 3
        $pageIdsToBeFlushedFromCache = $parameters['pageIdArray'];
33 3
        if (empty($pageIdsToBeFlushedFromCache)) {
34
            return;
35
        }
36 3
        foreach ($pageIdsToBeFlushedFromCache as $pageId) {
37 3
            $pageId = (int) $pageId;
38 3
            if ($pageId < 1 || empty($this->getPageRepository()->getPage($pageId))) {
39 3
                continue;
40
            }
41 3
            if ($this->getQueueRepository()->isPageInQueue($pageId)) {
42 2
                continue;
43
            }
44 3
            $this->getCrawlerApi()->addPageToQueue($pageId);
45
        }
46 3
    }
47
48 3
    private function getQueueRepository(): QueueRepository
49
    {
50 3
        return GeneralUtility::makeInstance(ObjectManager::class)->get(QueueRepository::class);
51
    }
52
53 3
    private function getCrawlerApi(): CrawlerApi
54
    {
55 3
        return GeneralUtility::makeInstance(ObjectManager::class)->get(CrawlerApi::class);
56
    }
57
58 3
    private function getPageRepository(): PageRepository
59
    {
60
        // Todo: Switch to TYPO3\CMS\Core\Repository\PageRepository when dropping support for TYPO3 9LTS
61 3
        return GeneralUtility::makeInstance(ObjectManager::class)->get(PageRepository::class);
62
    }
63
}
64