Conditions | 10 |
Paths | 9 |
Total Lines | 45 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
54 | public function __construct( |
||
55 | string $tempFile, |
||
56 | int $fileSize, |
||
57 | int $errorStatus, |
||
58 | string $clientFilename = null, |
||
59 | string $clientMediaType = null |
||
60 | ) { |
||
61 | if ($errorStatus === UPLOAD_ERR_OK) { |
||
62 | if (false === file_exists($tempFile)) { |
||
63 | throw new InvalidArgumentException( |
||
64 | 'Temp File does not exists' |
||
65 | ); |
||
66 | } |
||
67 | |||
68 | $this->file = $tempFile; |
||
69 | $this->fileSize = $fileSize; |
||
70 | } |
||
71 | |||
72 | if (false === is_int($errorStatus) |
||
73 | || 0 > $errorStatus |
||
74 | || 8 < $errorStatus |
||
75 | ) { |
||
76 | throw new InvalidArgumentException( |
||
77 | 'Invalid error status for UploadedFile; must be an UPLOAD_ERR_* constant' |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | $this->error = $errorStatus; |
||
82 | |||
83 | if (null !== $clientFilename && false === is_string($clientFilename)) { |
||
84 | throw new InvalidArgumentException( |
||
85 | 'Invalid client filename provided for UploadedFile; must be null or a string' |
||
86 | ); |
||
87 | } |
||
88 | |||
89 | $this->clientFilename = $clientFilename; |
||
90 | |||
91 | if (null !== $clientMediaType && false === is_string($clientMediaType)) { |
||
92 | throw new InvalidArgumentException( |
||
93 | 'Invalid client media type provided for UploadedFile; must be null or a string' |
||
94 | ); |
||
95 | } |
||
96 | |||
97 | $this->clientMediaType = $clientMediaType; |
||
98 | } |
||
99 | |||
201 |