Complex classes like Request often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Request, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | final class Request implements RequestInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var ServerRequestCreatorInterface|null |
||
| 18 | */ |
||
| 19 | private static $serverRequestCreator = null; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var int |
||
| 23 | */ |
||
| 24 | private static $bufferSize = 10485760; // 10 MB |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private static $uploadDir = null; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $uploadedFiles = []; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | private $params; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var resource |
||
| 43 | */ |
||
| 44 | private $stdin; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Constructor. |
||
| 48 | * |
||
| 49 | * @param array $params The FastCGI server params as an associative array |
||
| 50 | * @param resource $stdin The FastCGI stdin data as a stream resource |
||
| 51 | */ |
||
| 52 | public function __construct(array $params, $stdin) |
||
| 64 | |||
| 65 | public static function setServerRequestCreator(ServerRequestCreatorInterface $serverRequestCreator): void |
||
| 69 | |||
| 70 | /** |
||
| 71 | * {@inheritdoc} |
||
| 72 | */ |
||
| 73 | public function getParams(): array |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Remove all uploaded files |
||
| 80 | */ |
||
| 81 | public function cleanUploadedFiles(): void |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Set a buffer size to read uploaded files |
||
| 90 | */ |
||
| 91 | public static function setBufferSize(int $size): void |
||
| 95 | |||
| 96 | public static function getBufferSize(): int |
||
| 100 | |||
| 101 | public static function setUploadDir(string $dir): void |
||
| 105 | |||
| 106 | public static function getUploadDir(): string |
||
| 110 | |||
| 111 | /** |
||
| 112 | * {@inheritdoc} |
||
| 113 | */ |
||
| 114 | public function getQuery(): array |
||
| 124 | |||
| 125 | /** |
||
| 126 | * {@inheritdoc} |
||
| 127 | */ |
||
| 128 | public function getPost(): array |
||
| 155 | |||
| 156 | private function parseMultipartFormData($stream, string $boundary): array { |
||
| 210 | |||
| 211 | /** |
||
| 212 | * {@inheritdoc} |
||
| 213 | */ |
||
| 214 | public function getCookies(): array |
||
| 229 | |||
| 230 | /** |
||
| 231 | * {@inheritdoc} |
||
| 232 | */ |
||
| 233 | public function getStdin() |
||
| 237 | |||
| 238 | /** |
||
| 239 | * {@inheritdoc} |
||
| 240 | */ |
||
| 241 | public function getServerRequest(): ServerRequestInterface |
||
| 264 | |||
| 265 | /** |
||
| 266 | * {@inheritdoc} |
||
| 267 | */ |
||
| 268 | public function getHttpFoundationRequest(): HttpFoundationRequest |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Add a file to the $files array |
||
| 283 | */ |
||
| 284 | private function addFile(array &$files, string $fieldName, string $filename, string $tmpPath, string $mimeType, bool $err): void |
||
| 315 | } |
||
| 316 |
If you suppress an error, we recommend checking for the error condition explicitly: