Completed
Pull Request — 4.0 (#124)
by
unknown
02:44
created

Comment::commentColumns()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 3
eloc 4
nc 3
nop 2
1
<?php
2
3
namespace Yajra\Oci8\Schema;
4
5
use Illuminate\Database\Connection;
6
7
class Comment
8
{
9
    /**
10
     * @var \Illuminate\Database\Connection
11
     */
12
    protected $connection;
13
14
    /**
15
     * @param Connection $connection
16
     */
17
    public function __construct(Connection $connection)
18
    {
19
        $this->connection = $connection;
20
    }
21
22
    /**
23
     * Set table and column comments.
24
     *
25
     * @param  \Yajra\Oci8\Schema\OracleBlueprint $blueprint
26
     */
27
    public function setComments(OracleBlueprint $blueprint)
28
    {
29
        // Comment set by $table->comment('comment');
30
        if ($blueprint->commentTable != null)
31
        {
32
            $this->connection->statement(sprintf('comment on table %s is \'%s\'', $blueprint->getTable(), $blueprint->commentTable));
33
        }
34
35
        // Comments set by $table->string('column')->comment('comment');
36
        $this->commentColumns($blueprint->getTable(), $blueprint->getColumns());
37
38
        // Comments set by $table->commentColumn('column', 'comment');
39
        $this->commentColumns($blueprint->getTable(), $blueprint->commentColumn);
40
    }
41
42
    /**
43
     * Set column comment.
44
     *
45
     * @param  string $table
46
     * @param  array  $columns
47
     */
48
    private function commentColumns($table, $columns)
49
    {
50
        foreach ($columns as $column)
51
        {
52
            if (isset($column['comment']))
53
            {
54
                $this->connection->statement(sprintf('comment on column %s.%s is \'%s\'', $table, $column['name'], $column['comment']));
55
            }
56
        }
57
    }
58
}
59