Conditions | 7 |
Paths | 64 |
Total Lines | 106 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | } |