Passed
Push — master ( db71b9...272130 )
by Darío
04:27
created

RoleTbl::getNextId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Auth\Model;
4
5
use Drone\Db\TableGateway\TableGateway;
6
7
class RoleTbl extends TableGateway
8
{
9
    /**
10
     * Returns the next primary key in the table
11
     *
12
     * @return string
13
     */
14
    public function getNextId()
15
    {
16
        $table = $this->getEntity()->getTableName();
17
18
        $sql = "SELECT CASE WHEN MAX(ROLE_ID) IS NULL THEN 1 ELSE MAX(ROLE_ID) + 1 END AS ROLE_ID FROM $table";
19
20
        $this->getDriver()->getDb()->execute($sql);
21
        $rowset = $this->getDriver()->getDb()->getArrayResult();
22
        $row = array_shift($rowset);
23
24
        return $row["ROLE_ID"];
25
    }
26
}