Completed
Push — master ( 664783...554f9d )
by
unknown
15:59
created

HomepageRenderEvent   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 57
ccs 0
cts 18
cp 0
rs 10
c 2
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addRoute() 0 7 1
A normalizeRelativeUrl() 0 7 2
A getRoutes() 0 4 1
1
<?php
2
/**
3
 * event object when the homepage is rendered
4
 */
5
6
namespace Graviton\CoreBundle\Event;
7
8
use Symfony\Component\EventDispatcher\Event;
9
10
/**
11
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
12
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
13
 * @link     http://swisscom.ch
14
 */
15
final class HomepageRenderEvent extends Event
16
{
17
    /**
18
     * our event name
19
     *
20
     * @var string
21
     */
22
    const EVENT_NAME = 'homepage.render';
23
24
    /**
25
     * added routes
26
     *
27
     * @var array
28
     */
29
    private $addedRoutes = [];
30
31
    /**
32
     * add a route to the homepage
33
     *
34
     * @param string $url       relative (to root) url to the service
35
     * @param string $schemaUrl relative (to root) url to the schema
36
     *
37
     * @return void
38
     */
39
    public function addRoute($url, $schemaUrl)
40
    {
41
        $this->addedRoutes[] = [
42
            '$ref' => $this->normalizeRelativeUrl($url),
43
            'profile' => $this->normalizeRelativeUrl($schemaUrl)
44
        ];
45
    }
46
47
    /**
48
     * remove possibly leading slash from url
49
     *
50
     * @param string $url url
51
     *
52
     * @return string url
53
     */
54
    private function normalizeRelativeUrl($url)
55
    {
56
        if (substr($url, 0, 1) == '/') {
57
            return substr($url, 1);
58
        }
59
        return $url;
60
    }
61
62
    /**
63
     * returns the routes
64
     *
65
     * @return array routes
66
     */
67
    public function getRoutes()
68
    {
69
        return $this->addedRoutes;
70
    }
71
}
72