Test Setup Failed
Push — master ( 2fcff1...d002d2 )
by Php Easy Api
03:19
created

Client::create()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 106
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 51
nc 64
nop 0
dl 0
loc 106
rs 8.1357
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Resta\Console\Source\Client;
4
5
use Resta\Support\Utils;
6
use Resta\Console\ConsoleOutputter;
7
use Resta\Console\ConsoleListAccessor;
8
use Resta\Foundation\PathManager\StaticPathModel;
9
use Resta\Support\Generator\Generator;
10
11
class Client extends ConsoleOutputter 
12
{
13
    use ConsoleListAccessor;
14
15
    /**
16
     * @var string
17
     */
18
    public $type = 'client';
19
20
    /**
21
     * @var array
22
     */
23
    protected $runnableMethods = [
24
        'create'=>'Creates request object'
25
    ];
26
27
    /**
28
     * @var bool
29
     */
30
    protected $projectStatus = true;
31
32
    /**
33
     * @var array
34
     */
35
    public $commandRule=['name','client'];
36
37
    /**
38
     * @method create
39
     * @return void|mixed
40
     */
41
    public function create()
42
    {
43
        $name = $this->argument['name'];
44
        $client = $this->argument['client'];
45
46
47
        $this->directory['clientNameCreate']        = path()->request();
48
        $this->argument['clientNameNamespace']      = Utils::getNamespace($this->directory['clientNameCreate']);
49
        $this->directory['clientNameDir']           = $this->directory['clientNameCreate'].'/'.$name;
50
        $this->argument['clientNameDirNamespace']  = Utils::getNamespace($this->directory['clientNameCreate'].'/'.$name);
51
        $this->directory['clientSource']            = $this->directory['clientNameDir'].'/'.$client;
52
        $this->argument['clientSourceNamespace']   = Utils::getNamespace($this->directory['clientNameDir'].'/'.$client.'');
53
54
        //set project directory
55
        $this->file->makeDirectory($this);
56
57
        if(!file_exists($manager = $this->directory['clientNameDir'].'/'.$name.'Manager.php')){
58
            $this->touch['client/manager'] = $manager;
59
        }
60
61
        if(!file_exists($this->directory['clientNameCreate'].'/Client.php')){
62
            $this->touch['client/client'] = $this->directory['clientNameCreate'].'/Client.php';
63
            $this->touch['client/clientGenerator'] = $this->directory['clientNameCreate'].'/ClientGenerator.php';
64
        }
65
66
        $clientSourceNamespace = Utils::getNamespace($this->directory['clientSource'].'/'.$client.'.php');
67
        
68
        if(!file_exists($clientSourceName = $this->directory['clientSource'].'/'.$client.'.php')){
69
            $this->touch['client/source'] = $clientSourceName.'';
70
            //$this->touch['client/sourcegenerator'] = $this->directory['clientSource'].'/'.$client.'Generator.php';
71
        }
72
73
        if(!file_exists($this->directory['clientNameCreate'].'/ClientProvider.php')){
74
            $this->touch['client/clientProvider'] = $this->directory['clientNameCreate'].'/ClientProvider.php';
75
        }
76
77
        $this->touch['client/clientGeneratorFile'] = $this->directory['clientSource'].'/'.$client.'Generator.php';
78
        
79
        
80
        //set project touch
81
        $this->file->touch($this);
82
        
83
        $nameManager = $name.'Manager';
84
85
        $nameGeneratorNamespace = Utils::getNamespace($this->directory['clientNameDir'].''.DIRECTORY_SEPARATOR.''.$nameManager.'.php');
86
        
87
        $generator = new Generator(path()->version(),'ClientManager');
88
        
89
        $clientManager = app()->namespace()->version().'\\ClientManager';
90
        
91
        $clientManagerResolve = new $clientManager;
92
        
93
        if(!method_exists($clientManagerResolve,strtolower($name))){
94
95
            $generator->createMethod([
96
                strtolower($name)
97
            ]);
98
            
99
            $generator->createClassUse([
100
                $nameGeneratorNamespace 
101
            ]);
102
            
103
            $generator->createMethodBody([
104
                strtolower($name) => 'return new '.$nameManager.'();'
105
            ]);
106
            
107
            $generator->createMethodDocument([
108
                strtolower($name) => [
109
                    '@return '.$nameManager.''
110
                ]
111
            ]);
112
            
113
        }
114
115
        $nameGenerator = new Generator($this->directory['clientNameDir'],$name.'Manager');
116
        
117
        $nameGeneratorNamespaceResolve = new $nameGeneratorNamespace;
118
119
        if(!method_exists($nameGeneratorNamespaceResolve,strtolower($client))){
120
121
            $nameGenerator->createMethod([
122
                strtolower($client)
123
            ]);
124
125
            $nameGenerator->createMethodBody([
126
                strtolower($client) => 'return new '.$client.'();'
127
            ]);
128
129
            $nameGenerator->createMethodDocument([
130
                strtolower($client) => [
131
                    '@return '.$client.'',
132
                    '',
133
                    '@throws ReflectionException'
134
                ]
135
            ]);
136
137
138
            $nameGenerator->createClassUse([
139
                $clientSourceNamespace
140
            ]);
141
           
142
        }
143
144
145
        
146
        echo $this->classical(' > Client called as "'.$client.'" has been successfully created in the '.app()->namespace()->request().'');
147
    }
148
}