Skip to content

Commit cf3a503

Browse files
committed
Upgrade to PHP 8.1 and higher and renamed methods for floats.
1 parent c959d3c commit cf3a503

File tree

5 files changed

+74
-74
lines changed

5 files changed

+74
-74
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
"type": "library",
1515
"license": "MIT",
1616
"require": {
17-
"php": ">=7.4",
18-
"hassankhan/config": "^3.0.1",
19-
"setbased/helper-cast": "^2.1.1"
17+
"php": ">=8.1",
18+
"hassankhan/config": "^3.1.0",
19+
"setbased/helper-cast": "^3.0.0"
2020
},
2121
"minimum-stability": "dev",
2222
"prefer-stable": true,
2323
"require-dev": {
24-
"phing/phing": "^3.0.0-RC3",
25-
"phpunit/phpunit": "^9.5.27"
24+
"phing/phing": "^3.0.0-RC4",
25+
"phpunit/phpunit": "^9.5.28"
2626
},
2727
"autoload": {
2828
"psr-4": {

src/TypedConfig.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TypedConfig
1818
*
1919
* @var Config
2020
*/
21-
private $config;
21+
private Config $config;
2222

2323
//--------------------------------------------------------------------------------------------------------------------
2424
/**
@@ -41,7 +41,7 @@ public function __construct(Config $config)
4141
*
4242
* @return TypedConfigException
4343
*/
44-
private static function createException(string $key, string $type, $value): TypedConfigException
44+
private static function createException(string $key, string $type, mixed $value): TypedConfigException
4545
{
4646
return new TypedConfigException($key, $type, $value);
4747
}
@@ -114,12 +114,12 @@ public function getManBool(string $key, ?bool $default = null): bool
114114
*
115115
* @throws TypedConfigException
116116
*/
117-
public function getManFiniteFloat(string $key, ?float $default = null): float
117+
public function getManFloat(string $key, ?float $default = null): float
118118
{
119119
$value = $this->config->get($key, $default);
120120
try
121121
{
122-
return Cast::toManFiniteFloat($value);
122+
return Cast::toManFloat($value);
123123
}
124124
catch (InvalidCastException $exception)
125125
{
@@ -129,7 +129,7 @@ public function getManFiniteFloat(string $key, ?float $default = null): float
129129

130130
//--------------------------------------------------------------------------------------------------------------------
131131
/**
132-
* Returns the value of a mandatory float configuration setting.
132+
* Returns the value of a mandatory float including NaN, -INF, and INF configuration setting.
133133
*
134134
* @param string $key The key of the configuration setting. The key might be nested using dot notation.
135135
* @param float|null $default The default value.
@@ -138,16 +138,16 @@ public function getManFiniteFloat(string $key, ?float $default = null): float
138138
*
139139
* @throws TypedConfigException
140140
*/
141-
public function getManFloat(string $key, ?float $default = null): float
141+
public function getManFloatInclusive(string $key, ?float $default = null): float
142142
{
143143
$value = $this->config->get($key, $default);
144144
try
145145
{
146-
return Cast::toManFloat($value);
146+
return Cast::toManFloatInclusive($value);
147147
}
148148
catch (InvalidCastException $exception)
149149
{
150-
throw self::createException($key, 'float', $value);
150+
throw self::createException($key, 'float inclusive', $value);
151151
}
152152
}
153153

@@ -256,12 +256,12 @@ public function getOptBool(string $key, ?bool $default = null): ?bool
256256
*
257257
* @throws TypedConfigException
258258
*/
259-
public function getOptFiniteFloat(string $key, ?float $default = null): ?float
259+
public function getOptFloat(string $key, ?float $default = null): ?float
260260
{
261261
$value = $this->config->get($key, $default);
262262
try
263263
{
264-
return Cast::toOptFiniteFloat($value);
264+
return Cast::toOptFloat($value);
265265
}
266266
catch (InvalidCastException $exception)
267267
{
@@ -271,7 +271,7 @@ public function getOptFiniteFloat(string $key, ?float $default = null): ?float
271271

272272
//--------------------------------------------------------------------------------------------------------------------
273273
/**
274-
* Returns the value of an optional float configuration setting.
274+
* Returns the value of an optional float including NaN, -INF, and INF configuration setting.
275275
*
276276
* @param string $key The key of the configuration setting. The key might be nested using dot notation.
277277
* @param float|null $default The default value.
@@ -280,16 +280,16 @@ public function getOptFiniteFloat(string $key, ?float $default = null): ?float
280280
*
281281
* @throws TypedConfigException
282282
*/
283-
public function getOptFloat(string $key, ?float $default = null): ?float
283+
public function getOptFloatInclusive(string $key, ?float $default = null): ?float
284284
{
285285
$value = $this->config->get($key, $default);
286286
try
287287
{
288-
return Cast::toOptFloat($value);
288+
return Cast::toOptFloatInclusive($value);
289289
}
290290
catch (InvalidCastException $exception)
291291
{
292-
throw self::createException($key, 'float', $value);
292+
throw self::createException($key, 'float inclusive', $value);
293293
}
294294
}
295295

src/TypedConfigException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(string $key, string $type, $value)
3333
*
3434
* @return string The error message.
3535
*/
36-
private static function message(string $key, string $type, $value): string
36+
private static function message(string $key, string $type, mixed $value): string
3737
{
3838
if ($value===null)
3939
{

0 commit comments

Comments
 (0)