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

ParsesCountries   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
ccs 0
cts 12
cp 0
rs 10
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isCountryCode() 0 4 1
A parseCountries() 0 10 3
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
}