SQLiteBuilder::createView()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 5
dl 0
loc 7
rs 10
c 1
b 0
f 0
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
     * @param bool $materialized
22
     * @return void
23
     */
24
    public function createView($name, $query, ?array $columns = null, $orReplace = false, bool $materialized = false)
0 ignored issues
show
Unused Code introduced by
The parameter $materialized is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
    public function createView($name, $query, ?array $columns = null, $orReplace = false, /** @scrutinizer ignore-unused */ bool $materialized = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        if ($orReplace) {
27
            $this->dropViewIfExists($name);
28
        }
29
30
        $this->createViewParent($name, $query, $columns);
31
    }
32
33
    /**
34
     * Rename a view on the schema.
35
     *
36
     * @param string $from
37
     * @param string $to
38
     * @return void
39
     */
40
    public function renameView($from, $to)
41
    {
42
        $view = $this->connection->selectOne(
43
            "select * from sqlite_master where type = 'view' and name = ?",
44
            [$this->connection->getTablePrefix().$from]
45
        );
46
47
        $this->dropView($from);
48
49
        $query = Str::replaceFirst(
50
            $this->grammar->wrapTable($from),
51
            $this->grammar->wrapTable($to),
52
            $view->sql
53
        );
54
55
        $this->connection->statement($query);
56
    }
57
}
58