Conditions | 9 |
Paths | 96 |
Total Lines | 52 |
Code Lines | 31 |
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 |
||
80 | private function updateConfig() |
||
81 | { |
||
82 | $data = static::config()->get('data'); |
||
83 | $transactionDate = $data['TransactionDate']; |
||
84 | static::config()->merge('data', [ |
||
85 | 'TransactionDate' => strtotime($transactionDate), |
||
86 | ]); |
||
87 | |||
88 | $orderID = $data['OrderID']; |
||
89 | if ($orderID === 'auto' || $orderID < 1) { |
||
90 | $lastOrderID = 0; |
||
91 | if ($lastOrder = Order::get()->sort('OrderID')->last()) { |
||
92 | $lastOrderID = $lastOrder->OrderID; |
||
93 | }; |
||
94 | static::config()->merge('data', [ |
||
95 | 'OrderID' => $lastOrderID + 1, |
||
96 | ]); |
||
97 | } |
||
98 | |||
99 | $email = $data['Email']; |
||
100 | if ($email === 'auto') { |
||
101 | static::config()->merge('data', [ |
||
102 | 'Email' => $this->generateEmail(), |
||
103 | ]); |
||
104 | } |
||
105 | |||
106 | $orderDetails = $data['OrderDetails']; |
||
107 | if (count($orderDetails) === 0) { |
||
108 | static::config()->merge('data', [ |
||
109 | 'OrderDetails' => [ |
||
110 | $this->generateOrderDetail() |
||
111 | ], |
||
112 | ]); |
||
113 | } |
||
114 | |||
115 | if (!array_key_exists('Salt', $data)) { |
||
116 | static::config()->merge('data', [ |
||
117 | 'Salt' => 'faGgWXUTdZ7i42lpA6cljzKeGBeUwShBSNHECwsJmt', |
||
118 | ]); |
||
119 | } |
||
120 | |||
121 | if (!array_key_exists('HashType', $data)) { |
||
122 | static::config()->merge('data', [ |
||
123 | 'HashType' => 'sha1_v2.4', |
||
124 | ]); |
||
125 | } |
||
126 | |||
127 | $data = static::config()->get('data'); |
||
128 | if (!array_key_exists('HashedPassword', $data)) { |
||
129 | $encryptor = PasswordEncryptor::create_for_algorithm($data['HashType']); |
||
130 | static::config()->merge('data', [ |
||
131 | 'HashedPassword' => $encryptor->encrypt($data['Password'], $data['Salt']), |
||
132 | ]); |
||
214 |