Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
11 / 11
CRAP
100.00% covered (success)
100.00%
1 / 1
Services
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
11 / 11
11
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCategoryId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCategoryId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFaqId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFaqId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLanguage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLanguage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getQuestion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setQuestion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPdfLink
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 getPdfApiLink
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Abstract class for 3rd party services, e.g., Gravatar.
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 2010-2026 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     2010-09-05
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ;
21
22/**
23 * Class Services
24 *
25 * @package phpMyFAQ
26 */
27class Services
28{
29    /**
30     * FAQ ID.
31     */
32    protected int $faqId;
33
34    /**
35     * Entity ID.
36     */
37    protected int $categoryId;
38
39    /**
40     * Language.
41     */
42    protected string $language;
43
44    /**
45     * Question of the FAQ.
46     */
47    protected string $question;
48
49    /**
50     * Constructor.
51     */
52    public function __construct(
53        private readonly Configuration $configuration,
54    ) {
55    }
56
57    public function getCategoryId(): int
58    {
59        return $this->categoryId;
60    }
61
62    public function setCategoryId(int $categoryId): void
63    {
64        $this->categoryId = $categoryId;
65    }
66
67    public function getFaqId(): int
68    {
69        return $this->faqId;
70    }
71
72    public function setFaqId(int $faqId): void
73    {
74        $this->faqId = $faqId;
75    }
76
77    public function getLanguage(): string
78    {
79        return $this->language;
80    }
81
82    public function setLanguage(string $language): void
83    {
84        $this->language = $language;
85    }
86
87    public function getQuestion(): string
88    {
89        return urlencode(trim($this->question));
90    }
91
92    public function setQuestion(string $question): void
93    {
94        $this->question = $question;
95    }
96
97    /**
98     * Returns the "Show FAQ as PDF" URL.
99     */
100    public function getPdfLink(): string
101    {
102        return sprintf(
103            '%spdf/%d/%d/%s',
104            $this->configuration->getDefaultUrl(),
105            $this->getCategoryId(),
106            $this->getFaqId(),
107            $this->getLanguage(),
108        );
109    }
110
111    /**
112     * Returns the "Show FAQ as PDF" URL.
113     */
114    public function getPdfApiLink(): string
115    {
116        return sprintf(
117            '%spdf/%d/%d/%s',
118            $this->configuration->getDefaultUrl(),
119            $this->getCategoryId(),
120            $this->getFaqId(),
121            $this->getLanguage(),
122        );
123    }
124}