AdminUsersMapper::getRandom()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Admin\Mapper;
6
7
use Zend\Db\Adapter\Adapter;
8
use Zend\Db\Adapter\AdapterAwareInterface;
9
use Zend\Db\Sql\Expression;
10
use Zend\Db\TableGateway\AbstractTableGateway;
11
12
/**
13
 * Class AdminUsersMapper.
14
 */
15
class AdminUsersMapper extends AbstractTableGateway implements AdapterAwareInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $table = 'admin_users';
21
22
    /**
23
     * Db adapter setter method,.
24
     *
25
     * @param Adapter $adapter db adapter
26
     *
27
     * @return void
28
     */
29
    public function setDbAdapter(Adapter $adapter)
30
    {
31
        $this->adapter = $adapter;
32
    }
33
34
    public function get($id)
35
    {
36
        return $this->select(['admin_user_id' => $id])->current();
37
    }
38
39
    /**
40
     * Get admin user by email.
41
     *
42
     * @param string $email email
43
     *
44
     * @return array|\ArrayObject|null
45
     */
46
    public function getByEmail(string $email)
47
    {
48
        return $this->select(['email' => $email])->current();
49
    }
50
51
    /**
52
     * Updates login data.
53
     *
54
     * @param string $uuid admin user id
0 ignored issues
show
Bug introduced by
There is no parameter named $uuid. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
55
     *
56
     * @return int number of affected rows
57
     */
58
    public function updateLogin(string $userId): int
59
    {
60
        return $this->update(['last_login' => date('Y-m-d H:i:s')], ['admin_user_id' => $userId]);
61
    }
62
63
    public function getPaginationSelect($userId)
64
    {
65
        $select = $this->getSql()->select()->order(['created_at' => 'desc']);
66
67
        $select->where->notEqualTo('admin_user_id', $userId);
68
69
        return $select;
70
    }
71
72
    public function getRandom($limit)
73
    {
74
        $select = $this->getSql()->select()
75
            ->where(['status' => 1])
76
            ->order(new Expression('rand()'))
0 ignored issues
show
Documentation introduced by
new \Zend\Db\Sql\Expression('rand()') is of type object<Zend\Db\Sql\Expression>, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
77
            ->limit($limit);
78
79
        return $this->selectWith($select);
80
    }
81
82
    public function getUuid($adminUserId)
83
    {
84
        $user = $this->select(['admin_user_id' => $adminUserId])->current();
85
86
        if (!$user) {
87
            throw new \Exception('Admin user does not exist!', 400);
88
        }
89
90
        return $user->admin_user_uuid;
91
    }
92
}
93