Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UserNameTwigExtension | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| getUserName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getRealName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Twig extension to return the login name of a user |
| 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-21 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Twig\Extensions; |
| 21 | |
| 22 | use phpMyFAQ\Configuration; |
| 23 | use phpMyFAQ\Core\Exception; |
| 24 | use phpMyFAQ\User; |
| 25 | use Twig\Attribute\AsTwigFilter; |
| 26 | use Twig\Extension\AbstractExtension; |
| 27 | |
| 28 | class UserNameTwigExtension extends AbstractExtension |
| 29 | { |
| 30 | /** |
| 31 | * @throws Exception |
| 32 | */ |
| 33 | #[AsTwigFilter(name: 'userName')] |
| 34 | public static function getUserName(int $userId): string |
| 35 | { |
| 36 | $user = new User(Configuration::getConfigurationInstance()); |
| 37 | $user->getUserById($userId); |
| 38 | return $user->getLogin(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @throws Exception |
| 43 | */ |
| 44 | #[AsTwigFilter(name: 'realName')] |
| 45 | public static function getRealName(int $userId): string |
| 46 | { |
| 47 | $user = new User(Configuration::getConfigurationInstance()); |
| 48 | $user->getUserById($userId); |
| 49 | return (string) $user->getUserData(field: 'display_name'); |
| 50 | } |
| 51 | } |