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