Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
FaqStrategy
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 build
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3/**
4 * Building FAQ URL segments for phpMyFAQ Link rewriting.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2025 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2025-11-08
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Link\Strategy;
21
22use InvalidArgumentException;
23use phpMyFAQ\Link;
24
25final class FaqStrategy implements StrategyInterface
26{
27    /**
28     * @param array<string,string> $params
29     */
30    public function build(array $params, Link $link): string
31    {
32        if (!array_key_exists(Link::LINK_GET_CATEGORY, $params)) {
33            throw new InvalidArgumentException('Missing required parameter: category');
34        }
35
36        if (!array_key_exists(Link::LINK_GET_ID, $params)) {
37            throw new InvalidArgumentException('Missing required parameter: id');
38        }
39
40        $art = $params[Link::LINK_GET_ARTLANG] ?? 'en';
41        $url =
42            Link::LINK_CONTENT
43            . $params[Link::LINK_GET_CATEGORY]
44            . Link::LINK_HTML_SLASH
45            . $params[Link::LINK_GET_ID]
46            . Link::LINK_HTML_SLASH
47            . $art
48            . Link::LINK_SLASH
49            . $link->getSEOTitle()
50            . Link::LINK_HTML_EXTENSION;
51
52        if (array_key_exists(Link::LINK_GET_HIGHLIGHT, $params)) {
53            $url .=
54                Link::LINK_SEARCHPART_SEPARATOR . Link::LINK_GET_HIGHLIGHT . '=' . $params[Link::LINK_GET_HIGHLIGHT];
55        }
56
57        if (array_key_exists(Link::LINK_FRAGMENT_SEPARATOR, $params)) {
58            $url .= Link::LINK_FRAGMENT_SEPARATOR . $params[Link::LINK_FRAGMENT_SEPARATOR];
59        }
60
61        return $url;
62    }
63}