Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 21 | class Delivery extends JsonObject |
||
| 22 | { |
||
| 23 | const NOTIFICATION_TYPE = 'notificationType'; |
||
| 24 | const TYPE_MESSAGE = 'Message'; |
||
| 25 | const TYPE_RESOURCE_CREATED = 'ResourceCreated'; |
||
| 26 | const TYPE_RESOURCE_UPDATED = 'ResourceUpdated'; |
||
| 27 | const TYPE_RESOURCE_DELETED = 'ResourceDeleted'; |
||
| 28 | |||
| 29 | 5 | public function fieldDefinitions() |
|
| 30 | { |
||
| 31 | return [ |
||
| 32 | 5 | 'projectKey' => [static::TYPE => 'string'], |
|
| 33 | 5 | static::NOTIFICATION_TYPE => [static::TYPE => 'string'], |
|
| 34 | 5 | 'resource' => [static::TYPE => Reference::class], |
|
| 35 | ]; |
||
| 36 | } |
||
| 37 | |||
| 38 | 5 | protected static function destinationType($typeId) |
|
| 48 | |||
| 49 | 5 | View Code Duplication | public static function fromArray(array $data, $context = null) |
| 61 | } |
||
| 62 |
This check looks for accesses to local static members using the fully qualified name instead of
self::.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBCcould just as well be replaced byself::TRIPLEDES_CBC. Referencing local members withself::assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.