Completed
Push — dev-v3 ( 0f682d )
by Propa
02:36
created

ParsesCountries::parseCountries()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
ccs 0
cts 8
cp 0
crap 12
rs 9.4285
1
<?php namespace Propaganistas\LaravelPhone\Traits;
2
3
use Iso3166\Codes as ISO3166;
4
5
trait ParsesCountries
6
{
7
    /**
8
     * Determine whether the given country code is valid.
9
     *
10
     * @param string $country
11
     * @return bool
12
     */
13
    public static function isCountryCode($country)
14
    {
15
        return ISO3166::isValid($country);
16
    }
17
18
    /**
19
     * Parse the provided phone countries to a valid array.
20
     *
21
     * @param string|array $countries
22
     * @return array
23
     */
24
    protected function parseCountries($countries)
25
    {
26
        $countries = is_array($countries) ? $countries : func_get_args();
27
28
        return array_filter($countries, function ($code) {
29
            $code = strtoupper($code);
30
31
            return static::isCountryCode($code) ? $code : null;
32
        });
33
    }
34
}