Completed
Push — master ( 5152c1...290c4d )
by Tim
02:12
created

BookingCountriesListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 2
A getCountrySelection() 0 9 2
1
<?php
2
3
namespace HDNET\Calendarize\EventListener;
4
5
use HDNET\Calendarize\Event\GenericActionAssignmentEvent;
6
use SJBR\StaticInfoTables\Domain\Repository\CountryRepository;
7
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
8
use TYPO3\CMS\Core\Utility\GeneralUtility;
9
use TYPO3\CMS\Extbase\Object\ObjectManager;
10
11
class BookingCountriesListener
12
{
13
    public function __invoke(GenericActionAssignmentEvent $event)
14
    {
15
        if (\HDNET\Calendarize\Controller\BookingController::class === $event->getClassName()) {
16
            $variables = $event->getVariables();
17
            $variables['extended']['countries'] = $this->getCountrySelection();
18
            $event->setVariables($variables);
19
        }
20
    }
21
22
    /**
23
     * Get country selection.
24
     *
25
     * @return array
26
     */
27
    protected function getCountrySelection()
28
    {
29
        if (!ExtensionManagementUtility::isLoaded('static_info_tables')) {
30
            return [];
31
        }
32
        $repository = GeneralUtility::makeInstance(ObjectManager::class)->get(CountryRepository::class);
33
34
        return $repository->findAll();
35
    }
36
}
37