Completed
Push — 1.0 ( 85ea96...11ed4b )
by Bernhard
04:23
created

ResourceBindingInitializer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 44
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A acceptsBinding() 0 6 3
A getAcceptedBindingClass() 0 4 1
A initializeBinding() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the puli/repository package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Repository\Discovery;
13
14
use Puli\Discovery\Api\Binding\Binding;
15
use Puli\Discovery\Api\Binding\Initializer\BindingInitializer;
16
use Puli\Repository\Api\ResourceRepository;
17
use Webmozart\Assert\Assert;
18
19
/**
20
 * @since  1.0
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class ResourceBindingInitializer implements BindingInitializer
25
{
26
    /**
27
     * @var ResourceRepository
28
     */
29
    private $repo;
30
31
    /**
32
     * @param ResourceRepository $repo
33
     */
34 6
    public function __construct(ResourceRepository $repo)
35
    {
36 6
        $this->repo = $repo;
37 6
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 2
    public function acceptsBinding($binding)
43
    {
44 2
        return $binding instanceof ResourceBinding
45 2
            || $binding === 'Puli\Repository\Discovery\ResourceBinding'
46 2
            || is_subclass_of($binding, 'Puli\Repository\Discovery\ResourceBinding');
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 1
    public function getAcceptedBindingClass()
53
    {
54 1
        return 'Puli\Repository\Discovery\ResourceBinding';
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 3
    public function initializeBinding(Binding $binding)
61
    {
62 3
        Assert::isInstanceOf($binding, 'Puli\Repository\Discovery\ResourceBinding', 'The binding must be an instance of ResourceBinding. Got: %s');
63
64
        /* @var ResourceBinding $binding */
65 2
        $binding->setRepository($this->repo);
66 2
    }
67
}
68