Passed
Push — features/addFlushedPagesToCraw... ( b1d38b...4e7dfc )
by Tomas Norre
08:01
created

DataHandlerHook::addFlushedPagesToCrawlerQueue()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 8.1174

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 6
eloc 12
c 2
b 0
f 1
nc 6
nop 2
dl 0
loc 19
ccs 11
cts 18
cp 0.6111
crap 8.1174
rs 9.2222
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\Extensionmanager\Utility\InstallUtility;
27
28
class DataHandlerHook
29
{
30 2
    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 2
        if (! in_array($parameters['table'], ['pages', 'tt_content'], true)) {
33
            return;
34
        }
35
36 2
        $pageIdsToBeFlushedFromCache = $parameters['pageIdArray'];
37 2
        if (empty($pageIdsToBeFlushedFromCache)) {
38
            return;
39
        }
40 2
        foreach ($pageIdsToBeFlushedFromCache as $pageId) {
41 2
            $pageId = (int) $pageId;
42 2
            if ($pageId < 1) {
43 2
                continue;
44
            }
45 2
            if ($this->getQueueRepository()->isPageInQueue($pageId)) {
46 2
                continue;
47
            }
48 2
            $this->getCrawlerApi()->addPageToQueue($pageId);
49
        }
50 2
    }
51
52 2
    private function getQueueRepository(): QueueRepository
53
    {
54 2
        return GeneralUtility::makeInstance(ObjectManager::class)->get(QueueRepository::class);
55
    }
56
57 2
    private function getCrawlerApi(): CrawlerApi
58
    {
59 2
        return GeneralUtility::makeInstance(ObjectManager::class)->get(CrawlerApi::class);
60
    }
61
}
62