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

ParamLocaleResolver::setParam()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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
?>