Passed
Push — master ( 99d842...264ba0 )
by Aleksandr
01:33
created

Testing::module()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace carono\exchange1c\models;
5
6
7
use yii\base\Model;
8
use yii\base\Module;
9
use yii\helpers\ArrayHelper;
10
use yii\helpers\StringHelper;
11
12
/**
13
 * Class Testing
14
 *
15
 * @package carono\exchange1c\models
16
 */
17
abstract class Testing extends Model
18
{
19
    public $name;
20
    public $method;
21
    public $comment;
22
    protected $_result;
23
24
    /**
25
     * @return \carono\exchange1c\ExchangeModule|Module
26
     */
27
    public static function module()
28
    {
29
        return \Yii::$app->controller->module;
30
    }
31
32
    /**
33
     * @return array
34
     */
35
    public static function findAll()
36
    {
37
        $reflection = new \ReflectionClass(static::class);
38
        $methods = $reflection->getMethods(\ReflectionMethod::IS_STATIC);
39
        $methods = ArrayHelper::map(array_filter($methods, function ($data) {
40
            return StringHelper::startsWith($data->name, 'test');
41
        }), 'name', 'name');
42
        $data = [];
43
        foreach ($methods as $method) {
44
            if ($test = call_user_func(static::class . "::$method")) {
45
                $data[] = $test;
46
            }
47
        }
48
        return $data;
49
    }
50
51
    /**
52
     * @return bool
53
     */
54
    public function testing()
55
    {
56
        return !$this->hasErrors();
57
    }
58
59
    /**
60
     * Testing constructor.
61
     *
62
     * @param array $config
63
     */
64
    public function __construct(array $config = [])
65
    {
66
        parent::__construct($config);
67
    }
68
}