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

ResourceBindingInitializer::acceptsBinding()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 3
eloc 4
nc 3
nop 1
crap 3
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