Ticket   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 60
rs 10
c 1
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRouteKeyName() 0 3 1
A purchase() 0 3 1
A price() 0 3 1
A event() 0 3 1
A priceCategory() 0 3 1
A getRowAndSeat() 0 25 6
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Ticket extends Model
8
{
9
    //
10
    protected $fillable = ['random_id', 'seat_number', 'purchase_id', 'event_id', 'price_category_id'];
11
12
    /**
13
     * Get the route key for the model.
14
     *
15
     * @return string
16
     */
17
    public function getRouteKeyName()
18
    {
19
        return 'random_id';
20
    }
21
22
    public function price()
23
    {
24
        return $this->priceCategory->price;
25
    }
26
27
    public function purchase()
28
    {
29
        return $this->belongsTo('App\Purchase');
30
    }
31
32
    public function event()
33
    {
34
        return $this->belongsTo('App\Event');
35
    }
36
37
    public function priceCategory()
38
    {
39
        return $this->belongsTo('App\PriceCategory');
40
    }
41
42
    public function getRowAndSeat()
43
    {
44
        if( !$this->event->seatMap->layout ) {
45
            return null;
46
        }
47
48
        $counter = 0;
49
        $columnCounter = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $columnCounter is dead and can be removed.
Loading history...
50
        $result = [];
51
        $rows = json_decode($this->event->seatMap->layout);
52
        foreach( $rows as $rowId => $row ) {
53
            $columnCounter = 0;
54
            foreach( str_split($row) as $charId => $char) {
55
                if($char === 'a') {
56
                    $counter++;
57
                    $columnCounter++;
58
                }
59
                if($counter === $this->seat_number) {
60
                    $result['row'] = $rowId+1;
61
                    $result['seat'] = $columnCounter;
62
                break;
63
                }
64
            }
65
        }
66
        return $result;
67
    }
68
}
69