Completed
Push — 1.0 ( 0e2cc5...14cdbe )
by Bernhard
02:42
created

AbstractEditableRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 5
c 4
b 1
f 2
lcom 1
cbo 2
dl 0
loc 42
ccs 11
cts 12
cp 0.9167
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getStack() 0 8 2
A appendToChangeStream() 0 6 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
18
/**
19
 * Abstract base for editable repositories providing tools to avoid code duplication.
20
 *
21
 * @since  1.0
22
 *
23
 * @author Bernhard Schussek <[email protected]>
24
 * @author Titouan Galopin <[email protected]>
25
 */
26
abstract class AbstractEditableRepository extends AbstractRepository implements EditableRepository
27
{
28
    /**
29
     * @var ChangeStream
30
     */
31
    private $changeStream;
32
33
    /**
34
     * Create the repository.
35
     *
36
     * @param ChangeStream|null $changeStream If provided, the repository will log
37
     *                                        resources changes in this change stream.
38
     */
39 608
    public function __construct(ChangeStream $changeStream = null)
40
    {
41 608
        $this->changeStream = $changeStream;
42 608
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 14
    public function getStack($path)
48
    {
49 14
        if (!$this->changeStream) {
50
            return parent::getStack($path);
51
        }
52
53 14
        return $this->changeStream->buildStack($this, $path);
54
    }
55
56
    /**
57
     * Append a change to the ChangeStream if possible.
58
     *
59
     * @param PuliResource $resource
60
     */
61 491
    protected function appendToChangeStream(PuliResource $resource)
62
    {
63 491
        if ($this->changeStream) {
64 7
            $this->changeStream->append($resource);
65 7
        }
66 491
    }
67
}
68