| Conditions | 10 |
| Paths | 13 |
| Total Lines | 37 |
| Code Lines | 18 |
| 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 |
||
| 75 | private function addExpectHeader( |
||
| 76 | RequestInterface $request, |
||
| 77 | array $options, |
||
| 78 | array &$modify |
||
| 79 | ) { |
||
| 80 | // Determine if the Expect header should be used |
||
| 81 | if ($request->hasHeader('Expect')) { |
||
| 82 | return; |
||
| 83 | } |
||
| 84 | |||
| 85 | $expect = isset($options['expect']) ? $options['expect'] : null; |
||
| 86 | |||
| 87 | // Return if disabled or if you're not using HTTP/1.1 or HTTP/2.0 |
||
| 88 | if ($expect === false || $request->getProtocolVersion() < 1.1) { |
||
| 89 | return; |
||
| 90 | } |
||
| 91 | |||
| 92 | // The expect header is unconditionally enabled |
||
| 93 | if ($expect === true) { |
||
| 94 | $modify['set_headers']['Expect'] = '100-Continue'; |
||
| 95 | return; |
||
| 96 | } |
||
| 97 | |||
| 98 | // By default, send the expect header when the payload is > 1mb |
||
| 99 | if ($expect === null) { |
||
| 100 | $expect = 1048576; |
||
| 101 | } |
||
| 102 | |||
| 103 | // Always add if the body cannot be rewound, the size cannot be |
||
| 104 | // determined, or the size is greater than the cutoff threshold |
||
| 105 | $body = $request->getBody(); |
||
| 106 | $size = $body->getSize(); |
||
| 107 | |||
| 108 | if ($size === null || $size >= (int) $expect || !$body->isSeekable()) { |
||
| 109 | $modify['set_headers']['Expect'] = '100-Continue'; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 |