| Conditions | 10 |
| Paths | 16 |
| Total Lines | 40 |
| Code Lines | 28 |
| 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 declare(strict_types=1); |
||
| 84 | public function getBodyParams() |
||
| 85 | { |
||
| 86 | if ($this->_bodyParams === null) { |
||
| 87 | if (isset($_POST[$this->methodParam])) { |
||
| 88 | $this->_bodyParams = $_POST; |
||
| 89 | unset($this->_bodyParams[$this->methodParam]); |
||
| 90 | return $this->_bodyParams; |
||
| 91 | } |
||
| 92 | $rawContentType = $this->getContentType(); |
||
| 93 | if (($pos = strpos($rawContentType, ';')) !== false) { |
||
| 94 | // e.g. text/html; charset=UTF-8 |
||
| 95 | $contentType = substr($rawContentType, 0, $pos); |
||
| 96 | } else { |
||
| 97 | $contentType = $rawContentType; |
||
| 98 | } |
||
| 99 | if (isset($this->parsers[$contentType])) { |
||
| 100 | $parser = Yii::createObject($this->parsers[$contentType]); |
||
| 101 | if (!($parser instanceof RequestParserInterface)) { |
||
| 102 | throw new InvalidConfigException("The '$contentType' request parser is invalid. It must implement the yii\\web\\RequestParserInterface."); |
||
| 103 | } |
||
| 104 | $this->_bodyParams = $parser->parse($this->getRawBody(), $rawContentType); |
||
| 105 | if ($this->striposa($this->_ncryptfContentTypes, $rawContentType)) { |
||
| 106 | $this->_decryptedBody = $parser->getDecryptedBody(); |
||
|
|
|||
| 107 | } |
||
| 108 | } elseif (isset($this->parsers['*'])) { |
||
| 109 | $parser = Yii::createObject($this->parsers['*']); |
||
| 110 | if (!($parser instanceof RequestParserInterface)) { |
||
| 111 | throw new InvalidConfigException('The fallback request parser is invalid. It must implement the yii\\web\\RequestParserInterface.'); |
||
| 112 | } |
||
| 113 | $this->_bodyParams = $parser->parse($this->getRawBody(), $rawContentType); |
||
| 114 | } elseif ($this->getMethod() === 'POST') { |
||
| 115 | // PHP has already parsed the body so we have all params in $_POST |
||
| 116 | $this->_bodyParams = $_POST; |
||
| 117 | } else { |
||
| 118 | $this->_bodyParams = []; |
||
| 119 | mb_parse_str($this->getRawBody(), $this->_bodyParams); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | return $this->_bodyParams; |
||
| 124 | } |
||
| 126 |