Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
BaseStringL11n
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 8
72
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 getId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getLanguage
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setLanguage
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getCountry
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setCountry
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toArray
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   phpOMS\Localization
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15namespace phpOMS\Localization;
16
17/**
18 * String l11n class.
19 *
20 * @package phpOMS\Localization
21 * @license OMS License 2.0
22 * @link    https://jingga.app
23 * @since   1.0.0
24 */
25class BaseStringL11n implements \JsonSerializable
26{
27    /**
28     * ID.
29     *
30     * @var int
31     * @since 1.0.0
32     */
33    public int $id = 0;
34
35    /**
36     * Name.
37     *
38     * @var string
39     * @since 1.0.0
40     */
41    public string $name = '';
42
43    // @todo: this feels like $name and $type accomplish the same thing
44    // maybe we can always use $type and remove $name.
45    // This would require some smart mapper adjustment where the name is part of the l11n model,
46    // maybe use the path definition in the mapper which is used by arrays (e.g. type/name)
47    // More maybe: $name might have been intended as internal value? -> Makes no sense because only string
48    public ?BaseStringL11nType $type = null;
49
50    /**
51     * Ref.
52     *
53     * @var int
54     * @since 1.0.0
55     */
56    public int $ref = 0;
57
58    /**
59     * Language.
60     *
61     * @var string
62     * @since 1.0.0
63     */
64    public string $language = ISO639x1Enum::_EN;
65
66    /**
67     * Country.
68     *
69     * @var string
70     * @since 1.0.0
71     */
72    public string $country = ISO3166TwoEnum::_USA;
73
74    /**
75     * Content.
76     *
77     * @var string
78     * @since 1.0.0
79     */
80    public string $content = '';
81
82    /**
83     * Constructor.
84     *
85     * @param string $content  Localized content
86     * @param string $language Language
87     * @param string $country  Country
88     *
89     * @since 1.0.0
90     */
91    public function __construct(
92        string $content = '',
93        string $language = ISO639x1Enum::_EN,
94        string $country = ISO3166TwoEnum::_USA
95    )
96    {
97        $this->content  = $content;
98        $this->language = $language;
99        $this->country  = $country;
100        $this->type     = new NullBaseStringL11nType();
101    }
102
103    /**
104     * Get id
105     *
106     * @return int
107     *
108     * @since 1.0.0
109     */
110    public function getId() : int
111    {
112        return $this->id;
113    }
114
115    /**
116     * Get language
117     *
118     * @return string
119     *
120     * @since 1.0.0
121     */
122    public function getLanguage() : string
123    {
124        return $this->language;
125    }
126
127    /**
128     * Set language
129     *
130     * @param string $language Language
131     *
132     * @return void
133     *
134     * @since 1.0.0
135     */
136    public function setLanguage(string $language) : void
137    {
138        $this->language = $language;
139    }
140
141    /**
142     * Get country
143     *
144     * @return string
145     *
146     * @since 1.0.0
147     */
148    public function getCountry() : string
149    {
150        return $this->country;
151    }
152
153    /**
154     * Set country
155     *
156     * @param string $country Country
157     *
158     * @return void
159     *
160     * @since 1.0.0
161     */
162    public function setCountry(string $country) : void
163    {
164        $this->country = $country;
165    }
166
167    /**
168     * {@inheritdoc}
169     */
170    public function toArray() : array
171    {
172        return [
173            'id'       => $this->id,
174            'content'  => $this->content,
175            'ref'      => $this->ref,
176            'language' => $this->language,
177            'country'  => $this->country,
178        ];
179    }
180
181    /**
182     * {@inheritdoc}
183     */
184    public function jsonSerialize() : mixed
185    {
186        return $this->toArray();
187    }
188}