Conditions | 4 |
Paths | 4 |
Total Lines | 62 |
Code Lines | 48 |
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 |
||
84 | public function persist(State $state): State { |
||
85 | switch ($state->getState()) { |
||
86 | case SmsProvider::STATE_DISABLED: |
||
87 | $this->deleteUserValue( |
||
88 | $state->getUser(), |
||
89 | $state->getGatewayName(), |
||
90 | 'verified' |
||
91 | ); |
||
92 | $this->deleteUserValue( |
||
93 | $state->getUser(), |
||
94 | $state->getGatewayName(), |
||
95 | 'verification_code' |
||
96 | ); |
||
97 | |||
98 | break; |
||
99 | case SmsProvider::STATE_VERIFYING: |
||
100 | $this->setUserValue( |
||
101 | $state->getUser(), |
||
102 | $state->getGatewayName(), |
||
103 | 'identifier', |
||
104 | $state->getIdentifier() |
||
105 | ); |
||
106 | $this->setUserValue( |
||
107 | $state->getUser(), |
||
108 | $state->getGatewayName(), |
||
109 | 'verification_code', |
||
110 | $state->getVerificationCode() |
||
111 | ); |
||
112 | $this->setUserValue( |
||
113 | $state->getUser(), |
||
114 | $state->getGatewayName(), |
||
115 | 'verified', |
||
116 | 'false' |
||
117 | ); |
||
118 | |||
119 | break; |
||
120 | case SmsProvider::STATE_ENABLED: |
||
121 | $this->setUserValue( |
||
122 | $state->getUser(), |
||
123 | $state->getGatewayName(), |
||
124 | 'identifier', |
||
125 | $state->getIdentifier() |
||
126 | ); |
||
127 | $this->setUserValue( |
||
128 | $state->getUser(), |
||
129 | $state->getGatewayName(), |
||
130 | 'verification_code', |
||
131 | $state->getVerificationCode() |
||
132 | ); |
||
133 | $this->setUserValue( |
||
134 | $state->getUser(), |
||
135 | $state->getGatewayName(), |
||
136 | 'verified', |
||
137 | 'true' |
||
138 | ); |
||
139 | |||
140 | break; |
||
141 | default: |
||
142 | throw new Exception('invalid provider state'); |
||
143 | } |
||
144 | |||
145 | return $state; |
||
146 | } |
||
148 |