user_helper   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 75
dl 0
loc 145
rs 10
c 0
b 0
f 0
wmc 20

17 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A fetch_pfp() 0 9 3
A if_blocked() 0 7 1
A fetch_unread_pms() 0 6 1
A if_admin() 0 6 1
A fetch_friends_accepted() 0 12 1
A get_channel_views() 0 6 1
A if_partner() 0 6 1
A fetch_user_favorites() 0 6 1
A user_exists() 0 6 1
A fetch_user_username() 0 6 2
A if_subscribed() 0 7 1
A fetch_user_videos() 0 6 1
A if_upload_cooldown() 0 6 1
A fetch_subscriptions() 0 6 1
A fetch_subs_count() 0 6 1
A if_cooldown() 0 6 1
1
<?php
2
3
/**
4
* @Auther: bhief
5
* @Version: 1.0
6
* @Added Base
7
*
8
* Use this class for getting user information
9
*
10
**/
11
class user_helper {
12
    public $__db;
13
14
	public function __construct($conn){
15
        $this->__db = $conn;
16
	}
17
18
    function fetch_pfp($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
19
        $stmt = $this->__db->prepare("SELECT pfp FROM users WHERE username = :username");
20
        $stmt->bindParam(":username", $username);
21
        $stmt->execute();
22
        while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
23
            $pfp = $row['pfp'];
24
        } // why the while statement? just remove it (i cant be bothered to)
25
26
        return (isset($pfp) ? $pfp : "default.png");
27
    }
28
29
    
30
    function fetch_unread_pms($user) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
31
        $stmt = $this->__db->prepare("SELECT * FROM pms WHERE touser = :user AND readed = 'y'");
32
        $stmt->bindParam(":user", $user);
33
        $stmt->execute();
34
    
35
        return $stmt->rowCount();
36
    }
37
38
    function if_blocked($user, $reciever) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
39
        $stmt = $this->__db->prepare("SELECT reciever FROM block WHERE sender = :user AND reciever = :reciever");
40
        $stmt->bindParam(":user", $user);
41
        $stmt->bindParam(":reciever", $reciever);
42
        $stmt->execute();
43
44
        return $stmt->rowCount() === 1;
45
    }    
46
47
    function if_admin($user) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
48
        $stmt = $this->__db->prepare("SELECT status FROM users WHERE username = :user AND status = 'admin'");
49
        $stmt->bindParam(":user", $user);;
50
        $stmt->execute();
51
52
        return $stmt->rowCount() === 1;
53
    }    
54
55
    function if_partner($user) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56
        $stmt = $this->__db->prepare("SELECT partner FROM users WHERE username = :user AND partner = 'y'");
57
        $stmt->bindParam(":user", $user);;
58
        $stmt->execute();
59
60
        return $stmt->rowCount() === 1;
61
    }    
62
    
63
    function if_cooldown($user) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
64
        $stmt = $this->__db->prepare("SELECT * FROM users WHERE username = :username AND cooldown_comment >= NOW() - INTERVAL 1 MINUTE");
65
        $stmt->bindParam(":username", $user);
66
        $stmt->execute();
67
        
68
        return $stmt->rowCount() === 1;
69
    }
70
71
    function if_upload_cooldown($user) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
72
        $stmt = $this->__db->prepare("SELECT * FROM users WHERE username = :username AND upload_cooldown >= NOW() - INTERVAL 10 MINUTE");
73
        $stmt->bindParam(":username", $user);
74
        $stmt->execute();
75
        
76
        return $stmt->rowCount() === 1;
77
    }
78
79
    function fetch_user_username($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
80
        $stmt = $this->__db->prepare("SELECT * FROM users WHERE username = :username");
81
        $stmt->bindParam(":username", $username);
82
        $stmt->execute();
83
84
        return ($stmt->rowCount() === 0 ? 0 : $stmt->fetch(PDO::FETCH_ASSOC));
85
    }
86
87
    function user_exists($user) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
88
        $stmt = $this->__db->prepare("SELECT username FROM users WHERE username = :username");
89
        $stmt->bindParam(":username", $user);
90
        $stmt->execute();
91
92
        return $stmt->rowCount() === 1;
93
    }
94
95
    function if_subscribed($user, $reciever) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
96
        $stmt = $this->__db->prepare("SELECT reciever FROM subscribers WHERE sender = :sender AND reciever = :reciever");
97
        $stmt->bindParam(":sender", $user);
98
        $stmt->bindParam(":reciever", $reciever);
99
        $stmt->execute();
100
101
        return $stmt->rowCount() === 1;
102
    }
103
104
    function fetch_subs_count($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
105
        $stmt = $this->__db->prepare("SELECT * FROM subscribers WHERE reciever = :username");
106
        $stmt->bindParam(":username", $username);
107
        $stmt->execute();
108
109
        return $stmt->rowCount();
110
    }
111
112
    function fetch_user_videos(string $id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
113
        $stmt = $this->__db->prepare("SELECT rid FROM videos WHERE author = :id");
114
        $stmt->bindParam(":id", $id);
115
        $stmt->execute();
116
        
117
        return $stmt->rowCount();
118
    }
119
120
    function fetch_user_favorites(string $username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
121
        $stmt = $this->__db->prepare("SELECT reciever FROM favorite_video WHERE sender = :username");
122
        $stmt->bindParam(":username", $username);
123
        $stmt->execute(); 
124
    
125
        return $stmt->rowCount();
126
    }
127
128
    function fetch_subscriptions($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
129
        $stmt = $this->__db->prepare("SELECT * FROM subscribers WHERE sender = :username");
130
        $stmt->bindParam(":username", $username);
131
        $stmt->execute();
132
    
133
        return $stmt->rowCount();
134
    }
135
136
    function get_channel_views(string $rid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
137
        $stmt = $this->__db->prepare("SELECT * FROM channel_views WHERE channel = :rid");
138
        $stmt->bindParam(":rid", $rid);
139
        $stmt->execute();
140
        
141
        return $stmt->rowCount();
142
    }
143
144
    function fetch_friends_accepted($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
145
        $stmt = $this->__db->prepare("SELECT * FROM friends WHERE reciever = :username AND status = 'a'");
146
        $stmt->bindParam(":username", $username);
147
        $stmt->execute();
148
    
149
        $friends = $stmt->rowCount();
150
151
        $stmt = $this->__db->prepare("SELECT * FROM friends WHERE sender = :username AND status = 'a'");
152
        $stmt->bindParam(":username", $username);
153
        $stmt->execute();
154
    
155
        return $friends + $stmt->rowCount();
156
    }
157
}
158
159
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...