| Conditions | 29 |
| Paths | 29 |
| Total Lines | 100 |
| Code Lines | 75 |
| Lines | 24 |
| Ratio | 24 % |
| 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 |
||
| 53 | public function handleCommand($command, $data = null) |
||
| 54 | { |
||
| 55 | switch (strtolower($command)) { |
||
| 56 | // string |
||
| 57 | case 'summary': |
||
| 58 | case 'description': |
||
| 59 | $this->$command = $data; |
||
| 60 | return $this; |
||
| 61 | |||
| 62 | // string[] |
||
| 63 | case 'tags': |
||
| 64 | case 'schemes': |
||
| 65 | $this->$command = array_merge($this->$command, self::wordSplit($data)); |
||
| 66 | return $this; |
||
| 67 | |||
| 68 | // MIME[] |
||
| 69 | case 'consumes': |
||
| 70 | View Code Duplication | case 'produces': |
|
| 71 | $this->$command = array_merge($this->$command, self::translateMimeTypes(self::wordSplit($data))); |
||
| 72 | return $this; |
||
| 73 | |||
| 74 | // boolean |
||
| 75 | case 'deprecated': |
||
| 76 | $this->deprecated = true; |
||
| 77 | return $this; |
||
| 78 | |||
| 79 | View Code Duplication | case 'error': |
|
| 80 | $code = self::wordShift($data); |
||
| 81 | $reasoncode = Response::getCode($code); |
||
| 82 | if ($reasoncode === null) { |
||
| 83 | throw new \SwaggerGen\Exception("Invalid error code: '$code'"); |
||
| 84 | } |
||
| 85 | $description = $data; |
||
| 86 | $Error = new Error($this, $reasoncode, $description); |
||
| 87 | $this->responses[$reasoncode] = $Error; |
||
| 88 | return $Error; |
||
| 89 | |||
| 90 | case 'errors': |
||
| 91 | foreach (self::wordSplit($data) as $code) { |
||
| 92 | $reasoncode = Response::getCode($code); |
||
| 93 | if ($reasoncode === null) { |
||
| 94 | throw new \SwaggerGen\Exception("Invalid error code: '$code'"); |
||
| 95 | } |
||
| 96 | $this->responses[$reasoncode] = new Error($this, $reasoncode); |
||
| 97 | } |
||
| 98 | return $this; |
||
| 99 | |||
| 100 | case 'path': |
||
| 101 | case 'query': |
||
| 102 | case 'query?': |
||
| 103 | case 'header': |
||
| 104 | case 'header?': |
||
| 105 | case 'form': |
||
| 106 | case 'form?': |
||
| 107 | $in = rtrim($command, '?'); |
||
| 108 | $Parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?'); |
||
| 109 | $this->parameters[$Parameter->getName()] = $Parameter; |
||
| 110 | return $Parameter; |
||
| 111 | |||
| 112 | case 'body': |
||
| 113 | case 'body?': |
||
| 114 | $Parameter = new BodyParameter($this, $data, substr($command, -1) !== '?'); |
||
| 115 | $this->parameters[$Parameter->getName()] = $Parameter; |
||
| 116 | return $Parameter; |
||
| 117 | |||
| 118 | case 'response': |
||
| 119 | $code = self::wordShift($data); |
||
| 120 | $reasoncode = Response::getCode($code); |
||
| 121 | if ($reasoncode === null) { |
||
| 122 | throw new \SwaggerGen\Exception("Invalid response code: '$code'"); |
||
| 123 | } |
||
| 124 | $definition = self::wordShift($data); |
||
| 125 | $description = $data; |
||
| 126 | $Response = new Response($this, $reasoncode, $definition, $description); |
||
| 127 | $this->responses[$reasoncode] = $Response; |
||
| 128 | return $Response; |
||
| 129 | |||
| 130 | View Code Duplication | case 'require': |
|
| 131 | $name = self::wordShift($data); |
||
| 132 | if (empty($name)) { |
||
| 133 | throw new \SwaggerGen\Exception('Empty security requirement name'); |
||
| 134 | } |
||
| 135 | $scopes = self::wordSplit($data); |
||
| 136 | sort($scopes); |
||
| 137 | $this->security[] = array( |
||
| 138 | $name => empty($scopes) ? array() : $scopes, |
||
| 139 | ); |
||
| 140 | return $this; |
||
| 141 | |||
| 142 | case 'id': |
||
| 143 | $operationId = self::trim($data); |
||
| 144 | if ($this->getSwagger()->hasOperationId($operationId)) { |
||
| 145 | throw new \SwaggerGen\Exception("Duplicate operation id '{$operationId}'"); |
||
| 146 | } |
||
| 147 | $this->operationId = $operationId; |
||
| 148 | return $this; |
||
| 149 | } |
||
| 150 | |||
| 151 | return parent::handleCommand($command, $data); |
||
| 152 | } |
||
| 153 | |||
| 214 |
This check marks private properties in classes that are never used. Those properties can be removed.