EnvironmentLocaleResolver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getLang() 0 7 2
A setLang() 0 3 1
A getVarName() 0 3 1
A setVarName() 0 3 1
A resolve() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Translation\Resolvers;
5
6
/**
7
 * EnvironmentResolver
8
 * Reads current language from an environment variable
9
 *
10
 * @author Jakub Konečný
11
 * @property string|NULL $lang
12
 * @property string $varName
13
 */
14 1
class EnvironmentLocaleResolver implements ILocaleResolver {
15 1
  use \Nette\SmartObject;
16
  
17
  /** @var string */
18
  protected $varName = "TRANSLATOR_LANGUAGE";
19
  
20
  public function getLang(): ?string {
0 ignored issues
show
Coding Style introduced by Jakub Konečný
Expected 1 space after closing parenthesis; found 0
Loading history...
Coding Style introduced by Jakub Konečný
Inline shorthand IF statement must be declared on a single line
Loading history...
21 1
    $lang = getenv($this->varName);
22 1
    if($lang) {
23 1
      return $lang;
24
    }
25 1
    return NULL;
26
  }
27
  
28
  public function setLang(string $lang) {
29 1
    putenv($this->varName . "=$lang");
30 1
  }
31
  
32
  public function getVarName(): string {
0 ignored issues
show
Coding Style introduced by Jakub Konečný
Expected 1 space after closing parenthesis; found 0
Loading history...
33 1
    return $this->varName;
34
  }
35
  
36
  public function setVarName(string $varName) {
37 1
    $this->varName = $varName;
38 1
  }
39
  
40
  public function resolve(): ?string {
0 ignored issues
show
Coding Style introduced by Jakub Konečný
Expected 1 space after closing parenthesis; found 0
Loading history...
Coding Style introduced by Jakub Konečný
Inline shorthand IF statement must be declared on a single line
Loading history...
41 1
    return $this->getLang();
42
  }
43
}
44
?>