| Conditions | 15 |
| Paths | 15 |
| Total Lines | 58 |
| Code Lines | 29 |
| 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 |
||
| 82 | public function getReason(): ?int { |
||
| 83 | /** |
||
| 84 | * Constraint errors |
||
| 85 | */ |
||
| 86 | if ($this->original instanceof ForeignKeyConstraintViolationException) { |
||
| 87 | return parent::REASON_FOREIGN_KEY_VIOLATION; |
||
| 88 | } |
||
| 89 | if ($this->original instanceof NotNullConstraintViolationException) { |
||
| 90 | return parent::REASON_NOT_NULL_CONSTRAINT_VIOLATION; |
||
| 91 | } |
||
| 92 | if ($this->original instanceof UniqueConstraintViolationException) { |
||
| 93 | return parent::REASON_UNIQUE_CONSTRAINT_VIOLATION; |
||
| 94 | } |
||
| 95 | // The base exception comes last |
||
| 96 | if ($this->original instanceof ConstraintViolationException) { |
||
| 97 | return parent::REASON_CONSTRAINT_VIOLATION; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Other server errors |
||
| 102 | */ |
||
| 103 | if ($this->original instanceof DatabaseObjectExistsException) { |
||
| 104 | return parent::REASON_DATABASE_OBJECT_EXISTS; |
||
| 105 | } |
||
| 106 | if ($this->original instanceof DatabaseObjectNotFoundException) { |
||
| 107 | return parent::REASON_DATABASE_OBJECT_NOT_FOUND; |
||
| 108 | } |
||
| 109 | if ($this->original instanceof DeadlockException) { |
||
| 110 | return parent::REASON_DEADLOCK; |
||
| 111 | } |
||
| 112 | if ($this->original instanceof InvalidFieldNameException) { |
||
| 113 | return parent::REASON_INVALID_FIELD_NAME; |
||
| 114 | } |
||
| 115 | if ($this->original instanceof NonUniqueFieldNameException) { |
||
| 116 | return parent::REASON_NON_UNIQUE_FIELD_NAME; |
||
| 117 | } |
||
| 118 | if ($this->original instanceof SyntaxErrorException) { |
||
| 119 | return parent::REASON_SYNTAX_ERROR; |
||
| 120 | } |
||
| 121 | // The base server exception class comes last |
||
| 122 | if ($this->original instanceof ServerException) { |
||
| 123 | return parent::REASON_SERVER; |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Generic errors |
||
| 128 | */ |
||
| 129 | if ($this->original instanceof ConnectionException) { |
||
| 130 | return parent::REASON_CONNECTION_LOST; |
||
| 131 | } |
||
| 132 | if ($this->original instanceof InvalidArgumentException) { |
||
| 133 | return parent::REASON_INVALID_ARGUMENT; |
||
| 134 | } |
||
| 135 | if ($this->original instanceof DriverException) { |
||
| 136 | return parent::REASON_DRIVER; |
||
| 137 | } |
||
| 138 | |||
| 139 | return null; |
||
| 140 | } |
||
| 142 |