Conditions | 10 |
Paths | 16 |
Total Lines | 39 |
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 |
||
39 | public function getBodyParams() |
||
40 | { |
||
41 | if ($this->_bodyParams === null) { |
||
42 | if (isset($_POST[$this->methodParam])) { |
||
43 | $this->_bodyParams = $_POST; |
||
44 | unset($this->_bodyParams[$this->methodParam]); |
||
45 | return $this->_bodyParams; |
||
46 | } |
||
47 | $rawContentType = $this->getContentType(); |
||
48 | if (($pos = strpos($rawContentType, ';')) !== false) { |
||
49 | // e.g. text/html; charset=UTF-8 |
||
50 | $contentType = substr($rawContentType, 0, $pos); |
||
51 | } else { |
||
52 | $contentType = $rawContentType; |
||
53 | } |
||
54 | if (isset($this->parsers[$contentType])) { |
||
55 | $parser = Yii::createObject($this->parsers[$contentType]); |
||
56 | if (!($parser instanceof RequestParserInterface)) { |
||
57 | throw new InvalidConfigException("The '$contentType' request parser is invalid. It must implement the yii\\web\\RequestParserInterface."); |
||
58 | } |
||
59 | $this->_bodyParams = $parser->parse($this->getRawBody(), $rawContentType); |
||
60 | if ($rawContentType === 'application/vnd.25519+json') { |
||
61 | $this->_decryptedBody = $parser->getDecryptedBody(); |
||
|
|||
62 | } |
||
63 | } elseif (isset($this->parsers['*'])) { |
||
64 | $parser = Yii::createObject($this->parsers['*']); |
||
65 | if (!($parser instanceof RequestParserInterface)) { |
||
66 | throw new InvalidConfigException('The fallback request parser is invalid. It must implement the yii\\web\\RequestParserInterface.'); |
||
67 | } |
||
68 | $this->_bodyParams = $parser->parse($this->getRawBody(), $rawContentType); |
||
69 | } elseif ($this->getMethod() === 'POST') { |
||
70 | // PHP has already parsed the body so we have all params in $_POST |
||
71 | $this->_bodyParams = $_POST; |
||
72 | } else { |
||
73 | $this->_bodyParams = []; |
||
74 | mb_parse_str($this->getRawBody(), $this->_bodyParams); |
||
75 | } |
||
76 | } |
||
77 | return $this->_bodyParams; |
||
78 | } |
||
80 |