Skip to content

Commit

Permalink
restrict & fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Sep 30, 2022
1 parent 7b4d9ed commit 7554339
Showing 1 changed file with 29 additions and 41 deletions.
70 changes: 29 additions & 41 deletions src/Hooks/StrictEqualityHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,13 @@ private static function isEqualOrdered(Atomic $first_type, Atomic $second_type):
return true;
}

if ($first_type instanceof Atomic\TList && $second_type instanceof Atomic\TList) {
// array/objects are somewhat safe to compare against strings
if (self::isTooComplicatedType($first_type) && $second_type instanceof Atomic\TString) {
return true;
}

if ($first_type instanceof Atomic\TIterable || $first_type instanceof Atomic\TKeyedArray || $first_type instanceof Atomic\TArray) {
} elseif (self::isTooComplicatedType($first_type)) {
return false;
}

if ($first_type instanceof Atomic\TNamedObject && $second_type instanceof Atomic\TNamedObject) {
return true;
}

if ($first_type instanceof Atomic\TObject && $second_type instanceof Atomic\TNamedObject) {
return true;
}

if ($first_type instanceof Atomic\TObject && $second_type instanceof Atomic\TObject) {
return true;
}

// generic same or parent class
if ($first_type instanceof $second_type) {
return true;
Expand All @@ -159,9 +146,11 @@ private static function isNotEqualOrdered(Atomic $first_type, Atomic $second_typ
private static function isUnionCompatibleType(array $left_type_atomics, array $right_type_atomics, string $expr_class): bool {
if ($expr_class === Equal::class) {
//This is just a trick to avoid handling every way
return self::isUnionEqualOrdered($left_type_atomics, $right_type_atomics) || self::isUnionEqualOrdered($right_type_atomics, $left_type_atomics);
return self::isUnionEqualOrdered($left_type_atomics, $right_type_atomics) || self::isUnionEqualOrdered($right_type_atomics, $left_type_atomics) ||
self::isUnionStringEqualOrdered($left_type_atomics, $right_type_atomics) || self::isUnionStringEqualOrdered($right_type_atomics, $left_type_atomics);
} else {
return self::isUnionNotEqualOrdered($left_type_atomics, $right_type_atomics) || self::isUnionNotEqualOrdered($right_type_atomics, $left_type_atomics);
return self::isUnionNotEqualOrdered($left_type_atomics, $right_type_atomics) || self::isUnionNotEqualOrdered($right_type_atomics, $left_type_atomics) ||
self::isUnionStringNotEqualOrdered($left_type_atomics, $right_type_atomics) || self::isUnionStringNotEqualOrdered($right_type_atomics, $left_type_atomics);
}
}

Expand All @@ -178,7 +167,6 @@ private static function isUnionStringEqualOrdered(array $first_types, array $sec
continue;
}

// only single, not-union string is fixable at the moment
return false;
}

Expand All @@ -191,27 +179,8 @@ private static function isUnionStringEqualOrdered(array $first_types, array $sec
continue;
}

if ($atomic_type instanceof Atomic\TArray) {
continue;
}

if ($atomic_type instanceof Atomic\TKeyedArray) {
continue;
}

if ($atomic_type instanceof Atomic\TList) {
continue;
}

if ($atomic_type instanceof Atomic\TIterable) {
continue;
}

if ($atomic_type instanceof Atomic\TObject) {
continue;
}

if ($atomic_type instanceof Atomic\TNamedObject) {
// array/objects are somewhat safe to compare against strings
if (self::isTooComplicatedType($atomic_type)) {
continue;
}

Expand Down Expand Up @@ -259,7 +228,7 @@ private static function isUnionEqualOrdered(array $first_types, array $second_ty
return false;
}

if (!($top_level_class instanceof Atomic\TList) && $top_level_class instanceof Atomic\TArray) {
if (self::isTooComplicatedType($top_level_class)) {
return false;
}

Expand All @@ -284,6 +253,25 @@ private static function isUnionNotEqualOrdered(array $first_types, array $second
// identical at the moment
return self::isUnionEqualOrdered($first_types, $second_types);
}

private static function isTooComplicatedType(Atomic $type) {
$too_complicated_types = array(
Atomic\TKeyedArray,
Atomic\TArray,
Atomic\TList,
Atomic\TIterable,
Atomic\TNamedObject,
Atomic\TObject
);

foreach ($too_complicated_types as $compare) {
if ($type instanceof $compare || $compare instanceof $type) {
return true;
}
}

return false;
}
}

class NotStrictEqualSign extends PluginIssue
Expand Down

0 comments on commit 7554339

Please sign in to comment.