Completed
Pull Request — master (#366)
by Beñat
14:32
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\Notifier\Infrastructure\Application;
16
17
use Kreta\Notifier\Application\GetDomainEventsResponse;
18
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
19
20
class SymfonyRouterGetDomainEventsResponse implements GetDomainEventsResponse
21
{
22
    private $urlGenerator;
23
24
    public function __construct(UrlGeneratorInterface $urlGenerator)
25
    {
26
        $this->urlGenerator = $urlGenerator;
27
    }
28
29
    public function build(array $events, int $page, int $pageSize) : array
30
    {
31
        return [
32
            '_meta'  => [
33
                'count' => count($events),
34
                'page'  => $page,
35
            ],
36
            '_links' => [
37
                'first' => $this->urlGenerate(1),
38
                'next'  => $this->urlGenerate($page + 1),
39
                'self'  => $this->urlGenerate($page),
40
            ],
41
            'data'   => $events,
42
        ];
43
    }
44
45
    private function urlGenerate(int $page) : string
46
    {
47
        return $this->urlGenerator->generate(
48
            'kreta_notifier_get_domain_events',
49
            ['page' => $page],
50
            UrlGeneratorInterface::ABSOLUTE_URL
51
        );
52
    }
53
}
54