Completed
Push — master ( feab26...f63281 )
by Logan H.
15s queued 11s
created

Overflowable::getColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace CraftLogan\LaravelOverflow;
4
use Illuminate\Support\Facades\Schema;
5
6
trait Overflowable{
7
8
    public function allWithOverflow()
9
    {
10
        $properties[$this->overflow_column] = $this->overflow();
0 ignored issues
show
Bug introduced by
The property overflow_column does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Coding Style Comprehensibility introduced by
$properties was never initialized. Although not strictly required by PHP, it is generally a good practice to add $properties = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
11
        return array_merge($properties, $this->getColumns());
12
    }
13
14
    public function getColumns()
15
    {
16
        $columnNames = $this->getColumnNames();
17
        $attributes = array_intersect_key($this->request->all(), $columnNames);
0 ignored issues
show
Bug introduced by
The property request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
        return $attributes;
19
    }
20
21 View Code Duplication
    public function overflow()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
    {
23
        $columnNames = $this->getColumnNames();
24
        $attributes = array_diff_key($this->request->all(), $columnNames);
25
        $attributes = json_encode($attributes);
26
        return $attributes;
27
    }
28
29
    public function getTableColumns()
30
    {
31
        return Schema::getColumnListing($this->model->getTable());
0 ignored issues
show
Bug introduced by
The property model does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
    }
33
34
    public function getColumnNames()
35
    {
36
        $columnNames = $this->getTableColumns();
37
        $columnNames = array_fill_keys($columnNames, "");
38
        return $columnNames;
39
    }
40
}
41