Completed
Pull Request — 3.x (#129)
by David
01:54
created

Url   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 45
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 6 2
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/mit-license.php MIT
7
 *
8
 */
9
namespace Aura\Router\Helper;
10
11
use Aura\Router\Exception\RouteNotFound;
12
use Aura\Router\Generator;
13
14
/**
15
 *
16
 * Generic Url Helper class
17
 *
18
 * @package Aura.Router
19
 *
20
 */
21
class Url
22
{
23
    /**
24
     *
25
     * The Generator object used by the RouteContainer
26
     *
27
     * @var Generator
28
     *
29
     */
30
    protected $generator;
31
32
    /**
33
     *
34
     * Constructor.
35
     *
36
     * @param Generator $generator The generator object to use
37
     *
38
     */
39 3
    public function __construct(Generator $generator)
40
    {
41 3
        $this->generator = $generator;
42 3
    }
43
44
    /**
45
     *
46
     * Returns the Generator
47
     *
48
     * @param string $name The name of the route to lookup.
49
     *
50
     * @param array $data The data to pass into the route.
51
     *
52
     * @param bool $returnRawUrl Whether or not to return the raw url.
53
     *
54
     * @return string The results of calling the appropriate _Generator_ method .
55
     *
56
     * @throws RouteNotFound When the route cannot be found.
57
     *
58
     */
59 2
    public function __invoke($name, array $data = [], $returnRawUrl = false)
60
    {
61
        return $returnRawUrl
62 2
            ? $this->generator->generateRaw($name, $data)
63 2
            : $this->generator->generate($name, $data);
64
    }
65
}