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 |
||
8 | class UploadTableInfo |
||
9 | { |
||
10 | public function __construct() |
||
16 | |||
17 | public function createUser() |
||
18 | { |
||
19 | $user = new UserController(); |
||
20 | $user->createUser([ |
||
21 | 'firstname' => 'Olotin', |
||
22 | 'lastname' => 'Temitope', |
||
23 | 'username' => 'laztopaz', |
||
24 | 'password' => 'tope0852', |
||
25 | 'email' => '[email protected]', |
||
26 | 'created_at' => date('Y-m-d h:i:s'), |
||
27 | 'updated_at' => date('Y-m-d h:i:s'), |
||
28 | ]); |
||
29 | } |
||
30 | |||
31 | public function createEmoji() |
||
32 | { |
||
33 | $emojiKeyword = 'eye, face, grin, person'; |
||
34 | |||
35 | $userId = 1; |
||
36 | |||
37 | $created_at = date('Y-m-d h:i:s'); |
||
38 | |||
39 | $emoji = Emoji::create([ |
||
40 | 'name' => 'GRINNING FACE', |
||
41 | 'char' => '\u{1F606}', |
||
42 | 'created_at' => $created_at, |
||
43 | 'category' => 1, |
||
44 | 'created_by' => $userId, |
||
45 | ]); |
||
46 | |||
47 | if ($emoji->id) { |
||
|
|||
48 | $createdKeyword = $this->createEmojiKeywords($emoji->id, $emojiKeyword); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | public function createCategory() |
||
61 | |||
62 | View Code Duplication | public function createEmojiKeywords($emoji_id, $keywords) |
|
80 | } |
||
81 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.