SessionLocaleResolver   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 8
eloc 19
c 4
b 1
f 1
dl 0
loc 51
ccs 15
cts 18
cp 0.8333
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getVarName() 0 2 1
A __construct() 0 8 2
A resolve() 0 2 1
A setLang() 0 2 1
A setVarName() 0 2 1
A getLang() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Translation\Resolvers;
5
6
use Nette\Http\Session;
7
use Nette\Http\SessionSection;
8
use Nette\Http\RequestFactory;
9
use Nette\Http\Response;
10
use Nexendrie\Translation\ISettableLocaleResolver;
11
12
/**
13
 * SessionLocaleResolver
14
 *
15
 * @author Jakub Konečný
16
 * @property string|null $lang
17
 */
18 1
final class SessionLocaleResolver implements ISettableLocaleResolver {
19
  use \Nette\SmartObject;
20
21
  private Session $session;
22
  private SessionSection $section;
23
  public string $varName = "lang";
24
  
25
  public function __construct(Session $session = null) {
26 1
    if($session === null) {
27 1
      $request = (new RequestFactory())->fromGlobals();
28 1
      $response = new Response();
29 1
      $session = new Session($request, $response);
30
    }
31 1
    $this->session = $session;
32 1
    $this->section = $session->getSection(get_class($this));
33 1
  }
34
35
  /**
36
   * @deprecated Access the property directly
37
   */
38
  public function getLang(): ?string {
39 1
    $lang = (string) $this->section->{$this->varName};
40 1
    if($lang === '') {
41 1
      return null;
42
    }
43 1
    return $lang;
44
  }
45
46
  /**
47
   * @deprecated Access the property directly
48
   */
49
  public function setLang(?string $lang): void {
50 1
    $this->section->{$this->varName} = $lang;
51 1
  }
52
53
  /**
54
   * @deprecated Access the property directly
55
   */
56
  public function getVarName(): string {
57
    return $this->varName;
58
  }
59
60
  /**
61
   * @deprecated Access the property directly
62
   */
63
  public function setVarName(string $varName): void {
64
    $this->varName = $varName;
65
  }
66
  
67
  public function resolve(): ?string {
68 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

68
    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...
69
  }
70
}
71
?>