EnvironmentLocaleResolver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 11
c 0
b 0
f 0
dl 0
loc 28
rs 10
ccs 12
cts 12
cp 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 2 1
A setLang() 0 2 1
A setVarName() 0 2 1
A getVarName() 0 2 1
A getLang() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Translation\Resolvers;
5
6
use Nexendrie\Translation\ISettableLocaleResolver;
7
8
/**
9
 * EnvironmentResolver
10
 * Reads current language from an environment variable
11
 *
12
 * @author Jakub Konečný
13
 * @property string|null $lang
14
 * @property string $varName
15
 */
16 1
final class EnvironmentLocaleResolver implements ISettableLocaleResolver {
17 1
  use \Nette\SmartObject;
18
  
19
  /** @var string */
20
  protected $varName = "TRANSLATOR_LANGUAGE";
21
  
22
  public function getLang(): ?string {
23 1
    $lang = getenv($this->varName);
24 1
    if(is_string($lang)) {
25 1
      return $lang;
26
    }
27 1
    return null;
28
  }
29
  
30
  public function setLang(string $lang): void {
31 1
    putenv($this->varName . "=$lang");
32 1
  }
33
  
34
  public function getVarName(): string {
35 1
    return $this->varName;
36
  }
37
  
38
  public function setVarName(string $varName): void {
39 1
    $this->varName = $varName;
40 1
  }
41
  
42
  public function resolve(): ?string {
43 1
    return $this->getLang();
44
  }
45
}
46
?>