Passed
Push — master ( 30143e...90c451 )
by Martin
05:30
created

SeatMap::getRowsAndColumns()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 2
nop 0
dl 0
loc 19
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class SeatMap extends Model
8
{
9
    protected $fillable = ['seats', 'name', 'description', 'layout'];
10
11
    public function events()
12
    {
13
        return $this->hasMany('App\Event');
14
    }
15
16
    public function getRowsAndColumns()
17
    {
18
        if(!$this->layout) {
19
            return null;
20
        }
21
22
        $result = [];
23
24
        $rows = json_decode($this->layout);
25
        $result['rows'] = count($rows);
26
        $result['columns'] = array_reduce($rows, function($intermediate, $row) {
27
            $columns = strlen($row);
28
            if($intermediate < $columns) {
29
                return $columns;
30
            } else {
31
                return $intermediate;
32
            }
33
        }, 0);
34
        return $result;
35
    }
36
}
37