Test Setup Failed
Push — master ( 1fae15...0a0a56 )
by Bas
01:35
created

Columns::renameColumn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace LaravelFreelancerNL\Aranguent\Schema\Concerns;
4
5
use Illuminate\Support\Fluent;
6
7
trait Columns
8
{
9
10
    /**
11
     * Check if any document within the table has the column.
12
     *
13
     * @param string|array $column
14
     * @return Fluent
15
     */
16
    public function hasColumn($column)
17
    {
18
        $parameters = [];
19
        $parameters['handler'] = 'aql';
20
        $parameters['explanation'] = "Checking if any document within the table has the '".implode(', ', (array) $column)."' column(s).";
21
        $parameters['column'] = $column;
22
23
        return $this->addCommand('hasAttribute', $parameters);
0 ignored issues
show
Bug introduced by
It seems like addCommand() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
24
    }
25
26
    /**
27
     * Indicate that the given attributes should be renamed.
28
     *
29
     * @param  string  $from
30
     * @param  string  $to
31
     * @return Fluent
32
     */
33
    public function renameColumn($from, $to)
34
    {
35
        $parameters = [];
36
        $parameters['handler'] = 'aql';
37
        $parameters['explanation'] = "Rename the column '$from' to '$to'.";
38
        $parameters['from'] = $from;
39
        $parameters['to'] = $to;
40
41
        return $this->addCommand('renameAttribute', $parameters);
0 ignored issues
show
Bug introduced by
It seems like addCommand() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
42
    }
43
44
45
    /**
46
     * Indicate that the given column(s) should be dropped.
47
     *
48
     * @param  array|mixed  $columns
49
     * @return Fluent
50
     */
51
    public function dropColumn($columns)
52
    {
53
        $columns = is_array($columns) ? $columns : func_get_args();
54
55
        $parameters = [];
56
        $parameters['handler'] = 'aql';
57
        $parameters['attributes'] = $columns;
58
        $parameters['explanation'] = 'Drop the following column(s): '.implode(',', $columns).'.';
59
60
        return $this->addCommand('dropAttribute', compact('parameters'));
0 ignored issues
show
Bug introduced by
It seems like addCommand() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
61
    }
62
63
}