Skip to content

Commit 2d0ea15

Browse files
committed
remove value type and variable type checking
per review feedback, this can be checked with tests rather than at runtime
1 parent ab0630a commit 2d0ea15

File tree

5 files changed

+52
-342
lines changed

5 files changed

+52
-342
lines changed

deptrac.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ deptrac:
9191
regex: ^Symfony\\Component\\*
9292
- name: SPI
9393
collectors:
94-
- type: className
95-
regex: ^Nevay\\SPI\\*
94+
- type: className
95+
regex: ^Nevay\\SPI\\*
9696

9797
ruleset:
9898
Context:

src/Config/Configuration/Configuration.php

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,23 @@ public static function has(string $name): bool
2828
public static function getInt(string $key, int $default = null): int
2929
{
3030
return (int) self::validateVariableValue(
31-
CompositeResolver::instance()->resolve(
32-
self::validateVariableType($key, VariableTypes::INTEGER),
33-
$default
34-
),
31+
CompositeResolver::instance()->resolve($key, $default),
3532
FILTER_VALIDATE_INT
3633
);
3734
}
3835

3936
public static function getString(string $key, string $default = null): string
4037
{
4138
return (string) self::validateVariableValue(
42-
CompositeResolver::instance()->resolve(
43-
self::validateVariableType($key, VariableTypes::STRING),
44-
$default
45-
)
39+
CompositeResolver::instance()->resolve($key, $default),
4640
);
4741
}
4842

4943
public static function getBoolean(string $key, bool $default = null): bool
5044
{
5145
$resolved = self::validateVariableValue(
5246
CompositeResolver::instance()->resolve(
53-
self::validateVariableType($key, VariableTypes::BOOL),
47+
$key,
5448
null === $default ? $default : ($default ? 'true' : 'false')
5549
)
5650
);
@@ -71,40 +65,28 @@ public static function getMixed(string $key, $default = null): mixed
7165
public static function getMap(string $key, array $default = null): array
7266
{
7367
return MapParser::parse(
74-
CompositeResolver::instance()->resolve(
75-
self::validateVariableType($key, VariableTypes::MAP),
76-
$default
77-
)
68+
CompositeResolver::instance()->resolve($key, $default),
7869
);
7970
}
8071

8172
public static function getList(string $key, array $default = null): array
8273
{
8374
return ListParser::parse(
84-
CompositeResolver::instance()->resolve(
85-
self::validateVariableType($key, VariableTypes::LIST),
86-
$default
87-
)
75+
CompositeResolver::instance()->resolve($key, $default),
8876
);
8977
}
9078

9179
public static function getEnum(string $key, string $default = null): string
9280
{
9381
return (string) self::validateVariableValue(
94-
CompositeResolver::instance()->resolve(
95-
self::validateVariableType($key, VariableTypes::ENUM),
96-
$default
97-
)
82+
CompositeResolver::instance()->resolve($key, $default),
9883
);
9984
}
10085

10186
public static function getFloat(string $key, float $default = null): float
10287
{
10388
return (float) self::validateVariableValue(
104-
CompositeResolver::instance()->resolve(
105-
self::validateVariableType($key, VariableTypes::FLOAT),
106-
$default
107-
),
89+
CompositeResolver::instance()->resolve($key, $default),
10890
FILTER_VALIDATE_FLOAT
10991
);
11092
}
@@ -113,10 +95,7 @@ public static function getRatio(string $key, float $default = null): float
11395
{
11496
return RatioParser::parse(
11597
self::validateVariableValue(
116-
CompositeResolver::instance()->resolve(
117-
self::validateVariableType($key, VariableTypes::RATIO),
118-
$default
119-
)
98+
CompositeResolver::instance()->resolve($key, $default),
12099
)
121100
);
122101
}
@@ -131,30 +110,12 @@ public static function getDefault(string $variableName)
131110
return ClassConstantAccessor::getValue(Defaults::class, $variableName);
132111
}
133112

134-
public static function getType(string $variableName): ?string
135-
{
136-
return ClassConstantAccessor::getValue(ValueTypes::class, $variableName);
137-
}
138-
139113
public static function isEmpty($value): bool
140114
{
141115
// don't use 'empty()', since '0' is not considered to be empty
142116
return $value === null || $value === '';
143117
}
144118

145-
private static function validateVariableType(string $variableName, string $type): string
146-
{
147-
$variableType = self::getType($variableName);
148-
149-
if ($variableType !== null && $variableType !== $type && $variableType !== VariableTypes::MIXED) {
150-
throw new UnexpectedValueException(
151-
sprintf('Variable "%s" is not supposed to be of type "%s" but type "%s"', $variableName, $type, $variableType)
152-
);
153-
}
154-
155-
return $variableName;
156-
}
157-
158119
private static function validateVariableValue(mixed $value, ?int $filterType = null): mixed
159120
{
160121
if ($filterType !== null && filter_var($value, $filterType) === false) {

src/Config/Configuration/ValueTypes.php

Lines changed: 0 additions & 136 deletions
This file was deleted.

src/Config/Configuration/VariableTypes.php

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)