TestingController::actionIndex()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 25
rs 9.5222
1
<?php
2
3
4
namespace carono\exchange1c\controllers;
5
6
7
use carono\exchange1c\models\TestingClass;
8
9
class TestingController extends Controller
10
{
11
    /**
12
     * @param null $class
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $class is correct as it would always require null to be passed?
Loading history...
13
     * @param null $result
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $result is correct as it would always require null to be passed?
Loading history...
14
     * @return string
15
     * @throws \Exception
16
     */
17
    public function actionIndex($class = null, $result = null)
18
    {
19
        /**
20
         * @var TestingClass $testingClass
21
         * @var TestingClass $resultClass
22
         */
23
        $testingClass = null;
24
        $resultClass = null;
25
        if ($class) {
0 ignored issues
show
introduced by
$class is of type null, thus it always evaluated to false.
Loading history...
26
            $className = 'carono\exchange1c\models\\' . $class;
27
            if (class_exists($className)) {
28
                $testingClass = new $className();
29
            } else {
30
                throw new \Exception("Class $className not found");
31
            }
32
33
            if ($testingClass::testImplementsClass()->hasErrors()) {
34
                throw new \Exception('Ошибки реализации интерфейсов.');
35
            }
36
37
            if ($result) {
38
                $resultClass = new $className(['method' => $result]);
39
            }
40
        }
41
        return $this->render('index', ['testingClass' => $testingClass, 'resultClass' => $resultClass]);
42
    }
43
}