SearchHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A stringToInt() 0 15 4
1
<?php
2
3
namespace app\core\helpers;
4
5
use app\core\exceptions\InternalException;
6
use app\core\exceptions\InvalidArgumentException;
7
use app\core\types\BaseType;
8
use yii\base\InvalidConfigException;
9
10
class SearchHelper
11
{
12
    /**
13
     * @param string $searchStr
14
     * @param $typeClassName
15
     * @return string
16
     * @throws InvalidArgumentException
17
     * @throws InvalidConfigException|InternalException
18
     */
19
    public static function stringToInt(string $searchStr, $typeClassName)
20
    {
21
        $items = [];
22
        /** @var BaseType $type */
23
        $type = \Yii::createObject($typeClassName);
24
        if (!$type instanceof BaseType) {
0 ignored issues
show
introduced by
$type is always a sub-type of app\core\types\BaseType.
Loading history...
25
            throw new InternalException('search string to Int fail');
26
        }
27
        $searchArr = explode(', ', $searchStr);
28
        foreach ($searchArr as $search) {
29
            if (in_array($search, $type::names())) {
30
                $items[] = $type::toEnumValue($search);
31
            }
32
        }
33
        return implode(', ', $items);
34
    }
35
}
36