Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| CategoryNameTwigExtension | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| getCategoryName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Twig extension to return the category name by category ID. |
| 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\Template |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @copyright 2024-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 2024-04-26 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Twig\Extensions; |
| 21 | |
| 22 | use phpMyFAQ\Category; |
| 23 | use phpMyFAQ\Configuration; |
| 24 | use Twig\Attribute\AsTwigFilter; |
| 25 | use Twig\Attribute\AsTwigFunction; |
| 26 | use Twig\Extension\AbstractExtension; |
| 27 | |
| 28 | class CategoryNameTwigExtension extends AbstractExtension |
| 29 | { |
| 30 | #[AsTwigFilter(name: 'categoryName')] |
| 31 | #[AsTwigFunction(name: 'categoryName')] |
| 32 | public static function getCategoryName(int $categoryId): string |
| 33 | { |
| 34 | $category = new Category(Configuration::getConfigurationInstance()); |
| 35 | |
| 36 | $categoryEntity = $category->getCategoryData($categoryId); |
| 37 | return $categoryEntity->getName(); |
| 38 | } |
| 39 | } |