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

src/Resolvers/EnvironmentLocaleResolver.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
Expected 1 space after closing parenthesis; found 0
Loading history...
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
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
Expected 1 space after closing parenthesis; found 0
Loading history...
Inline shorthand IF statement must be declared on a single line
Loading history...
41 1
    return $this->getLang();
42
  }
43
}
44
?>