EnvironmentLocaleResolver   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
wmc 7
eloc 14
c 0
b 0
f 0
dl 0
loc 43
ccs 10
cts 13
cp 0.7692
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 2 1
A setLang() 0 5 2
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
 */
15 1
final class EnvironmentLocaleResolver implements ISettableLocaleResolver {
16
  use \Nette\SmartObject;
17
18
  public string $varName = "TRANSLATOR_LANGUAGE";
19
20
  /**
21
   * @deprecated Access the property directly
22
   */
23
  public function getLang(): ?string {
24 1
    $lang = getenv($this->varName);
25 1
    if(is_string($lang)) {
26 1
      return $lang;
27
    }
28 1
    return null;
29
  }
30
31
  /**
32
   * @deprecated Access the property directly
33
   */
34
  public function setLang(?string $lang): void {
35 1
    if($lang === null) {
36 1
      putenv($this->varName);
37
    } else {
38 1
      putenv($this->varName . "=$lang");
39
    }
40 1
  }
41
42
  /**
43
   * @deprecated Access the property directly
44
   */
45
  public function getVarName(): string {
46
    return $this->varName;
47
  }
48
49
  /**
50
   * @deprecated Access the property directly
51
   */
52
  public function setVarName(string $varName): void {
53
    $this->varName = $varName;
54
  }
55
  
56
  public function resolve(): ?string {
57 1
    return $this->getLang();
0 ignored issues
show
Deprecated Code introduced by
The function Nexendrie\Translation\Re...caleResolver::getLang() has been deprecated: Access the property directly ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

57
    return /** @scrutinizer ignore-deprecated */ $this->getLang();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
58
  }
59
}
60
?>