Passed
Push — master ( bb74df...01777c )
by Jakub
02:24
created

EnvironmentLocaleResolver::setLang()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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
Expected 1 space after closing parenthesis; found 0
Loading history...
Coding Style introduced by
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
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
Expected 1 space after closing parenthesis; found 0
Loading history...
Coding Style introduced by
Inline shorthand IF statement must be declared on a single line
Loading history...
41 1
    return $this->getLang();
42
  }
43
}
44
?>