Conditions | 27 |
Paths | 27 |
Total Lines | 90 |
Code Lines | 65 |
Lines | 17 |
Ratio | 18.89 % |
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 |
||
48 | public function handleCommand($command, $data = null) |
||
49 | { |
||
50 | switch (strtolower($command)) { |
||
51 | // string |
||
52 | case 'summary': |
||
53 | case 'description': |
||
54 | $this->$command = $data; |
||
55 | return $this; |
||
56 | |||
57 | // string[] |
||
58 | case 'tags': |
||
59 | View Code Duplication | case 'schemes': |
|
|
|||
60 | $this->$command = array_merge($this->$command, self::wordSplit($data)); |
||
61 | return $this; |
||
62 | |||
63 | // MIME[] |
||
64 | case 'consumes': |
||
65 | View Code Duplication | case 'produces': |
|
66 | $this->$command = array_merge($this->$command, self::translateMimeTypes(self::wordSplit($data))); |
||
67 | return $this; |
||
68 | |||
69 | // boolean |
||
70 | case 'deprecated': |
||
71 | $this->deprecated = true; |
||
72 | return $this; |
||
73 | |||
74 | case 'error': |
||
75 | $code = self::wordShift($data); |
||
76 | $reasoncode = Response::getCode($code); |
||
77 | if ($reasoncode === null) { |
||
78 | throw new \SwaggerGen\Exception("Invalid error code: '$code'"); |
||
79 | } |
||
80 | $description = $data; |
||
81 | $Error = new Error($this, $reasoncode, $description); |
||
82 | $this->responses[$reasoncode] = $Error; |
||
83 | return $Error; |
||
84 | |||
85 | case 'errors': |
||
86 | foreach (self::wordSplit($data) as $code) { |
||
87 | $reasoncode = Response::getCode($code); |
||
88 | if ($reasoncode === null) { |
||
89 | throw new \SwaggerGen\Exception("Invalid error code: '$code'"); |
||
90 | } |
||
91 | $this->responses[$reasoncode] = new Error($this, $reasoncode); |
||
92 | } |
||
93 | return $this; |
||
94 | |||
95 | case 'path': |
||
96 | case 'query': case 'query?': |
||
97 | case 'header': case 'header?': |
||
98 | case 'form': case 'form?': |
||
99 | $in = rtrim($command, '?'); |
||
100 | $Parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?'); |
||
101 | $this->parameters[$Parameter->getName()] = $Parameter; |
||
102 | return $Parameter; |
||
103 | |||
104 | case 'body': case 'body?': |
||
105 | $Parameter = new BodyParameter($this, $data, substr($command, -1) !== '?'); |
||
106 | $this->parameters[$Parameter->getName()] = $Parameter; |
||
107 | return $Parameter; |
||
108 | |||
109 | case 'response': |
||
110 | $code = self::wordShift($data); |
||
111 | $reasoncode = Response::getCode($code); |
||
112 | if ($reasoncode === null) { |
||
113 | throw new \SwaggerGen\Exception("Invalid response code: '$code'"); |
||
114 | } |
||
115 | $definition = self::wordShift($data); |
||
116 | $description = $data; |
||
117 | $Response = new Response($this, $reasoncode, $definition, $description); |
||
118 | $this->responses[$reasoncode] = $Response; |
||
119 | return $Response; |
||
120 | |||
121 | View Code Duplication | case 'require': |
|
122 | $name = self::wordShift($data); |
||
123 | if (empty($name)) { |
||
124 | throw new \SwaggerGen\Exception('Empty security requirement name'); |
||
125 | } |
||
126 | $scopes = self::wordSplit($data); |
||
127 | sort($scopes); |
||
128 | $this->security[] = array( |
||
129 | $name => empty($scopes) ? array() : $scopes, |
||
130 | ); |
||
131 | return $this; |
||
132 | |||
133 | //@todo operationId |
||
134 | } |
||
135 | |||
136 | return parent::handleCommand($command, $data); |
||
137 | } |
||
138 | |||
189 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.