88 * file that was distributed with this source code.
99 */
1010
11- namespace Deployer \ Configuration ;
11+ namespace Deployer ;
1212
13- use Deployer \Deployer ;
1413use Deployer \Exception \ConfigurationException ;
1514use Deployer \Utility \Httpie ;
1615
2019
2120class 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
0 commit comments