LinkHandler::asString()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
c 1
b 0
f 1
dl 0
loc 14
ccs 0
cts 8
cp 0
rs 10
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
namespace AOE\HappyFeet\Typo3\Hook;
4
5
/*
6
 * Copyright notice
7
 *
8
 * (c) 2014 AOE GmbH <[email protected]>
9
 *
10
 * This file is part of the TYPO3 CMS project.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21
22
use TYPO3\CMS\Core\LinkHandling\LinkHandlingInterface;
23
24
/**
25
 * Linkhandler hook to manipulate link data before it is processed by core typolink method.
26
 */
27
class LinkHandler implements LinkHandlingInterface
28
{
29
    /**
30
     * The Base URN for this link handling to act on
31
     */
32
    protected string $baseUrn = 't3://happy_feet';
33
34
    /**
35
     * Returns all valid parameters for linking to a TYPO3 page as a string
36
     */
37
    public function asString(array $parameters): string
38
    {
39
        if (empty($parameters['uid'])) {
40
            throw new \InvalidArgumentException('The HappyFeetLinkHandler expects uid as $parameter configuration.', 1486155150);
41
        }
42
43
        $urn = $this->baseUrn;
44
        $urn .= sprintf('?uid=%s', $parameters['uid']);
45
46
        if (!empty($parameters['fragment'])) {
47
            $urn .= sprintf('#%s', $parameters['fragment']);
48
        }
49
50
        return $urn;
51
    }
52
53
    /**
54
     * Returns all relevant information built in the link to a page (see asString())
55
     */
56
    public function resolveHandlerData(array $data): array
57
    {
58
        if (empty($data['uid'])) {
59
            throw new \InvalidArgumentException('The HappyFeetLinkHandler expects identifier, uid as $data configuration', 1486155151);
60
        }
61
62
        return $data;
63
    }
64
}
65