| Conditions | 4 |
| Paths | 3 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 4.026 |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | 3 | public function getLastIncrement($table) |
|
| 24 | { |
||
| 25 | 3 | $con = $this->resource->getConnection(); |
|
| 26 | 3 | $builder = $con->createQueryBuilder(); |
|
| 27 | 3 | $builder->select('AUTO_INCREMENT') |
|
| 28 | 3 | ->from('INFORMATION_SCHEMA.TABLES') |
|
| 29 | 3 | ->where('TABLE_SCHEMA=?') |
|
| 30 | 3 | ->andWhere('TABLE_NAME=?'); |
|
| 31 | 3 | $stmt = $con->prepare($builder->getSQL()); |
|
| 32 | 3 | $stmt->bindValue(1, $con->getDatabase()); |
|
| 33 | 3 | $stmt->bindValue(2, $table); |
|
| 34 | 3 | $stmt->execute(); |
|
| 35 | 3 | $result = $stmt->fetch(\PDO::FETCH_NUM); |
|
| 36 | 3 | if ($result !== false && is_array($result)) { |
|
| 37 | 3 | if (is_null($result[0])) { |
|
| 38 | 3 | return 1; |
|
| 39 | } |
||
| 40 | return $result[0]; |
||
| 41 | } |
||
| 42 | throw new \Exception("Could not fetch last increment id."); |
||
| 43 | } |
||
| 44 | } |
||
| 45 |