Completed
Pull Request — 4.0 (#124)
by
unknown
05:29
created

Comment   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 56
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B setComments() 0 23 5
A commentColumn() 0 4 1
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->comment != null)
31
        {
32
            $this->connection->statement(sprintf('comment on table %s is \'%s\'', $blueprint->getTable(), $blueprint->comment));
33
        }
34
35
        // Comments set by $table->string('column')->comment('comment');
36
        foreach ($blueprint->getColumns() as $column)
37
        {
38
            if (isset($column['comment']))
39
            {
40
                $this->commentColumn($blueprint->getTable(), $column['name'], $column['comment']);
41
            }
42
        }
43
44
        // Comments set by $table->commentColumns = ['column' => 'comment'];
45
        foreach ($blueprint->commentColumns as $column => $comment)
46
        {
47
            $this->commentColumn($blueprint->getTable(), $column, $comment);
48
        }
49
    }
50
51
    /**
52
     * Run the comment on column statement
53
     *
54
     * @param  string $table
55
     * @param  string $column
56
     * @param  string $comment
57
     */
58
    private function commentColumn($table, $column, $comment)
59
    {
60
        $this->connection->statement(sprintf('comment on column %s.%s is \'%s\'', $table, $column, $comment));
61
    }
62
}
63