Completed
Pull Request — 1.0 (#58)
by Titouan
02:34
created

AbstractEditableRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 5
c 4
b 0
f 1
lcom 1
cbo 3
dl 0
loc 47
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A appendToChangeStream() 0 6 2
A getStack() 0 12 2
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;
13
14
use Puli\Repository\Api\ChangeStream\ChangeStream;
15
use Puli\Repository\Api\EditableRepository;
16
use Puli\Repository\Api\Resource\PuliResource;
17
use Puli\Repository\Api\UnsupportedOperationException;
18
19
/**
20
 * Abstract base for editable repositories providing tools to avoid code duplication.
21
 *
22
 * @since  1.0
23
 *
24
 * @author Bernhard Schussek <[email protected]>
25
 * @author Titouan Galopin <[email protected]>
26
 */
27
abstract class AbstractEditableRepository extends AbstractRepository implements EditableRepository
28
{
29
    /**
30
     * @var ChangeStream
31
     */
32
    private $changeStream;
33
34
    /**
35
     * Create the repository.
36
     *
37
     * @param ChangeStream|null $changeStream If provided, the repository will log
38
     *                                        resources changes in this change stream.
39
     */
40 604
    public function __construct(ChangeStream $changeStream = null)
41
    {
42 604
        $this->changeStream = $changeStream;
43 604
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 14
    public function getStack($path)
49
    {
50 14
        if (!$this->changeStream) {
51 7
            throw new UnsupportedOperationException(sprintf(
52
                'Could not retrieve the resource stack for path "%s" as no ChangeStream was passed to the '.
53 7
                'constructor of the repository.',
54
                $path
55 7
            ));
56
        }
57
58 7
        return $this->changeStream->buildStack($this, $path);
59
    }
60
61
    /**
62
     * Append a change to the ChangeStream if possible.
63
     *
64
     * @param string       $path
65
     * @param PuliResource $resource
66
     */
67 498
    protected function appendToChangeStream($path, PuliResource $resource)
0 ignored issues
show
Unused Code introduced by
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
    {
69 498
        if ($this->changeStream) {
70 7
            $this->changeStream->append($resource);
71 7
        }
72 498
    }
73
}
74