ResponseAbstract::formOutputPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace carono\turbotext\codegen;
4
5
use carono\codegen\ClassGenerator;
6
7
class ResponseAbstract extends ClassGenerator
8
{
9
    public $properties = [];
10
11
    protected function formExtends()
12
    {
13
        if (strpos($this->formClassName(), 'ElementResponse')) {
14
            return 'carono\turbotext\ArrayObject';
15
        }
16
17
        return 'carono\turbotext\ResponseAbstract';
18
    }
19
20
    protected function formClassName()
21
    {
22
        $name = $this->params['name'];
23
        $name = formClassName($name);
24
        if (!isset($this->params['result']) && substr($name, -1, 1) == 's') {
25
            $name = substr($name, 0, -1) . 'Element';
26
        }
27
        return $name . 'Response';
28
    }
29
30
    protected function formClassNamespace()
31
    {
32
        return 'carono\turbotext\response';
33
    }
34
35
    protected function formOutputPath()
36
    {
37
        return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'response' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php';
38
    }
39
40
    protected function classProperties()
41
    {
42
        $properties = [];
43
        if (isset($this->params['result'])) {
44
            $properties = [
45
                '_responseClasses' => [
46
                    'value' => [],
47
                    'visibility' => 'protected'
48
                ]
49
            ];
50
            $element = new self();
51
            $params = $this->params['result'];
52
            $params['name'] = $this->params['name'];
53
            $element->renderToFile($params);
54
            $varClass = $element->formClassName();
55
            $properties['_responseClasses']['value'][$this->params['name']] = 'carono\turbotext\response\\' . $varClass;
56
            $properties[$this->params['name']] = [
57
                'value' => [],
58
                'comment' => [
59
                    stripAndWordWrap($this->params['description']),
60
                    "@var {$varClass}[]"
61
                ]
62
            ];
63
        } else {
64
            foreach ($this->params as $param) {
65
                if (is_string($param)) {
66
                    continue;
67
                }
68
                $properties[$param['name']] = [
69
                    'comment' => [
70
                        stripAndWordWrap($param['description']),
71
                        '@var ' . formParamType($param['type'])
72
                    ]
73
                ];
74
            }
75
        }
76
        return $properties;
77
    }
78
79
}