Skip to content

Commit 8fdb638

Browse files
committed
Refactor Configuration.php
1 parent 8489340 commit 8fdb638

File tree

10 files changed

+21
-56
lines changed

10 files changed

+21
-56
lines changed

src/Command/MainCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Deployer\Command;
1212

13-
use Deployer\Configuration\Configuration;
13+
use Deployer\Configuration;
1414
use Deployer\Deployer;
1515
use Deployer\Exception\Exception;
1616
use Deployer\Exception\GracefulShutdownException;
Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Deployer\Configuration;
11+
namespace Deployer;
1212

13-
use Deployer\Deployer;
1413
use Deployer\Exception\ConfigurationException;
1514
use Deployer\Utility\Httpie;
1615

@@ -20,15 +19,8 @@
2019

2120
class Configuration implements \ArrayAccess
2221
{
23-
/**
24-
* @var Configuration|null
25-
*/
26-
private $parent;
27-
28-
/**
29-
* @var array
30-
*/
31-
private $values = [];
22+
private ?Configuration $parent;
23+
private array $values = [];
3224

3325
public function __construct(?Configuration $parent = null)
3426
{
@@ -45,10 +37,7 @@ public function bind(Configuration $parent): void
4537
$this->parent = $parent;
4638
}
4739

48-
/**
49-
* @param mixed $value
50-
*/
51-
public function set(string $name, $value): void
40+
public function set(string $name, mixed $value): void
5241
{
5342
$this->values[$name] = $value;
5443
}
@@ -83,11 +72,7 @@ public function add(string $name, array $array): void
8372
}
8473
}
8574

86-
/**
87-
* @param mixed|null $default
88-
* @return mixed|null
89-
*/
90-
public function get(string $name, $default = null)
75+
public function get(string $name, mixed $default = null): mixed
9176
{
9277
if (array_key_exists($name, $this->values)) {
9378
if (is_closure($this->values[$name])) {
@@ -115,10 +100,7 @@ public function get(string $name, $default = null)
115100
throw new ConfigurationException("Config option \"$name\" does not exist.");
116101
}
117102

118-
/**
119-
* @return mixed|null
120-
*/
121-
public function fetch(string $name)
103+
protected function fetch(string $name): mixed
122104
{
123105
if (array_key_exists($name, $this->values)) {
124106
return $this->values[$name];
@@ -129,41 +111,25 @@ public function fetch(string $name)
129111
return null;
130112
}
131113

132-
/**
133-
* @param string|mixed $value
134-
* @return string|mixed
135-
*/
136-
public function parse($value)
114+
public function parse(mixed $value): mixed
137115
{
138116
if (is_string($value)) {
139117
$normalizedValue = normalize_line_endings($value);
140-
return preg_replace_callback('/\{\{\s*([\w\.\/-]+)\s*\}\}/', [$this, 'parseCallback'], $normalizedValue);
118+
return preg_replace_callback('/\{\{\s*([\w\.\/-]+)\s*\}\}/', function (array $matches) {
119+
return isset($matches[1]) ? $this->get($matches[1]) : null;
120+
}, $normalizedValue);
141121
}
142122

143123
return $value;
144124
}
145125

146-
public function ownValues(): array
147-
{
148-
return $this->values;
149-
}
150-
151126
public function keys(): array
152127
{
153128
return array_keys($this->values);
154129
}
155130

156131
/**
157-
* @param array $matches
158-
* @return mixed|null
159-
*/
160-
private function parseCallback(array $matches)
161-
{
162-
return isset($matches[1]) ? $this->get($matches[1]) : null;
163-
}
164-
165-
/**
166-
* @param mixed $offset
132+
* @param string $offset
167133
* @return bool
168134
*/
169135
#[\ReturnTypeWillChange]
@@ -174,8 +140,7 @@ public function offsetExists($offset)
174140

175141
/**
176142
* @param string $offset
177-
* @return mixed|null
178-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
143+
* @return mixed
179144
*/
180145
#[\ReturnTypeWillChange]
181146
public function offsetGet($offset)
@@ -186,7 +151,6 @@ public function offsetGet($offset)
186151
/**
187152
* @param string $offset
188153
* @param mixed $value
189-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
190154
*/
191155
#[\ReturnTypeWillChange]
192156
public function offsetSet($offset, $value): void

src/Deployer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use Deployer\ProcessRunner\Printer;
2626
use Deployer\ProcessRunner\ProcessRunner;
2727
use Deployer\Ssh\SshClient;
28-
use Deployer\Configuration\Configuration;
28+
use Deployer\Configuration;
2929
use Deployer\Executor\Master;
3030
use Deployer\Executor\Messenger;
3131
use Deployer\Host\Host;

src/Host/Host.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Deployer\Host;
1212

13-
use Deployer\Configuration\Configuration;
13+
use Deployer\Configuration;
1414
use Deployer\Deployer;
1515
use Deployer\Exception\ConfigurationException;
1616
use Deployer\Exception\Exception;

src/Task/Context.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Deployer\Task;
1212

13-
use Deployer\Configuration\Configuration;
13+
use Deployer\Configuration;
1414
use Deployer\Exception\Exception;
1515
use Deployer\Host\Host;
1616
use Symfony\Component\Console\Input\InputInterface;

tests/src/Configuration/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Deployer\Configuration;
44

5+
use Deployer\Configuration;
56
use Deployer\Exception\ConfigurationException;
67
use PHPUnit\Framework\TestCase;
78

tests/src/FunctionsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Deployer;
99

10-
use Deployer\Configuration\Configuration;
10+
use Deployer\Configuration;
1111
use Deployer\Host\Host;
1212
use Deployer\Host\Localhost;
1313
use Deployer\Task\Context;

tests/src/Host/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Deployer\Host;
99

10-
use Deployer\Configuration\Configuration;
10+
use Deployer\Configuration;
1111
use Deployer\Exception\ConfigurationException;
1212
use PHPUnit\Framework\TestCase;
1313

tests/src/Host/HostTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Deployer\Host;
99

10-
use Deployer\Configuration\Configuration;
10+
use Deployer\Configuration;
1111
use PHPUnit\Framework\TestCase;
1212

1313
class HostTest extends TestCase

tests/src/Task/ContextTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Deployer\Task;
99

10-
use Deployer\Configuration\Configuration;
10+
use Deployer\Configuration;
1111
use Deployer\Host\Host;
1212
use PHPUnit\Framework\TestCase;
1313
use Symfony\Component\Console\Input\InputInterface;

0 commit comments

Comments
 (0)