Completed
Push — master ( 843511...992a29 )
by Tim
02:25
created

AbstractUrl::getIndexBase()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8817
c 0
b 0
f 0
cc 6
nc 8
nop 1
1
<?php
2
3
/**
4
 * AbstractUrl.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\Service\Url;
9
10
use HDNET\Calendarize\Domain\Model\Index;
11
use HDNET\Calendarize\Domain\Repository\IndexRepository;
12
use HDNET\Calendarize\Features\SpeakingUrlInterface;
13
use HDNET\Calendarize\Service\AbstractService;
14
use HDNET\Calendarize\Utility\ConfigurationUtility;
15
use HDNET\Calendarize\Utility\HelperUtility;
16
17
/**
18
 * AbstractUrl.
19
 */
20
abstract class AbstractUrl extends AbstractService
21
{
22
    /**
23
     * Convert the given information.
24
     *
25
     * @param $param1
26
     * @param $param2
27
     */
28
    abstract public function convert($param1, $param2);
29
30
    /**
31
     * Build the speaking base.
32
     *
33
     * @param int $indexUid
34
     *
35
     * @return string
36
     */
37
    protected function getIndexBase($indexUid): string
38
    {
39
        $indexRepository = HelperUtility::create(IndexRepository::class);
40
        $index = $indexRepository->findByUid((int) $indexUid);
41
        if (!($index instanceof Index)) {
42
            return 'idx-' . $indexUid;
43
        }
44
45
        $originalObject = $index->getOriginalObject();
46
        if (!($originalObject instanceof SpeakingUrlInterface)) {
47
            return 'idx-' . $indexUid;
48
        }
49
50
        $base = $originalObject->getRealUrlAliasBase();
51
        if (!(bool) ConfigurationUtility::get('disableDateInSpeakingUrl')) {
52
            $datePart = $index->isAllDay() ? 'Y-m-d' : 'Y-m-d-h-i';
53
            $base .= '-' . $index->getStartDateComplete()
54
                ->format($datePart);
55
        }
56
57
        if ((bool) ConfigurationUtility::get('addIndexInSpeakingUrl')) {
58
            $base .= '-' . $indexUid;
59
        }
60
61
        return (string) $base;
62
    }
63
}
64