Completed
Push — 1.x ( 36cc2e...2affd8 )
by Akihito
26s queued 14s
created

ResourceClientModule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 34
ccs 0
cts 0
cp 0
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureDeprecatedBindings() 0 4 1
A configure() 0 20 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource\Module;
6
7
use BEAR\Resource\Anchor;
8
use BEAR\Resource\AnchorInterface;
9
use BEAR\Resource\ExtraMethodInvoker;
10
use BEAR\Resource\Factory;
11
use BEAR\Resource\FactoryInterface;
12
use BEAR\Resource\HalLink;
13
use BEAR\Resource\HalLinker;
14
use BEAR\Resource\Invoker;
15
use BEAR\Resource\InvokerInterface;
16
use BEAR\Resource\Linker;
17
use BEAR\Resource\LinkerInterface;
18
use BEAR\Resource\LoggerInterface;
19
use BEAR\Resource\NamedParameter;
20
use BEAR\Resource\NamedParameterInterface;
21
use BEAR\Resource\NamedParamMetas;
22
use BEAR\Resource\NamedParamMetasInterface;
23
use BEAR\Resource\NullLogger;
24
use BEAR\Resource\NullReverseLink;
25
use BEAR\Resource\NullReverseLinker;
26
use BEAR\Resource\OptionsMethods;
27
use BEAR\Resource\OptionsRenderer;
28
use BEAR\Resource\PrettyJsonRenderer;
29
use BEAR\Resource\RenderInterface;
30
use BEAR\Resource\Resource;
31
use BEAR\Resource\ResourceInterface;
32
use BEAR\Resource\ReverseLinkerInterface;
33
use BEAR\Resource\ReverseLinkInterface;
34
use BEAR\Resource\SchemeCollectionInterface;
35
use BEAR\Resource\UriFactory;
36
use Ray\Di\AbstractModule;
37
use Ray\Di\Exception\NotFound;
38
use Ray\Di\Scope;
39
40
/**
41 51
 * Provides ResourceInterface and derived bindings
42
 *
43 51
 * The following module is installed:
44 51
 *
45 51
 * UriFactory
46 51
 * ResourceInterface
47 51
 * InvokerInterface
48 51
 * LinkerInterface
49 51
 * FactoryInterface
50 51
 * SchemeCollectionInterface
51 51
 * AnchorInterface
52 51
 * NamedParameterInterface
53 51
 * RenderInterface
54 51
 * RenderInterface-options
55 51
 * OptionsMethods
56
 * NamedParamMetasInterface
57
 * ExtraMethodInvoker
58
 * HalLink
59
 * ReverseLinkInterface
60
 * LoggerInterface
61
 * HalLinker
62
 * ReverseLinkerInterface
63
 *
64
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
65
 */
66
final class ResourceClientModule extends AbstractModule
67
{
68
    /**
69
     * {@inheritDoc}
70
     *
71
     * @throws NotFound
72
     */
73
    protected function configure(): void
74
    {
75
        $this->bind(UriFactory::class);
76
        $this->bind(ResourceInterface::class)->to(Resource::class)->in(Scope::SINGLETON);
77
        $this->bind(InvokerInterface::class)->to(Invoker::class);
78
        $this->bind(LinkerInterface::class)->to(Linker::class);
79
        $this->bind(FactoryInterface::class)->to(Factory::class);
80
        $this->bind(SchemeCollectionInterface::class)->toProvider(SchemeCollectionProvider::class);
81
        $this->bind(AnchorInterface::class)->to(Anchor::class);
82
        $this->bind(NamedParameterInterface::class)->to(NamedParameter::class);
83
        $this->bind(RenderInterface::class)->to(PrettyJsonRenderer::class)->in(Scope::SINGLETON);
84
        /** @psalm-suppress DeprecatedClass */
85
        $this->bind(RenderInterface::class)->annotatedWith('options')->to(OptionsRenderer::class);
86
        $this->bind(OptionsMethods::class);
87
        $this->bind(NamedParamMetasInterface::class)->to(NamedParamMetas::class);
88
        $this->bind(ExtraMethodInvoker::class);
89
        $this->bind(HalLinker::class);
90
        $this->bind(ReverseLinkerInterface::class)->to(NullReverseLinker::class);
91
        $this->bind(LoggerInterface::class)->to(NullLogger::class);
92
        $this->configureDeprecatedBindings();
93
    }
94
95
    /** @psalm-suppress DeprecatedClass */
96
    private function configureDeprecatedBindings(): void
97
    {
98
        $this->bind(HalLink::class); // @phpstan-ignore
99
        $this->bind(ReverseLinkInterface::class)->to(NullReverseLink::class); // @phpstan-ignore
100
    }
101
}
102