Region   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 2
eloc 14
c 2
b 1
f 1
dl 0
loc 49
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegionsByCountry() 0 9 1
A getRegionName() 0 5 1
1
<?php
2
3
namespace DavideCasiraghi\LaravelEventsCalendar\Models;
4
5
use Astrotomic\Translatable\Translatable;
6
use Illuminate\Database\Eloquent\Model;
7
8
class Region extends Model
9
{
10
    /***************************************************************************/
11
    /**
12
     * The table associated with the model.
13
     *
14
     * @var string
15
     */
16
    protected $table = 'regions';
17
18
    /***************************************************************************/
19
20
    use Translatable;
0 ignored issues
show
Bug introduced by
The trait Astrotomic\Translatable\Translatable requires the property $each which is not provided by DavideCasiraghi\LaravelE...sCalendar\Models\Region.
Loading history...
21
22
    public $translatedAttributes = ['name', 'slug'];
23
    protected $fillable = ['country_id', 'timezone'];
24
    public $useTranslationFallback = true;
25
26
    /***************************************************************************/
27
28
    /*
29
     * Return the region name.
30
     *
31
     * @param  int  $regionId
32
     * @return string
33
     */
34 1
    public static function getRegionName($regionId): string
35
    {
36 1
        $ret = self::find($regionId)->name;
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on DavideCasiraghi\LaravelE...sCalendar\Models\Region. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
37
38 1
        return $ret;
39
    }
40
41
    /***************************************************************************/
42
43
    /**
44
     * Return all the countries ordered by name.
45
     *
46
     * @return \Illuminate\Support\Collection
47
     */
48 1
    public static function getRegionsByCountry($countryId)
49
    {
50 1
        $ret = self::join('region_translations', 'regions.id', '=', 'region_translations.region_id')
51 1
                    ->where('locale', 'en')
52 1
                    ->where('country_id', $countryId)
53 1
                    ->orderBy('name')
54 1
                    ->pluck('name', 'region_translations.region_id AS id');
55
56 1
        return $ret;
57
    }
58
}
59