Skip to content

Commit ad94f10

Browse files
committed
added PHP 8 typehints
1 parent 15f2109 commit ad94f10

2 files changed

Lines changed: 9 additions & 28 deletions

File tree

src/Bootstrap/Configurator.php

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,11 @@ public function __construct()
7878

7979
/**
8080
* Set parameter %debugMode%.
81-
* @param bool|string|array $value
82-
* @return static
8381
*/
84-
public function setDebugMode($value)
82+
public function setDebugMode(bool|string|array $value): static
8583
{
8684
if (is_string($value) || is_array($value)) {
8785
$value = static::detectDebugMode($value);
88-
} elseif (!is_bool($value)) {
89-
throw new Nette\InvalidArgumentException(sprintf('Value must be either a string, array, or boolean, %s given.', gettype($value)));
9086
}
9187

9288
$this->staticParameters['debugMode'] = $value;
@@ -103,9 +99,8 @@ public function isDebugMode(): bool
10399

104100
/**
105101
* Sets path to temporary directory.
106-
* @return static
107102
*/
108-
public function setTempDirectory(string $path)
103+
public function setTempDirectory(string $path): static
109104
{
110105
$this->staticParameters['tempDir'] = $path;
111106
return $this;
@@ -114,9 +109,8 @@ public function setTempDirectory(string $path)
114109

115110
/**
116111
* Sets the default timezone.
117-
* @return static
118112
*/
119-
public function setTimeZone(string $timezone)
113+
public function setTimeZone(string $timezone): static
120114
{
121115
date_default_timezone_set($timezone);
122116
@ini_set('date.timezone', $timezone); // @ - function may be disabled
@@ -126,19 +120,17 @@ public function setTimeZone(string $timezone)
126120

127121
/**
128122
* Alias for addStaticParameters()
129-
* @return static
130123
*/
131-
public function addParameters(array $params)
124+
public function addParameters(array $params): static
132125
{
133126
return $this->addStaticParameters($params);
134127
}
135128

136129

137130
/**
138131
* Adds new static parameters.
139-
* @return static
140132
*/
141-
public function addStaticParameters(array $params)
133+
public function addStaticParameters(array $params): static
142134
{
143135
$this->staticParameters = DI\Config\Helpers::merge($params, $this->staticParameters);
144136
return $this;
@@ -147,9 +139,8 @@ public function addStaticParameters(array $params)
147139

148140
/**
149141
* Adds new dynamic parameters.
150-
* @return static
151142
*/
152-
public function addDynamicParameters(array $params)
143+
public function addDynamicParameters(array $params): static
153144
{
154145
$this->dynamicParameters = $params + $this->dynamicParameters;
155146
return $this;
@@ -158,9 +149,8 @@ public function addDynamicParameters(array $params)
158149

159150
/**
160151
* Add instances of services.
161-
* @return static
162152
*/
163-
public function addServices(array $services)
153+
public function addServices(array $services): static
164154
{
165155
$this->services = $services + $this->services;
166156
return $this;
@@ -234,10 +224,8 @@ public function createRobotLoader(): Nette\Loaders\RobotLoader
234224

235225
/**
236226
* Adds configuration file.
237-
* @param string|array $config
238-
* @return static
239227
*/
240-
public function addConfig($config)
228+
public function addConfig(string|array $config): static
241229
{
242230
$this->configs[] = $config;
243231
return $this;
@@ -352,9 +340,8 @@ protected function getCacheDirectory(): string
352340

353341
/**
354342
* Detects debug mode by IP addresses or computer names whitelist detection.
355-
* @param string|array $list
356343
*/
357-
public static function detectDebugMode($list = null): bool
344+
public static function detectDebugMode(string|array $list = null): bool
358345
{
359346
$addr = $_SERVER['REMOTE_ADDR'] ?? php_uname('n');
360347
$secret = is_string($_COOKIE[self::CookieSecret] ?? null)

tests/Bootstrap/Configurator.debugMode.phpt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ test('', function () {
3232
});
3333

3434

35-
Assert::exception(function () {
36-
$configurator = new Configurator;
37-
$configurator->setDebugMode(1);
38-
}, Nette\InvalidArgumentException::class);
39-
40-
4135
test('localhost', function () {
4236
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
4337

0 commit comments

Comments
 (0)