1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Temitope Olotin <[email protected]> |
4
|
|
|
* @license <https://opensource.org/license/MIT> MIT |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Laztopaz\EmojiRestfulAPI; |
8
|
|
|
|
9
|
|
|
use Laztopaz\EmojiRestfulAPI\Emoji; |
10
|
|
|
use Laztopaz\EmojiRestfulAPI\Keyword; |
11
|
|
|
use Laztopaz\EmojiRestfulAPI\UserController; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class UploadTableInfo |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
public function __construct() |
18
|
|
|
{ |
19
|
|
|
$this->createUser(); |
20
|
|
|
$this->createCategory(); |
21
|
|
|
$this->createEmoji(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function createUser() |
25
|
|
|
{ |
26
|
|
|
$suer = new UserController(); |
|
|
|
|
27
|
|
|
|
28
|
|
|
$user->createUser([ |
|
|
|
|
29
|
|
|
'firstname' => 'Temitope', |
30
|
|
|
'lastname' => 'Olotin', |
31
|
|
|
'username' => 'laztopaz', |
32
|
|
|
'password' => 'tope0852', |
33
|
|
|
'email' => '[email protected]', |
34
|
|
|
'created_at' => date('Y-m-d h:i:s'), |
35
|
|
|
'updated_at' => date('Y-m-d h:i:s') |
36
|
|
|
]); |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function createEmoji() |
41
|
|
|
{ |
42
|
|
|
$emojiKeyword = 'eye,face,grin,person'; |
43
|
|
|
|
44
|
|
|
$userId = 1; |
45
|
|
|
|
46
|
|
|
$created_at = date('Y-m-d h:i:s'); |
47
|
|
|
|
48
|
|
|
$emoji = Emoji::create( |
49
|
|
|
[ |
50
|
|
|
'name' => 'GRINNING FACE', |
51
|
|
|
'char' => '\u{1F600}', |
52
|
|
|
'created_at' => $created_at, |
53
|
|
|
'category' => 1, |
54
|
|
|
'created_by' => $userId |
55
|
|
|
] |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
if ($emoji->id) { |
|
|
|
|
59
|
|
|
$createdKeyword = $this->createEmojiKeywords($emoji->id, $emojiKeyword); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function createCategory() |
65
|
|
|
{ |
66
|
|
|
$created_at = date('Y-m-d h:i:s'); |
67
|
|
|
|
68
|
|
|
$category = Category::create( |
|
|
|
|
69
|
|
|
[ |
70
|
|
|
'category_name' => 'people', |
71
|
|
|
'created_at' => $created_at |
72
|
|
|
] |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
View Code Duplication |
public function createEmojiKeywords($emoji_id, $keywords) |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
if ($keywords) { |
80
|
|
|
$splittedKeywords = explode(',', $keywords); |
81
|
|
|
|
82
|
|
|
$created_at = date('Y-m-d h:i:s'); |
83
|
|
|
|
84
|
|
|
foreach ($splittedKeywords as $keyword) { |
85
|
|
|
$emojiKeyword = Keyword::create( |
86
|
|
|
[ |
87
|
|
|
'emoji_id' => $emoji_id, |
88
|
|
|
'keyword_name' => $keyword, |
89
|
|
|
'created_at' => $created_at, |
90
|
|
|
] |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $emojiKeyword->id; |
|
|
|
|
96
|
|
|
} |
97
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.