Users::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
c 3
b 1
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Sovereign\Lib;
4
5
6
/**
7
 * Class Users
8
 * @package Sovereign\Lib
9
 */
10
/**
11
 * Class Users
12
 * @package Sovereign\Lib
13
 */
14
class Users
15
{
16
    /**
17
     * @var Db
18
     */
19
    protected $db;
20
21
    /**
22
     * Users constructor.
23
     * @param Db $db
24
     */
25
    public function __construct(Db $db)
26
    {
27
        $this->db = $db;
28
    }
29
30
    /**
31
     * @param $userID
32
     * @param $name
33
     * @param $lastStatus
34
     * @param $game
35
     * @param $lastSeen
36
     * @param $lastSpoke
37
     * @param $lastWritten
38
     * @throws \Exception
39
     */
40
    public function set($userID, $name, $lastStatus, $game, $lastSeen, $lastSpoke, $lastWritten)
41
    {
42
        try {
43 View Code Duplication
            if (isset($lastStatus)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
                $this->db->execute("INSERT INTO users (discordID, nickName, lastStatus) VALUES (:discordID, :nickName, :lastStatus) ON DUPLICATE KEY UPDATE lastStatus = :lastStatus", [":discordID" => $userID, ":nickName" => $name, ":lastStatus" => $lastStatus]);
45
            }
46
47
            if (isset($game)) {
48
                $this->db->execute("INSERT INTO users (discordID, nickName, game) VALUES (:discordID, :nickName, :game) ON DUPLICATE KEY UPDATE game = :game", [":discordID" => $userID, ":nickName" => $name, ":game" => $game]);
49
                $this->db->execute("INSERT IGNORE INTO games (game) VALUES (:game)", array(":game" => $game));
50
            }
51
52 View Code Duplication
            if (isset($lastSeen)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
                $this->db->execute("INSERT INTO users (discordID, nickName, lastSeen) VALUES (:discordID, :nickName, :lastSeen) ON DUPLICATE KEY UPDATE lastSeen = :lastSeen", [":discordID" => $userID, ":nickName" => $name, ":lastSeen" => $lastSeen]);
54
            }
55
56 View Code Duplication
            if (isset($lastSpoke)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
                $this->db->execute("INSERT INTO users (discordID, nickName, lastSpoke) VALUES (:discordID, :nickName, :lastSpoke) ON DUPLICATE KEY UPDATE lastSpoke = :lastSpoke", [":discordID" => $userID, ":nickName" => $name, ":lastSpoke" => $lastSpoke]);
58
            }
59
60 View Code Duplication
            if (isset($lastWritten)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
                $this->db->execute("INSERT INTO users (discordID, nickName, lastWritten) VALUES (:discordID, :nickName, :lastWritten) ON DUPLICATE KEY UPDATE lastWritten = :lastWritten", [":discordID" => $userID, ":nickName" => $name, ":lastWritten" => $lastWritten]);
62
            }
63
        } catch (\Exception $e) {
64
            throw new \Exception("There was an error setting data for {$name}: {$e->getMessage()}");
65
        }
66
    }
67
68
    /**
69
     * @param $userID
70
     * @return array
71
     */
72
    public function get($userID)
73
    {
74
        return $this->db->queryRow("SELECT * FROM users WHERE userID = :userID", array(":userID" => $userID));
75
    }
76
}