CountryFormatter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Temidaio\ValueObjects\Formatters;
6
7
use Illuminate\Support\Str;
8
use MichaelRubel\Formatters\Formatter;
9
10
class CountryFormatter implements Formatter
11
{
12
    /**
13
     * @param string|null $country
14
     * @param string|null $iso_code
15
     */
16 36
    public function __construct(
17
        public ?string $country  = null,
18
        public ?string $iso_code = null
19
    ) {
20 36
    }
21
22
    /**
23
     * Run the formatter.
24
     *
25
     * @return string
26
     */
27 36
    public function format(): string
28
    {
29 36
        if (! empty($this->country)) {
30 21
            return Str::ucfirst($this->country);
31 15
        } elseif (! empty($this->iso_code)) {
32 2
            return Str::upper($this->iso_code);
33
        }
34
35 13
        return '';
36
    }
37
}
38