CategoryRepository   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeObject() 0 4 1
B findDemanded() 0 38 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\Domain\Repository;
13
14
use DERHANSEN\SfEventMgt\Domain\Model\Category;
15
use DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand;
16
use DERHANSEN\SfEventMgt\Service\CategoryService;
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Persis...eric\Typo3QuerySettings was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Persistence\QueryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Persistence\QueryResultInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use TYPO3\CMS\Extbase\Persistence\Repository;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Persistence\Repository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
/**
24
 * @extends Repository<Category>
25
 */
26
class CategoryRepository extends Repository
27
{
28
    public function initializeObject(): void
29
    {
30
        $this->defaultQuerySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
0 ignored issues
show
Bug Best Practice introduced by
The property defaultQuerySettings does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
        $this->defaultQuerySettings->setRespectStoragePage(false);
32
    }
33
34
    /**
35
     * Returns all categories depending on the settings in the demand object
36
     */
37
    public function findDemanded(CategoryDemand $demand): QueryResultInterface
38
    {
39
        $constraints = [];
40
        $query = $this->createQuery();
41
42
        if ($demand->getCategories() !== '') {
43
            $query->getQuerySettings()->setRespectSysLanguage(false);
44
        }
45
46
        if ($demand->getRestrictToStoragePage()) {
47
            $pidList = GeneralUtility::intExplode(',', $demand->getStoragePage(), true);
48
            $constraints[] = $query->in('pid', $pidList);
49
        }
50
51
        if ($demand->getCategories()) {
52
            if ($demand->getIncludeSubcategories()) {
53
                $categoryList = CategoryService::getCategoryListWithChilds($demand->getCategories());
54
                $pidList = GeneralUtility::intExplode(',', $categoryList, true);
55
            } else {
56
                $pidList = GeneralUtility::intExplode(',', $demand->getCategories(), true);
57
            }
58
            $constraints[] = $query->in('uid', $pidList);
59
        }
60
61
        if (count($constraints) > 0) {
62
            $query->matching($query->logicalAnd(...$constraints));
63
        }
64
65
        if ($demand->getOrderField() !== '' && $demand->getOrderDirection() !== '' &&
66
            in_array($demand->getOrderField(), CategoryDemand::ORDER_FIELD_ALLOWED, true)
67
        ) {
68
            $orderings[$demand->getOrderField()] = ((strtolower($demand->getOrderDirection()) === 'desc') ?
0 ignored issues
show
Comprehensibility Best Practice introduced by
$orderings was never initialized. Although not strictly required by PHP, it is generally a good practice to add $orderings = array(); before regardless.
Loading history...
69
                QueryInterface::ORDER_DESCENDING :
70
                QueryInterface::ORDER_ASCENDING);
71
            $query->setOrderings($orderings);
72
        }
73
74
        return $query->execute();
75
    }
76
}
77