ModuleHelper   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPhpDocInterfaceProperty() 0 8 2
A getModuleNameByClass() 0 14 5
1
<?php
2
3
4
namespace carono\exchange1c\helpers;
5
6
7
class ModuleHelper
8
{
9
    /**
10
     * @param string $class
11
     * @param string|null $default
12
     * @return int|null|string
13
     */
14
    public static function getModuleNameByClass($class = 'carono\exchange1c\ExchangeModule', $default = null)
15
    {
16
        foreach (\Yii::$app->modules as $name => $module) {
17
            $result = '';
18
            if ((is_array($module))) {
19
                $result = ltrim($module['class'], '\\');
20
            } elseif (is_object($module)) {
21
                $result = get_class($module);
22
            }
23
            if ($result == ltrim($class, '\\')) {
24
                return $name;
25
            }
26
        }
27
        return $default;
28
    }
29
30
    /**
31
     * @param $variable
32
     * @param string $class
33
     * @return string|null
34
     */
35
    public static function getPhpDocInterfaceProperty($variable, $class = 'carono\exchange1c\ExchangeModule')
36
    {
37
        $reflection = new \ReflectionClass($class);
38
        $property = $reflection->getProperty($variable);
39
        if (preg_match('#@var\s+([\w\\\]+)#iu', $property->getDocComment(), $match)) {
40
            return $match[1];
41
        } else {
42
            return null;
43
        }
44
    }
45
}