We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
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 |
||
| 9 | class CrudPanelCreateTest extends BaseDBCrudPanelTest |
||
| 10 | { |
||
| 11 | private $nonRelationshipField = [ |
||
| 12 | 'name' => 'field1', |
||
| 13 | 'label' => 'Field1', |
||
| 14 | ]; |
||
| 15 | |||
| 16 | private $userInputFieldsNoRelationships = [ |
||
| 17 | [ |
||
| 18 | 'name' => 'id', |
||
| 19 | 'type' => 'hidden', |
||
| 20 | ], [ |
||
| 21 | 'name' => 'name', |
||
| 22 | ], [ |
||
| 23 | 'name' => 'email', |
||
| 24 | 'type' => 'email', |
||
| 25 | ], [ |
||
| 26 | 'name' => 'password', |
||
| 27 | 'type' => 'password', |
||
| 28 | ], |
||
| 29 | ]; |
||
| 30 | |||
| 31 | private $articleInputFieldsOneToMany = [ |
||
| 32 | [ |
||
| 33 | 'name' => 'id', |
||
| 34 | 'type' => 'hidden', |
||
| 35 | ], [ |
||
| 36 | 'name' => 'content', |
||
| 37 | ], [ |
||
| 38 | 'name' => 'tags', |
||
| 39 | ], [ |
||
| 40 | 'label' => 'Author', |
||
| 41 | 'type' => 'select', |
||
| 42 | 'name' => 'user_id', |
||
| 43 | 'entity' => 'user', |
||
| 44 | 'attribute' => 'name', |
||
| 45 | ], |
||
| 46 | ]; |
||
| 47 | |||
| 48 | private $userInputFieldsManyToMany = [ |
||
| 49 | [ |
||
| 50 | 'name' => 'id', |
||
| 51 | 'type' => 'hidden', |
||
| 52 | ], [ |
||
| 53 | 'name' => 'name', |
||
| 54 | ], [ |
||
| 55 | 'name' => 'email', |
||
| 56 | 'type' => 'email', |
||
| 57 | ], [ |
||
| 58 | 'name' => 'password', |
||
| 59 | 'type' => 'password', |
||
| 60 | ], [ |
||
| 61 | 'label' => 'Roles', |
||
| 62 | 'type' => 'select_multiple', |
||
| 63 | 'name' => 'roles', |
||
| 64 | 'entity' => 'roles', |
||
| 65 | 'attribute' => 'name', |
||
| 66 | 'pivot' => true, |
||
| 67 | ], |
||
| 68 | ]; |
||
| 69 | |||
| 70 | private $userInputFieldsDotNotation = [ |
||
| 71 | [ |
||
| 72 | 'name' => 'id', |
||
| 73 | 'type' => 'hidden', |
||
| 74 | ], [ |
||
| 75 | 'name' => 'name', |
||
| 76 | ], [ |
||
| 77 | 'name' => 'email', |
||
| 78 | 'type' => 'email', |
||
| 79 | ], [ |
||
| 80 | 'name' => 'password', |
||
| 81 | 'type' => 'password', |
||
| 82 | ], [ |
||
| 83 | 'label' => 'Roles', |
||
| 84 | 'type' => 'select_multiple', |
||
| 85 | 'name' => 'roles', |
||
| 86 | 'entity' => 'roles', |
||
| 87 | 'attribute' => 'name', |
||
| 88 | 'pivot' => true, |
||
| 89 | ], [ |
||
| 90 | 'label' => 'Street', |
||
| 91 | 'name' => 'street', |
||
| 92 | 'entity' => 'accountDetails.addresses', |
||
| 93 | 'attribute' => 'street', |
||
| 94 | ], |
||
| 95 | ]; |
||
| 96 | |||
| 97 | private $userInputFieldsManyToOne = [ |
||
| 98 | [ |
||
| 99 | 'name' => 'id', |
||
| 100 | 'type' => 'hidden', |
||
| 101 | ], [ |
||
| 102 | 'name' => 'name', |
||
| 103 | ], [ |
||
| 104 | 'name' => 'email', |
||
| 105 | 'type' => 'email', |
||
| 106 | ], [ |
||
| 107 | 'name' => 'password', |
||
| 108 | 'type' => 'password', |
||
| 109 | ], [ |
||
| 110 | 'label' => 'Roles', |
||
| 111 | 'type' => 'select_multiple', |
||
| 112 | 'name' => 'roles', |
||
| 113 | 'entity' => 'roles', |
||
| 114 | 'attribute' => 'name', |
||
| 115 | 'pivot' => true, |
||
| 116 | ], [ |
||
| 117 | 'name' => 'articles', |
||
| 118 | 'type' => 'select2_many', |
||
| 119 | 'entity' => 'articles', |
||
| 120 | 'model' => Article::class, |
||
| 121 | 'attribute' => 'content', |
||
| 122 | ], |
||
| 123 | ]; |
||
| 124 | |||
| 125 | public function testCreate() |
||
| 142 | |||
| 143 | public function testCreateWithOneToOneRelationship() |
||
| 147 | |||
| 148 | public function testCreateWithOneToManyRelationship() |
||
| 171 | |||
| 172 | public function testCreateWithManyToOneRelationship() |
||
| 191 | |||
| 192 | public function testCreateWithManyToManyRelationship() |
||
| 210 | |||
| 211 | View Code Duplication | public function testGetRelationFields() |
|
| 224 | |||
| 225 | View Code Duplication | public function testGetRelationFieldsCreateForm() |
|
| 234 | |||
| 235 | View Code Duplication | public function testGetRelationFieldsUpdateForm() |
|
| 244 | |||
| 245 | public function testGetRelationFieldsUnknownForm() |
||
| 258 | |||
| 259 | View Code Duplication | public function testGetRelationFieldsDotNotation() |
|
| 268 | |||
| 269 | public function testGetRelationFieldsNoRelations() |
||
| 277 | |||
| 278 | public function testGetRelationFieldsNoFields() |
||
| 284 | |||
| 285 | View Code Duplication | public function testGetRelationFieldsWithPivot() |
|
| 294 | |||
| 295 | public function testGetRelationFieldsWithPivotNoRelations() |
||
| 304 | |||
| 305 | View Code Duplication | public function testSyncPivot() |
|
| 323 | |||
| 324 | View Code Duplication | public function testSyncPivotUnknownData() |
|
| 342 | |||
| 343 | View Code Duplication | public function testSyncPivotUnknownModel() |
|
| 361 | } |
||
| 362 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.