Completed
Push — master ( 77ccc6...f13dc8 )
by Propa
05:09
created

ParsesCountries   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValidCountryCode() 0 4 1
A parseCountries() 0 10 2
1
<?php namespace Propaganistas\LaravelPhone\Traits;
2
3
use Illuminate\Support\Collection;
4
use Iso3166\Codes as ISO3166;
5
6
trait ParsesCountries
7
{
8
    /**
9
     * Determine whether the given country code is valid.
10
     *
11
     * @param string $country
12
     * @return bool
13
     */
14 102
    public static function isValidCountryCode($country)
15
    {
16 102
        return ISO3166::isValid($country);
17
    }
18
19
    /**
20
     * Parse the provided phone countries to a valid array.
21
     *
22
     * @param string|array $countries
23
     * @return array
24
     */
25 96
    protected function parseCountries($countries)
26
    {
27 96
        return Collection::make(is_array($countries) ? $countries : func_get_args())
28
                         ->map(function ($country) {
29 96
                             return strtoupper($country);
30 96
                         })
31 96
                         ->filter(function ($value) {
32 96
                             return static::isValidCountryCode($value);
33 96
                         })->toArray();
34
    }
35
}