Failed Conditions
Pull Request — master (#50)
by Bernhard
06:13 queued 19s
created

RemovePathMappingFromModuleFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 7 2
A rollback() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the puli/manager 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\Manager\Repository\Mapping;
13
14
use Puli\Manager\Api\Module\RootModuleFile;
15
use Puli\Manager\Api\Repository\PathMapping;
16
use Puli\Manager\Transaction\AtomicOperation;
17
18
/**
19
 * Removes a path mapping from the root module file.
20
 *
21
 * @since  1.0
22
 *
23
 * @author Bernhard Schussek <[email protected]>
24
 */
25
class RemovePathMappingFromModuleFile implements AtomicOperation
26
{
27
    /**
28
     * @var string
29
     */
30
    private $repositoryPath;
31
32
    /**
33
     * @var RootModuleFile
34
     */
35
    private $rootModuleFile;
36
37
    /**
38
     * @var PathMapping
39
     */
40
    private $previousMapping;
41
42 12
    public function __construct($repositoryPath, RootModuleFile $rootModuleFile)
43
    {
44 12
        $this->repositoryPath = $repositoryPath;
45 12
        $this->rootModuleFile = $rootModuleFile;
46 12
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 12
    public function execute()
52
    {
53 12
        if ($this->rootModuleFile->hasPathMapping($this->repositoryPath)) {
54 12
            $this->previousMapping = $this->rootModuleFile->getPathMapping($this->repositoryPath);
55 12
            $this->rootModuleFile->removePathMapping($this->repositoryPath);
56
        }
57 12
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 4
    public function rollback()
63
    {
64 4
        if ($this->previousMapping) {
65 4
            $this->rootModuleFile->addPathMapping($this->previousMapping);
66
        }
67 4
    }
68
}
69