Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Radix
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
1 / 1
13
100.00% covered (success)
100.00%
1 / 1
 verify
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
1 / 1
13
1<?php
2
3/**
4 * @license MIT
5 * @author hazuki3417<hazuki3417@gmail.com>
6 * @copyright 2021 hazuki3417 all rights reserved.
7 */
8
9namespace Selen\Verify\Str\Radixes;
10
11use LogicException;
12
13class Radix
14{
15    /**
16     * 基数かどうか判定します.
17     *
18     * @param string $num  チェックする値
19     * @param int    $base チェックする基数
20     *
21     * @throws LogicException サポートしていない基数を指定したときに発生します
22     *
23     * @return bool 基数の場合はtrueを、それ以外の場合はfalseを返します
24     */
25    public static function verify(string $num, int $base): bool
26    {
27        switch ($base) {
28            case Radix2::CARDINALITY:
29                return Radix2::verify($num);
30            case Radix3::CARDINALITY:
31                return Radix3::verify($num);
32            case Radix4::CARDINALITY:
33                return Radix4::verify($num);
34            case Radix5::CARDINALITY:
35                return Radix5::verify($num);
36            case Radix6::CARDINALITY:
37                return Radix6::verify($num);
38            case Radix7::CARDINALITY:
39                return Radix7::verify($num);
40            case Radix8::CARDINALITY:
41                return Radix8::verify($num);
42            case Radix9::CARDINALITY:
43                return Radix9::verify($num);
44            case Radix10::CARDINALITY:
45                return Radix10::verify($num);
46            case Radix16::CARDINALITY:
47                return Radix16::verify($num);
48            case Radix26::CARDINALITY:
49                return Radix26::verify($num);
50            default:
51                break;
52        }
53
54        throw new LogicException(
55            'Does not support validation of the specified radix.'
56        );
57    }
58}