Passed
Push — master ( 3415eb...56b5c5 )
by Jonas
04:04
created

SQLiteBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 58
ccs 18
cts 18
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A renameView() 0 16 1
A createView() 0 7 2
A getBindingsForHasView() 0 3 1
1
<?php
2
3
namespace Staudenmeir\LaravelMigrationViews\Schema\Builders;
4
5
use Illuminate\Database\Schema\SQLiteBuilder as Base;
6
use Illuminate\Support\Str;
7
8
class SQLiteBuilder extends Base
9
{
10
    use ManagesViews {
11
        createView as createViewParent;
12
    }
13
14
    /**
15
     * Create a new view on the schema.
16
     *
17
     * @param string $name
18
     * @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|string $query
19
     * @param array|null $columns
20
     * @param bool $orReplace
21
     * @return void
22
     */
23 10
    public function createView($name, $query, array $columns = null, $orReplace = false)
24
    {
25 10
        if ($orReplace) {
26 1
            $this->dropViewIfExists($name);
27
        }
28
29 10
        $this->createViewParent($name, $query, $columns);
30 10
    }
31
32
    /**
33
     * Rename a view on the schema.
34
     *
35
     * @param string $from
36
     * @param string $to
37
     * @return void
38
     */
39 1
    public function renameView($from, $to)
40
    {
41 1
        $view = $this->connection->selectOne(
42 1
            "select * from sqlite_master where type = 'view' and name = ?",
43 1
            [$this->connection->getTablePrefix().$from]
44
        );
45
46 1
        $this->dropView($from);
47
48 1
        $query = Str::replaceFirst(
49 1
            $this->grammar->wrapTable($from),
50 1
            $this->grammar->wrapTable($to),
51 1
            $view->sql
52
        );
53
54 1
        $this->connection->statement($query);
55 1
    }
56
57
    /**
58
     * Get the bindings for a "Has View" statement.
59
     *
60
     * @param string $view
61
     * @return array
62
     */
63 3
    protected function getBindingsForHasView($view)
64
    {
65 3
        return [$view];
66
    }
67
}
68