• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AJenbo / agcms / 21420560247

28 Jan 2026 12:59AM UTC coverage: 52.306% (-1.4%) from 53.72%
21420560247

push

github

AJenbo
Bump phpunit/phpunit from 9.6.11 to 9.6.33 in /application

Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.6.11 to 9.6.33.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/9.6.33/ChangeLog-9.6.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.6.11...9.6.33)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-version: 9.6.33
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

3039 of 5810 relevant lines covered (52.31%)

12.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.98
/application/inc/Models/User.php
1
<?php
2

3
namespace App\Models;
4

5
use App\Exceptions\Exception;
6
use App\Services\DbService;
7
use DateTime;
8

9
class User extends AbstractEntity
10
{
11
    /** Table name */
12
    public const TABLE_NAME = 'users';
13

14
    /** Number of seconds a user is assumed to be active. */
15
    private const ONLINE_INTERVAL = 1800;
16

17
    /** Not approved user */
18
    public const NO_ACCESS = 0;
19

20
    /** Full access user */
21
    public const ADMINISTRATOR = 1;
22

23
    /** Can't edit other users */
24
    public const MANAGER = 3;
25

26
    /** Can only handle orders */
27
    public const CLERK = 4;
28

29
    /** @var string User's full name. */
30
    private string $fullName = '';
31

32
    /** @var string User's nick name. */
33
    private string $nickname = '';
34

35
    /** @var string User's Password hash. */
36
    private string $passwordHash = '';
37

38
    /** @var int User's access level. */
39
    private int $accessLevel = 0;
40

41
    /** @var int time of last login */
42
    private int $lastLogin;
43

44
    public function __construct(array $data = [])
45
    {
46
        $this->setFullName(valstring($data['full_name']))
53✔
47
            ->setNickname(valstring($data['nickname']))
53✔
48
            ->setPasswordHash(valstring($data['password_hash']))
53✔
49
            ->setAccessLevel(valint($data['access_level']))
53✔
50
            ->setLastLogin(valint($data['last_login']))
53✔
51
            ->setId(intOrNull($data['id'] ?? null));
53✔
52
    }
53

54
    public static function mapFromDB(array $data): array
55
    {
56
        return [
53✔
57
            'id'            => $data['id'],
53✔
58
            'full_name'     => $data['fullname'],
53✔
59
            'nickname'      => $data['name'],
53✔
60
            'password_hash' => $data['password'],
53✔
61
            'access_level'  => $data['access'],
53✔
62
            'last_login'    => strtotime($data['lastlogin']) + app(DbService::class)->getTimeOffset(),
53✔
63
        ];
53✔
64
    }
65

66
    public function getDbArray(): array
67
    {
68
        $db = app(DbService::class);
×
69

70
        return [
×
71
            'fullname'  => $db->quote($this->fullName),
×
72
            'name'      => $db->quote($this->nickname),
×
73
            'password'  => $db->quote($this->passwordHash),
×
74
            'access'    => (string)$this->accessLevel,
×
75
            'lastlogin' => $db->getDateValue($this->lastLogin - $db->getTimeOffset()),
×
76
        ];
×
77
    }
78

79
    /**
80
     * Set user's full name.
81
     *
82
     * @return $this
83
     */
84
    public function setFullName(string $fullName): self
85
    {
86
        $this->fullName = $fullName;
53✔
87

88
        return $this;
53✔
89
    }
90

91
    /**
92
     * Get user's full name.
93
     */
94
    public function getFullName(): string
95
    {
96
        return $this->fullName;
×
97
    }
98

99
    /**
100
     * Set user's nick name.
101
     *
102
     * @return $this
103
     */
104
    public function setNickname(string $nickname): self
105
    {
106
        $this->nickname = $nickname;
53✔
107

108
        return $this;
53✔
109
    }
110

111
    /**
112
     * Get nick name.
113
     */
114
    public function getNickname(): string
115
    {
116
        return $this->nickname;
×
117
    }
118

119
    /**
120
     * Set users password.
121
     *
122
     * @throws Exception
123
     *
124
     * @return $this
125
     */
126
    public function setPassword(string $password): self
127
    {
128
        $hash = password_hash($password, PASSWORD_BCRYPT);
×
129
        if (!$hash) {
×
130
            throw new Exception('Failed to hash password');
×
131
        }
132

133
        $this->passwordHash = $hash;
×
134

135
        return $this;
×
136
    }
137

138
    /**
139
     * Set users password hash.
140
     *
141
     * @return $this
142
     */
143
    public function setPasswordHash(string $passwordHash): self
144
    {
145
        $this->passwordHash = $passwordHash;
53✔
146

147
        return $this;
53✔
148
    }
149

150
    /**
151
     * Get password hash.
152
     */
153
    public function getPasswordHash(): string
154
    {
155
        return $this->passwordHash;
×
156
    }
157

158
    /**
159
     * Set access level.
160
     *
161
     * @return $this
162
     */
163
    public function setAccessLevel(int $accessLevel): self
164
    {
165
        $this->accessLevel = $accessLevel;
53✔
166

167
        return $this;
53✔
168
    }
169

170
    /**
171
     * Get access level.
172
     */
173
    public function getAccessLevel(): int
174
    {
175
        return $this->accessLevel;
53✔
176
    }
177

178
    /**
179
     * Set last activity time.
180
     *
181
     * @return $this
182
     */
183
    public function setLastLogin(int $lastLogin): self
184
    {
185
        $this->lastLogin = $lastLogin;
53✔
186

187
        return $this;
53✔
188
    }
189

190
    /**
191
     * Get last activity time.
192
     */
193
    public function getLastLogin(): int
194
    {
195
        return $this->lastLogin;
×
196
    }
197

198
    /**
199
     * Validate a password with this user.
200
     */
201
    public function validatePassword(string $password): bool
202
    {
203
        return password_verify($password, $this->passwordHash);
×
204
    }
205

206
    /**
207
     * Check if user has given access level (or higher).
208
     */
209
    public function hasAccess(int $requestedLevel): bool
210
    {
211
        if (!$this->accessLevel) {
×
212
            return false;
×
213
        }
214

215
        return $this->accessLevel <= $requestedLevel;
×
216
    }
217

218
    /**
219
     * Generate a human frindly string showing time since last active.
220
     */
221
    public function getLastLoginText(): string
222
    {
223
        if (!$this->lastLogin) {
×
224
            return _('Never');
×
225
        }
226

227
        if (time() < $this->lastLogin + self::ONLINE_INTERVAL) {
×
228
            return _('Online');
×
229
        }
230

231
        $lastLoginDate = new DateTime('@' . $this->lastLogin);
×
232
        $interval = $lastLoginDate->diff(new DateTime('now'));
×
233

234
        if ($interval->y) {
×
235
            return sprintf(_('%s years and %s months ago'), $interval->y, $interval->m);
×
236
        }
237

238
        if ($interval->m) {
×
239
            return sprintf(_('%s months and %s days ago'), $interval->m, $interval->d);
×
240
        }
241

242
        if ($interval->d) {
×
243
            return sprintf(_('%s days and %s hours ago'), $interval->d, $interval->h);
×
244
        }
245

246
        if ($interval->h) {
×
247
            return sprintf(_('%s hours and %s minutes ago'), $interval->h, $interval->i);
×
248
        }
249

250
        return sprintf(_('%s minutes and %s seconds ago'), $interval->i, $interval->s);
×
251
    }
252
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc