SeatMap::events()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
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