Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ShowStrategy
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 build
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3/**
4 * Building Category overview 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 phpMyFAQ\Link;
23
24final class ShowStrategy implements StrategyInterface
25{
26    /**
27     * @param array<string,string> $params
28     */
29    public function build(array $params, Link $link): string
30    {
31        $cat = $params[Link::LINK_GET_CATEGORY] ?? 0;
32        if ($cat === 0 || $cat === '0') {
33            return Link::LINK_HTML_SHOW_CATEGORIES;
34        }
35
36        $url = Link::LINK_CATEGORY . $cat;
37        $page = $params[Link::LINK_GET_PAGE] ?? null;
38        if ($page !== null) {
39            $url .= Link::LINK_HTML_SLASH . $page;
40        }
41
42        return $url . Link::LINK_HTML_SLASH . $link->getSEOTitle() . Link::LINK_HTML_EXTENSION;
43    }
44}