Conditions | 14 |
Paths | 9 |
Total Lines | 51 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
59 | public function __construct( |
||
60 | $requestId, |
||
61 | $type, |
||
62 | $createdAt, |
||
63 | $verificationVideo = null, |
||
64 | $faceProof = null, |
||
65 | $documentProof = null, |
||
66 | $documentTwoProof = null, |
||
67 | $consentProof = null |
||
68 | |||
69 | ) { |
||
70 | if (!is_int($requestId)) { |
||
71 | throw new \InvalidArgumentException('Request ID must be integer'); |
||
72 | } |
||
73 | |||
74 | if (!is_string($type)) { |
||
75 | throw new \InvalidArgumentException('Type must be string'); |
||
76 | } |
||
77 | |||
78 | if (!is_int($createdAt)) { |
||
79 | throw new \InvalidArgumentException('Created At must be integer'); |
||
80 | } |
||
81 | |||
82 | if ($verificationVideo !== null && !is_string($verificationVideo)) { |
||
83 | throw new \InvalidArgumentException('Verification Video must be string'); |
||
84 | } |
||
85 | |||
86 | if ($faceProof !== null && !is_string($faceProof)) { |
||
87 | throw new \InvalidArgumentException('Face Proof must be string'); |
||
88 | } |
||
89 | |||
90 | if ($documentProof !== null && !is_string($documentProof)) { |
||
91 | throw new \InvalidArgumentException('Document Proof must be string'); |
||
92 | } |
||
93 | |||
94 | if ($documentTwoProof !== null && !is_string($documentTwoProof)) { |
||
95 | throw new \InvalidArgumentException('Document Two Proof must be string'); |
||
96 | } |
||
97 | |||
98 | if ($consentProof !== null && !is_string($consentProof)) { |
||
99 | throw new \InvalidArgumentException('Consent Proof must be string'); |
||
100 | } |
||
101 | $this->requestId = $requestId; |
||
102 | $this->type = $type; |
||
103 | $this->createdAt = $createdAt; |
||
104 | $this->verificationVideo = $verificationVideo; |
||
105 | $this->faceProof = $faceProof; |
||
106 | $this->documentProof = $documentProof; |
||
107 | $this->documentTwoProof = $documentTwoProof; |
||
108 | $this->consentProof = $consentProof; |
||
109 | } |
||
110 | |||
177 |