Passed
Push — master ( 1cf0a9...56b73d )
by Ayan
01:37
created

Service   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 25
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 17 3
1
<?php
2
3
namespace Phprest\Service\Hateoas;
4
5
use Hateoas\HateoasBuilder;
6
use Hateoas\UrlGenerator\CallableUrlGenerator;
7
use League\Container\ContainerInterface;
8
use Phprest\Service\Configurable;
9
use Phprest\Service\Serviceable;
10
11
class Service implements Serviceable
12
{
13
    /**
14
     * @param ContainerInterface $container
15
     * @param Configurable $config
16
     *
17
     * @return void
18
     */
19 21
    public function register(ContainerInterface $container, Configurable $config): void
20
    {
21 21
        if (! $config instanceof Config) {
22 1
            throw new \InvalidArgumentException('Wrong Config object');
23
        }
24
25 20
        $hateoas = HateoasBuilder::create();
26
27 20
        $hateoas->setDebug($config->debug);
28 20
        $hateoas->setUrlGenerator(null, new CallableUrlGenerator($config->urlGenerator));
29
30 20
        if (! $config->debug) {
31
            $hateoas->setCacheDir($config->cacheDir);
32
            $hateoas->addMetadataDir($config->metadataDir);
33
        }
34
35 20
        $container->add($config->getServiceName(), $hateoas->build());
36 20
    }
37
}
38