Completed
Pull Request — master (#5)
by Samuel
07:07 queued 03:31
created

NotNullArrayable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 10 4
1
<?php
2
3
namespace SMartins\Exceptions\Traits;
4
5
use Illuminate\Contracts\Support\Arrayable;
6
7
trait NotNullArrayable
8
{
9
    /**
10
     * Get the instance as an array.
11
     *
12
     * @return array
13
     */
14
    public function toArray()
15
    {
16
        $array = [];
17
        foreach (get_object_vars($this) as $attribute => $value) {
18
            if (! is_null($value)) {
19
                $array[$attribute] = $value instanceof Arrayable ? $value->toArray() : $value;
20
            }
21
        }
22
23
        return $array;
24
    }
25
}
26