Slim4Plugin::pathFor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EngineWorks\Templates\Slim;
6
7
use EngineWorks\Templates\Plugin;
8
use Slim\Interfaces\RouteParserInterface;
9
10
class Slim4Plugin implements Plugin
11
{
12
    /**
13
     * @inheritdoc
14
     * @return array{pathFor: string, baseUrl: string}
15
     */
16 1
    public function getCallablesTable(): array
17
    {
18
        return [
19 1
            'pathFor' => 'pathFor',
20
            'baseUrl' => 'baseUrl',
21
        ];
22
    }
23
24
    /** @var RouteParserInterface */
25
    private $router;
26
27
    /** @var string */
28
    private $baseUrl;
29
30 2
    public function __construct(RouteParserInterface $router, string $baseUrl)
31
    {
32 2
        $this->router = $router;
33 2
        $this->baseUrl = $baseUrl;
34
    }
35
36
    /**
37
     * @param string $name
38
     * @param string[] $data
39
     * @param string[] $queryParams
40
     * @return string
41
     */
42 1
    public function pathFor(string $name, array $data = [], array $queryParams = []): string
43
    {
44 1
        return $this->router->urlFor($name, $data, $queryParams);
45
    }
46
47 1
    public function baseUrl(): string
48
    {
49 1
        return $this->baseUrl;
50
    }
51
}
52