Skip to content

Commit 70082cd

Browse files
committed
Type: refactoring
1 parent 0a14f22 commit 70082cd

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

src/Utils/Type.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,36 +233,36 @@ public function isClassKeyword(): bool
233233
/**
234234
* Verifies type compatibility. For example, it checks if a value of a certain type could be passed as a parameter.
235235
*/
236-
public function allows(string $subtype): bool
236+
public function allows(string $type): bool
237237
{
238238
if ($this->types === ['mixed']) {
239239
return true;
240240
}
241241

242-
$subtype = self::fromString($subtype);
243-
return $subtype->isUnion()
244-
? Arrays::every($subtype->types, fn($t) => $this->allows2($t instanceof self ? $t->types : [$t]))
245-
: $this->allows2($subtype->types);
242+
$type = self::fromString($type);
243+
return $type->isUnion()
244+
? Arrays::every($type->types, fn($t) => $this->allowsAny($t instanceof self ? $t->types : [$t]))
245+
: $this->allowsAny($type->types);
246246
}
247247

248248

249-
private function allows2(array $subtypes): bool
249+
private function allowsAny(array $givenTypes): bool
250250
{
251251
return $this->isUnion()
252-
? Arrays::some($this->types, fn($t) => $this->allows3($t instanceof self ? $t->types : [$t], $subtypes))
253-
: $this->allows3($this->types, $subtypes);
252+
? Arrays::some($this->types, fn($t) => $this->allowsAll($t instanceof self ? $t->types : [$t], $givenTypes))
253+
: $this->allowsAll($this->types, $givenTypes);
254254
}
255255

256256

257-
private function allows3(array $types, array $subtypes): bool
257+
private function allowsAll(array $ourTypes, array $givenTypes): bool
258258
{
259259
return Arrays::every(
260-
$types,
261-
fn($type) => Arrays::some(
262-
$subtypes,
263-
fn($subtype) => Validators::isBuiltinType($type)
264-
? strcasecmp($type, $subtype) === 0
265-
: is_a($subtype, $type, allow_string: true),
260+
$ourTypes,
261+
fn($ourType) => Arrays::some(
262+
$givenTypes,
263+
fn($givenType) => Validators::isBuiltinType($ourType)
264+
? strcasecmp($ourType, $givenType) === 0
265+
: is_a($givenType, $ourType, allow_string: true),
266266
),
267267
);
268268
}

0 commit comments

Comments
 (0)