SubCommandConfig::getDefaultHandler()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the webmozart/console 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 Webmozart\Console\Api\Config;
13
14
/**
15
 * The configuration of an console sub-command.
16
 *
17
 * A sub-command is defined within the scope of another command. For example,
18
 * in the command `server add <host>`, the command "add" is a sub-command of the
19
 * "server" command.
20
 *
21
 * @since  1.0
22
 *
23
 * @author Bernhard Schussek <[email protected]>
24
 *
25
 * @see    OptionCommandConfig
26
 */
27
class SubCommandConfig extends CommandConfig
28
{
29
    /**
30
     * @var CommandConfig
31
     */
32
    private $parentConfig;
33
34
    /**
35
     * Creates a new configuration.
36
     *
37
     * @param string        $name         The name of the command.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $name not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
38
     * @param CommandConfig $parentConfig The command configuration that
0 ignored issues
show
Documentation introduced by
Should the type for parameter $parentConfig not be null|CommandConfig?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
39
     *                                    contains this configuration.
40
     */
41 85
    public function __construct($name = null, CommandConfig $parentConfig = null)
42
    {
43 85
        parent::__construct($name);
44
45 85
        if ($parentConfig) {
46 22
            $this->setParentConfig($parentConfig);
47
        }
48 85
    }
49
50
    /**
51
     * Returns the parent command configuration.
52
     *
53
     * @return CommandConfig The parent command configuration.
54
     */
55 4
    public function getParentConfig()
56
    {
57 4
        return $this->parentConfig;
58
    }
59
60
    /**
61
     * Sets the parent command configuration.
62
     *
63
     * @param CommandConfig $parentConfig The parent command configuration.
64
     */
65 50
    public function setParentConfig(CommandConfig $parentConfig)
66
    {
67 50
        $this->parentConfig = $parentConfig;
68
69 50
        if ($parentConfig->getApplicationConfig()) {
70 30
            $this->setApplicationConfig($parentConfig->getApplicationConfig());
71
        }
72 50
    }
73
74
    /**
75
     * Ends the block when dynamically configuring a nested configuration.
76
     *
77
     * This method is usually used together with
78
     * {@link CommandConfig::beginSubCommand()},
79
     * {@link CommandConfig::beginOptionCommand()} or
80
     * {@link CommandConfig::beginDefaultCommand()}:
81
     *
82
     * ```php
83
     * $config
84
     *     ->beginSubCommand('add')
85
     *         // ...
86
     *     ->end()
87
     *
88
     *     // ...
89
     * ;
90
     * ```
91
     *
92
     * @return CommandConfig|SubCommandConfig|OptionCommandConfig The parent command configuration.
93
     */
94 14
    public function end()
95
    {
96 14
        return $this->parentConfig;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 1
    protected function getDefaultHelperSet()
103
    {
104 1
        return $this->parentConfig
105 1
            ? $this->parentConfig->getHelperSet()
106 1
            : parent::getDefaultHelperSet();
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112 1
    protected function getDefaultHandler()
113
    {
114 1
        return $this->parentConfig
115 1
            ? $this->parentConfig->getHandler()
116 1
            : parent::getDefaultHandler();
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122 5
    protected function getDefaultHandlerMethod()
123
    {
124 5
        return $this->parentConfig
125 5
            ? $this->parentConfig->getHandlerMethod()
126 5
            : parent::getDefaultHandlerMethod();
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132 127
    protected function getDefaultArgsParser()
133
    {
134 127
        return $this->parentConfig
135 127
            ? $this->parentConfig->getArgsParser()
136 127
            : parent::getDefaultArgsParser();
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142 127
    protected function getDefaultLenientArgsParsing()
143
    {
144 127
        return $this->parentConfig
145 127
            ? $this->parentConfig->isLenientArgsParsingEnabled()
146 127
            : parent::getDefaultLenientArgsParsing();
147
    }
148
}
149