Failed Conditions
Pull Request — master (#56)
by Bernhard
11:07
created

cannotEnableBinding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
cc 1
eloc 7
nc 1
nop 3
crap 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\Api;
13
14
use Exception;
15
use Rhumsaa\Uuid\Uuid;
16
use RuntimeException;
17
18
/**
19
 * Thrown when an operation was performed for the root module when a non-root
20
 * module was expected.
21
 *
22
 * @since  1.0
23
 *
24
 * @author Bernhard Schussek <[email protected]>
25
 */
26
class NonRootModuleExpectedException extends RuntimeException
27
{
28
    /**
29
     * Creates an exception for a binding UUID that could not be enabled in the
30
     * root module.
31
     *
32
     * @param Uuid           $uuid       The UUID.
33
     * @param string         $moduleName The name of the module.
34
     * @param Exception|null $cause      The exception that caused this
35
     *                                   exception.
36
     *
37
     * @return static The created exception.
38
     */
39
    public static function cannotEnableBinding(Uuid $uuid, $moduleName, Exception $cause = null)
40
    {
41
        return new static(sprintf(
42
            'Cannot enable binding "%s" in module "%s": Can only enable '.
43
            'bindings in non-root modules.',
44
            $uuid->toString(),
45
            $moduleName
46
        ), 0, $cause);
47
    }
48
49
    /**
50
     * Creates an exception for a binding UUID that could not be disabled in the
51
     * root module.
52
     *
53
     * @param Uuid           $uuid       The UUID.
54
     * @param string         $moduleName The name of the module.
55
     * @param Exception|null $cause      The exception that caused this
56
     *                                   exception.
57
     *
58
     * @return static The created exception.
59
     */
60
    public static function cannotDisableBinding(Uuid $uuid, $moduleName, Exception $cause = null)
61
    {
62
        return new static(sprintf(
63
            'Cannot disable binding "%s" in module "%s": Can only disable '.
64
            'bindings in non-root modules.',
65
            $uuid->toString(),
66
            $moduleName
67
        ), 0, $cause);
68
    }
69
}
70