Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
AbstractWidth | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
exist | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
notExist | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
only | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
notOnly | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
calcStrAllFullWidth | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
calcStrAllHalfWidth | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStrLength | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStrWidth | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @license MIT |
5 | * @author hazuki3417<hazuki3417@gmail.com> |
6 | * @copyright 2023 hazuki3417 all rights reserved. |
7 | */ |
8 | |
9 | namespace Selen\Str\Verify\Width; |
10 | |
11 | abstract class AbstractWidth |
12 | { |
13 | /** @var int 半角1文字の幅 */ |
14 | public const HALF_CHARACTER_WIDTH = 1; |
15 | |
16 | /** @var int 全角1文字の幅 */ |
17 | public const FULL_CHARACTER_WIDTH = 2; |
18 | |
19 | /** @var string */ |
20 | protected $str; |
21 | |
22 | public function __construct(string $val) |
23 | { |
24 | $this->str = $val; |
25 | } |
26 | |
27 | abstract public function exist(): bool; |
28 | abstract public function notExist(): bool; |
29 | abstract public function only(): bool; |
30 | abstract public function notOnly(): bool; |
31 | |
32 | /** |
33 | * すべて全角文字だった場合の横幅の長さを計算します |
34 | * |
35 | * @return int 横幅の長さを返します |
36 | */ |
37 | protected function calcStrAllFullWidth(): int |
38 | { |
39 | return $this->getStrLength() * self::FULL_CHARACTER_WIDTH; |
40 | } |
41 | |
42 | /** |
43 | * すべて半角文字だった場合の横幅の長さを計算します |
44 | * |
45 | * @return int 横幅の長さを返します |
46 | */ |
47 | protected function calcStrAllHalfWidth(): int |
48 | { |
49 | return $this->getStrLength() * self::HALF_CHARACTER_WIDTH; |
50 | } |
51 | |
52 | /** |
53 | * 文字列の長さを取得します |
54 | * |
55 | * @return int 文字列の長さを返します |
56 | */ |
57 | protected function getStrLength(): int |
58 | { |
59 | return mb_strlen($this->str); |
60 | } |
61 | |
62 | /** |
63 | * 文字列の横幅を取得します |
64 | * |
65 | * @return int 文字列の横幅を返します |
66 | */ |
67 | protected function getStrWidth(): int |
68 | { |
69 | return mb_strwidth($this->str); |
70 | } |
71 | } |