Completed
Push — master ( 81aee3...0e26f5 )
by Tim
02:28
created

EventMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 7 1
A resolve() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * EventMapper.
6
 */
7
8
namespace HDNET\Calendarize\Routing\Aspect;
9
10
use HDNET\Calendarize\Service\Url\Typo3Route;
11
use TYPO3\CMS\Core\Routing\Aspect\PersistedMappableAspectInterface;
12
use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
13
use TYPO3\CMS\Core\Routing\RouteNotFoundException;
14
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
17
/**
18
 * EventMapper.
19
 */
20
class EventMapper implements PersistedMappableAspectInterface, StaticMappableAspectInterface
21
{
22
    use SiteLanguageAwareTrait;
23
24
    /**
25
     * @param string $value
26
     *
27
     * @return string|null
28
     */
29
    public function generate(string $value): ?string
30
    {
31
        $route = GeneralUtility::makeInstance(Typo3Route::class);
32
        $speaking = $route->convert(['generate' => $value], null);
33
34
        return $speaking;
35
    }
36
37
    /**
38
     * @param string $value
39
     *
40
     * @throws \Exception
41
     *
42
     * @return string|null
43
     */
44
    public function resolve(string $value): ?string
45
    {
46
        $route = GeneralUtility::makeInstance(Typo3Route::class);
47
        $id = (string) $route->convert(['resolve' => $value], null);
48
49
        if ($this->generate($id) !== $value) {
50
            throw new RouteNotFoundException('Wrong realurl segment', 12378);
51
        }
52
53
        return $id;
54
    }
55
}
56