| Conditions | 4 |
| Paths | 11 |
| Total Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 21 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | 12 | public function pop() |
|
| 22 | { |
||
| 23 | 12 | $sql = sprintf( |
|
| 24 | 12 | 'SELECT id, item FROM %s WHERE eta <= %d ORDER BY eta LIMIT 1', |
|
| 25 | 12 | $this->tableName, |
|
| 26 | 12 | time() |
|
| 27 | 12 | ); |
|
| 28 | |||
| 29 | 12 | $this->pdo->exec('BEGIN IMMEDIATE'); |
|
| 30 | |||
| 31 | try { |
||
| 32 | 12 | $stmt = $this->pdo->query($sql); |
|
| 33 | 11 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 34 | 11 | $stmt->closeCursor(); |
|
| 35 | |||
| 36 | 11 | if ($row) { |
|
| 37 | 11 | $sql = sprintf('DELETE FROM %s WHERE id = %d', $this->tableName, $row['id']); |
|
| 38 | 11 | $this->pdo->exec($sql); |
|
| 39 | 11 | } |
|
| 40 | |||
| 41 | 11 | $this->pdo->exec('COMMIT'); |
|
| 42 | 12 | } catch (\Exception $e) { |
|
| 43 | 1 | $this->pdo->exec('ROLLBACK'); |
|
| 44 | 1 | throw $e; |
|
| 45 | } |
||
| 46 | |||
| 47 | 11 | if ($row) { |
|
| 48 | 11 | return $row['item']; |
|
| 49 | } |
||
| 50 | |||
| 51 | 2 | throw new NoItemAvailableException($this); |
|
| 52 | } |
||
| 53 | |||
| 59 |