Passed
Pull Request — master (#53)
by
unknown
05:24
created

Venue   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 50
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setDefaultLocation() 0 17 7
A country() 0 3 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Venue extends Model
8
{
9
    public $timestamps = true;
10
    protected $table = 'venue';
11
    protected $fillable = [
12
        'venue_name',
13
        'address',
14
        'details',
15
        'city',
16
        'CP',
17
        'state',
18
        'country_id',
19
        'latitude',
20
        'longitude',
21
    ];
22
23
    /**
24
     * A Venue Belongs to a Country
25
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
26
     */
27
    public function country()
28
    {
29
        return $this->belongsTo(Country::class);
30
    }
31
32
33
    /**
34
     * Get the Current User location
35
     * @param $tournament
36
     * @param $latitude
37
     * @param $longitude
38
     * @return $this
39
     */
40 8
    public function setDefaultLocation($tournament, $latitude, $longitude)
41
    {
42 8
        $userLat = $tournament != null ? $tournament->owner->latitude : null;
43 8
        $userLng = $tournament != null ? $tournament->owner->longitude : null;
44
45 8
        if ($latitude != null && $longitude != null) {
46 6
            $this->latitude = $latitude;
47 6
            $this->longitude = $longitude;
48 7
        } else if (!isNullOrEmptyString($userLat) && !isNullOrEmptyString($userLng)) {
49 6
            $this->latitude = $userLat;
50 6
            $this->longitude = $userLng;
51
        } else {
52
            //TODO Should popup for user localization
53 1
            $this->latitude = 0;
54 1
            $this->longitude = 0;
55
        }
56 8
        return $this;
57
    }
58
}
59