Total Complexity | 4 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | class UrlTransformer |
||
12 | { |
||
13 | /** |
||
14 | * @var Request |
||
15 | */ |
||
16 | protected $request = null; |
||
17 | |||
18 | /** |
||
19 | * @param Request $request |
||
20 | * @return UrlTransformer |
||
21 | */ |
||
22 | 4 | public static function from(Request $request = null) |
|
23 | { |
||
24 | 4 | $transformer = new self($request); |
|
25 | 4 | return $transformer; |
|
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param $url |
||
30 | * @param $section |
||
31 | * @return string |
||
32 | */ |
||
33 | 4 | public function transform($url, $section) |
|
34 | { |
||
35 | 4 | $http = $this->request->getHttp(); |
|
36 | 4 | $httpSubdomain = $http->getSubdomain(); |
|
37 | 4 | $rootDomain = $http->getRootDomain(); |
|
38 | |||
39 | 4 | $replace = '://' . $section->getSubdomain() . '.' . $rootDomain; |
|
40 | $transform = [ |
||
41 | 4 | '://' . $httpSubdomain . '.' . $rootDomain => $replace, |
|
42 | 4 | '://' . $rootDomain => $replace, |
|
43 | ]; |
||
44 | |||
45 | 4 | $url = strtr($url, $transform); |
|
46 | 4 | return $url; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * UrlTransformer constructor. |
||
51 | * @param Request|null $request |
||
52 | */ |
||
53 | 4 | protected function __construct(Request $request = null) |
|
56 | } |
||
57 | } |