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 |
||
| 19 | class TestPermissionNode extends DataObject implements TestOnly |
||
| 20 | { |
||
| 21 | private static $db = [ |
||
|
|
|||
| 22 | "Title" => "Varchar(255)", |
||
| 23 | ]; |
||
| 24 | |||
| 25 | private static $has_one = [ |
||
| 26 | "Parent" => self::class, |
||
| 27 | ]; |
||
| 28 | |||
| 29 | private static $table_name = 'InheritedPermissionsTest_TestPermissionNode'; |
||
| 30 | |||
| 31 | private static $extensions = [ |
||
| 32 | Versioned::class, |
||
| 33 | InheritedPermissionsExtension::class, |
||
| 34 | ]; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @return InheritedPermissions |
||
| 38 | */ |
||
| 39 | public static function getInheritedPermissions() |
||
| 44 | |||
| 45 | View Code Duplication | public function canEdit($member = null) |
|
| 52 | |||
| 53 | View Code Duplication | public function canView($member = null) |
|
| 60 | |||
| 61 | View Code Duplication | public function canDelete($member = null) |
|
| 68 | } |
||
| 69 |