Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Identity
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
3
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
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLocale
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\User\Presentation\Web;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use Yiisoft\Auth\IdentityInterface;
12
13/**
14 * User Identity implementation for Yii3 CurrentUser container.
15 *
16 * @package App\Modules\User\Presentation\Web
17 */
18final readonly class Identity implements IdentityInterface
19{
20    /**
21     * Identity constructor.
22     *
23     * @param int|string $id User identifier.
24     * @param string $locale User preferred locale code.
25     */
26    public function __construct(
27        private int|string $id,
28        private string $locale = 'en'
29    ) {
30    }
31
32    /**
33     * {@inheritdoc}
34     */
35    public function getId(): string
36    {
37        return (string) $this->id;
38    }
39
40    /**
41     * Gets user preferred locale.
42     *
43     * @return string Locale code.
44     */
45    public function getLocale(): string
46    {
47        return $this->locale;
48    }
49}