Passed
Push — master ( 26152a...8fe73e )
by F
04:04
created

Country   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A languages() 0 7 1
A getNameAttribute() 0 7 3
A __construct() 0 5 1
1
<?php
2
3
/**
4
 * PWWEB\Localisation\Models\Country Model.
5
 *
6
 * Standard Country Model.
7
 *
8
 * @author    Frank Pillukeit <[email protected]>
9
 * @copyright 2020 pw-websolutions.com
10
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
11
 */
12
13
namespace PWWEB\Localisation\Models;
14
15
use Illuminate\Database\Eloquent\Model;
16
use Illuminate\Database\Eloquent\Relations\HasMany;
17
use PWWEB\Localisation\Contracts\Country as CountryContract;
18
19
class Country extends Model implements CountryContract
20
{
21
    /**
22
     * Constructor.
23
     *
24
     * @param array $attributes additional attributes for model initialisation
25
     *
26
     * @return void
27
     */
28
    public function __construct(array $attributes = [])
29
    {
30
        parent::__construct($attributes);
31
32
        $this->setTable(config('pwweb.localisation.table_names.countries'));
33
    }
34
35
    /**
36
     * A country can have multiple languages.
37
     *
38
     * @return \Illuminate\Database\Eloquent\Relations\HasMany collection of languages used in the country
39
     */
40
    public function languages(): HasMany
41
    {
42
        return $this->hasMany(
43
            config('pwweb.localisation.models.languages'),
44
            config('pwweb.localisation.table_names.country_has_language'),
45
            'country_id',
46
            'language_id'
0 ignored issues
show
Unused Code introduced by
The call to Illuminate\Database\Eloquent\Model::hasMany() has too many arguments starting with 'language_id'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        return $this->/** @scrutinizer ignore-call */ hasMany(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
47
        );
48
    }
49
50
    /**
51
     * Obtain a localised country name.
52
     *
53
     * @param string $value Original value.
54
     *
55
     * @return string Localised country name.
56
     */
57
    public function getNameAttribute($value)
58
    {
59
        if (null === $value || '' === $value) {
60
            return '';
61
        }
62
63
        return __('pwweb::localization.' . $value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return __('pwweb::localization.' . $value) also could return the type array which is incompatible with the documented return type string.
Loading history...
64
    }
65
}
66