Completed
Push — master ( a9a357...5d1efe )
by Tim
02:14
created

DefaultEventSearchListener   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 24 6
1
<?php
2
3
namespace HDNET\Calendarize\EventListener;
4
5
use HDNET\Calendarize\Domain\Repository\EventRepository;
6
use HDNET\Calendarize\Event\IndexRepositoryFindBySearchEvent;
7
use HDNET\Calendarize\Register;
8
use TYPO3\CMS\Core\Utility\GeneralUtility;
9
use TYPO3\CMS\Extbase\Object\ObjectManager;
10
11
class DefaultEventSearchListener
12
{
13
    public function __invoke(IndexRepositoryFindBySearchEvent $event)
14
    {
15
        if (!\in_array(Register::UNIQUE_REGISTER_KEY, $event->getIndexTypes(), true)) {
16
            return;
17
        }
18
19
        $customSearch = $event->getCustomSearch();
20
21
        // @todo Filter here for $customSearch['categories'] and take also care of the fullText
22
        // ?tx_calendarize_calendar[customSearch][categories]=1
23
        // https://github.com/lochmueller/calendarize/issues/89
24
25
        if (!isset($customSearch['fullText']) || !$customSearch['fullText']) {
26
            return;
27
        }
28
        /** @var EventRepository $eventRepository */
29
        $eventRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(EventRepository::class);
30
        $searchTermHits = $eventRepository->getIdsBySearchTerm($customSearch['fullText']);
31
        if ($searchTermHits && \count($searchTermHits)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $searchTermHits of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
32
            $indexIds = $event->getIndexIds();
33
            $indexIds['tx_calendarize_domain_model_event'] = $searchTermHits;
34
            $event->setIndexIds($indexIds);
35
        }
36
    }
37
}
38