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
  function getLang(): ?string {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
21 1
    $lang = getenv($this->varName);
22 1
    if($lang) {
23 1
      return $lang;
24
    }
25 1
    return NULL;
26
  }
27
  
28
  function setLang(string $lang) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29 1
    putenv($this->varName . "=$lang");
30 1
  }
31
  
32
  function getVarName(): string {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33 1
    return $this->varName;
34
  }
35
  
36
  function setVarName(string $varName) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37 1
    $this->varName = $varName;
38 1
  }
39
  
40
  function resolve(): ?string {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
41 1
    return $this->getLang();
42
  }
43
}
44
?>