| Conditions | 7 |
| Paths | 6 |
| Total Lines | 55 |
| Code Lines | 45 |
| 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 |
||
| 97 | private static function getExceptionMessage($statusCode, $subCode = null, $field = null) |
||
| 98 | { |
||
| 99 | $codes = [ |
||
| 100 | self::STATUS_NO_DATA => |
||
| 101 | 'There is no data available (in response to an action that would normally result in returning data). ' . |
||
| 102 | 'Usually indicates that there is no item with the ID you specified. ' . |
||
| 103 | 'To resolve the error, change the specified ID to that of an item that exists.', |
||
| 104 | self::STATUS_TOO_MUCH_DATA => 'The action should have returned a single result but is actually returning ' . |
||
| 105 | 'multiple results. For example, if there are multiple users with the same user name and password, ' . |
||
| 106 | 'and you call the login action using that user name and password as parameters, ' . |
||
| 107 | 'the system cannot determine which user to log you in as, so it returns a too-much-data error.', |
||
| 108 | self::STATUS_NO_ACCESS => [ |
||
| 109 | 'account-expired' => 'The account has expired.', |
||
| 110 | 'denied' => 'Based on the supplied credentials, you don’t have permission to call the action.', |
||
| 111 | 'no-login' => 'The user is not logged in. To resolve the error, log in (using the login action) ' . |
||
| 112 | 'before you make the call.', |
||
| 113 | 'illegalparent' => 'The specified acl - id is not a seminar or an unknown issue occured while ' . |
||
| 114 | 'retrieving the quota for that seminar.', |
||
| 115 | 'no-quota' => 'The account limits have been reached or exceeded.', |
||
| 116 | 'not-available' => 'The required resource is unavailable.', |
||
| 117 | 'not-secure' => 'You must use SSL to call this action.', |
||
| 118 | 'pending-activation' => 'The account is not yet activated.', |
||
| 119 | 'pending-license' => 'The account’s license agreement has not been settled.', |
||
| 120 | 'sco-expired' => 'The course or tracking content has expired.', |
||
| 121 | 'sco-not-started' => 'The meeting or course has not started.', |
||
| 122 | 'valuelessthanorequal' => 'Value is not a valid integer or is greater than the allowed license quota ' . |
||
| 123 | 'for that seminar.', |
||
| 124 | ], |
||
| 125 | self::STATUS_INVALID => [ |
||
| 126 | 'duplicate' => 'The call attempted to add a duplicate item on %s in a context where uniqueness is ' . |
||
| 127 | 'required.', |
||
| 128 | 'format' => 'passed %s parameter had the wrong format.', |
||
| 129 | 'illegal-operation' => 'The requested operation on %s violates integrity rules ' . |
||
| 130 | '(for example, moving a folder into itself).', |
||
| 131 | 'missing' => 'A required parameter %s is missing.', |
||
| 132 | 'no-such-item' => 'The requested %s does not exist.', |
||
| 133 | 'range' => 'The value of %s is outside the permitted range of values.' |
||
| 134 | ] |
||
| 135 | ]; |
||
| 136 | |||
| 137 | //this statement will check for any unknown subcodes if any subcodes provided |
||
| 138 | // and if any unknown provided, it'll return default error message! |
||
| 139 | if ($subCode && !isset($codes[$statusCode][$field])) { |
||
| 140 | return "{$statusCode} - {$subCode} - {$field}"; |
||
| 141 | } |
||
| 142 | |||
| 143 | switch ($statusCode) { |
||
| 144 | case self::STATUS_INVALID: |
||
| 145 | return sprintf($codes[self::STATUS_INVALID][$subCode], $field); |
||
| 146 | case self::STATUS_NO_ACCESS: |
||
| 147 | return $codes[self::STATUS_NO_ACCESS][$subCode]; |
||
| 148 | case self::STATUS_NO_DATA: |
||
| 149 | return $codes[self::STATUS_NO_DATA]; |
||
| 150 | case self::STATUS_TOO_MUCH_DATA: |
||
| 151 | return $codes[self::STATUS_TOO_MUCH_DATA]; |
||
| 152 | } |
||
| 155 |