Passed
Push — master ( 885dd6...ad933e )
by Wilmer
29:56 queued 26:08
created

TransactionPDO   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 25
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setTransactionIsolationLevel() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Sqlite;
6
7
use Throwable;
8
use Yiisoft\Db\Driver\PDO\TransactionPDO as AbstractTransactionPDO;
9
use Yiisoft\Db\Exception\Exception;
10
use Yiisoft\Db\Exception\InvalidConfigException;
11
use Yiisoft\Db\Exception\NotSupportedException;
12
use Yiisoft\Db\Transaction\TransactionInterface;
13
14
final class TransactionPDO extends AbstractTransactionPDO
15
{
16
    /**
17
     * Sets the isolation level of the current transaction.
18
     *
19
     * @param string $level The transaction isolation level to use for this transaction. This can be either
20
     * {@see TransactionInterface::READ_UNCOMMITTED} or {@see TransactionInterface::SERIALIZABLE}.
21
     *
22
     * @throws Exception|InvalidConfigException|NotSupportedException|Throwable when unsupported isolation levels are
23
     * used. SQLite only supports SERIALIZABLE and READ UNCOMMITTED.
24
     *
25
     * {@see http://www.sqlite.org/pragma.html#pragma_read_uncommitted}
26
     */
27 3
    protected function setTransactionIsolationLevel(string $level): void
28
    {
29
        switch ($level) {
30 3
            case self::SERIALIZABLE:
31 1
                $this->db->createCommand('PRAGMA read_uncommitted = False;')->execute();
32 1
                break;
33 3
            case self::READ_UNCOMMITTED:
34 3
                $this->db->createCommand('PRAGMA read_uncommitted = True;')->execute();
35 3
                break;
36
            default:
37
                throw new NotSupportedException(
38
                    self::class . ' only supports transaction isolation levels READ UNCOMMITTED and SERIALIZABLE.'
39
                );
40
        }
41
    }
42
}
43