Language::canAddLanguage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace kalanis\google_maps\Remote\Headers;
4
5
6
use kalanis\google_maps\ClientConfig;
7
8
9
/**
10
 * Class for work with language params
11
 */
12
class Language
13
{
14 57
    public function __construct(
15
        protected readonly ClientConfig $config,
16
    )
17
    {
18 57
    }
19
20
    /**
21
     * @param string $method
22
     * @return array<string, string>
23
     */
24 35
    public function getToQuery(string $method): array
25
    {
26 35
        $params = [];
27 35
        if ($this->canAddLanguage($method) && !empty($this->config->getLanguage())) {
28 2
            $params['language'] = $this->config->getLanguage();
29
        }
30 35
        return $params;
31
    }
32
33 35
    protected function canAddLanguage(string $method): bool
34
    {
35 35
        return ('GET' == strtoupper($method)) && $this->config->getLanguage();
36
    }
37
38 4
    public function getLanguage(): ?string
39
    {
40 4
        return $this->config->getLanguage();
41
    }
42
}
43