Passed
Push — master ( ffac22...5623ee )
by Jakub
01:55
created

ParamLocaleResolver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 7
eloc 13
c 3
b 0
f 1
dl 0
loc 29
ccs 12
cts 13
cp 0.9231
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 5 2
A onRequest() 0 6 3
A getParam() 0 2 1
A setParam() 0 2 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Translation\Bridges\NetteApplication;
5
6
use Nette\Application\Application;
7
use Nette\Application\Request;
8
9
/**
10
 * ParamLocaleResolver
11
 *
12
 * @author Jakub Konečný
13
 * @property string $param
14
 */
15 1
final class ParamLocaleResolver implements IAppRequestAwareLocaleResolver {
16 1
  use \Nette\SmartObject;
17
  
18
  /** @var Request|null */
19
  protected $request = null;
20
  /** @var string */
21
  protected $param = "locale";
22
  
23
  public function getParam(): string {
24 1
    return $this->param;
25
  }
26
  
27
  public function setParam(string $param): void {
28 1
    $this->param = $param;
29 1
  }
30
  
31
  public function onRequest(Application $application, Request $request): void {
32 1
    $locale = $request->getParameter($this->param);
33 1
    if($request->method === Request::FORWARD && $locale === null) {
34
      return;
35
    }
36 1
    $this->request = $request;
37 1
  }
38
  
39
  public function resolve(): ?string {
40 1
    if($this->request !== null) {
41 1
      return $this->request->getParameter($this->param);
42
    }
43 1
    return null;
44
  }
45
}
46
?>