Skip to content

Commit

Permalink
remove PositiveNumeric assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
orklah committed Jan 23, 2022
1 parent d3ffde6 commit e9ac465
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 167 deletions.
Expand Up @@ -58,7 +58,6 @@
use Psalm\Storage\Assertion\IsNotIdentical;
use Psalm\Storage\Assertion\IsNotLooselyEqual;
use Psalm\Storage\Assertion\IsNotType;
use Psalm\Storage\Assertion\IsPositiveNumeric;
use Psalm\Storage\Assertion\IsType;
use Psalm\Storage\Assertion\NestedAssertions;
use Psalm\Storage\Assertion\NonEmptyCountable;
Expand Down
5 changes: 0 additions & 5 deletions src/Psalm/Internal/Type/NegatedAssertionReconciler.php
Expand Up @@ -11,7 +11,6 @@
use Psalm\Storage\Assertion\IsClassNotEqual;
use Psalm\Storage\Assertion\IsNotCountable;
use Psalm\Storage\Assertion\IsNotIdentical;
use Psalm\Storage\Assertion\IsNotPositiveNumeric;
use Psalm\Storage\Assertion\IsNotType;
use Psalm\Type;
use Psalm\Type\Atomic;
Expand Down Expand Up @@ -87,10 +86,6 @@ public static function reconcile(
);
}

if ($is_equality && $assertion instanceof IsNotPositiveNumeric) {
return $existing_var_type;
}

$existing_var_atomic_types = $existing_var_type->getAtomicTypes();

if ($assertion_type instanceof TFalse && isset($existing_var_atomic_types['bool'])) {
Expand Down
93 changes: 0 additions & 93 deletions src/Psalm/Internal/Type/SimpleAssertionReconciler.php
Expand Up @@ -22,7 +22,6 @@
use Psalm\Storage\Assertion\IsIsset;
use Psalm\Storage\Assertion\IsLessThan;
use Psalm\Storage\Assertion\IsLooselyEqual;
use Psalm\Storage\Assertion\IsPositiveNumeric;
use Psalm\Storage\Assertion\IsType;
use Psalm\Storage\Assertion\NonEmpty;
use Psalm\Storage\Assertion\NonEmptyCountable;
Expand Down Expand Up @@ -238,19 +237,6 @@ public static function reconcile(
);
}

if ($assertion instanceof IsPositiveNumeric) {
return self::reconcilePositiveNumeric(
$assertion,
$existing_var_type,
$key,
$negated,
$code_location,
$suppressed_issues,
$failed_reconciliation,
$is_equality
);
}

if ($assertion instanceof NonEmptyCountable) {
return self::reconcileNonEmptyCountable(
$assertion,
Expand Down Expand Up @@ -725,85 +711,6 @@ private static function reconcileExactlyCountable(
return $existing_var_type;
}

/**
* @param string[] $suppressed_issues
* @param Reconciler::RECONCILIATION_* $failed_reconciliation
*/
private static function reconcilePositiveNumeric(
Assertion $assertion,
Union $existing_var_type,
?string $key,
bool $negated,
?CodeLocation $code_location,
array $suppressed_issues,
int &$failed_reconciliation,
bool $is_equality
): Union {
$old_var_type_string = $existing_var_type->getId();

$did_remove_type = false;

$positive_types = [];

foreach ($existing_var_type->getAtomicTypes() as $atomic_type) {
if ($atomic_type instanceof TLiteralInt) {
if ($atomic_type->value < 1) {
$did_remove_type = true;
} else {
$positive_types[] = $atomic_type;
}
} elseif ($atomic_type instanceof TPositiveInt) {
$positive_types[] = $atomic_type;
} elseif ($atomic_type instanceof TIntRange) {
if (!$atomic_type->isPositive()) {
$did_remove_type = true;
}
$positive_types[] = new TIntRange(
$atomic_type->min_bound === null ? 1 : max(1, $atomic_type->min_bound),
$atomic_type->max_bound === null ? null : max(1, $atomic_type->max_bound)
);
} elseif (get_class($atomic_type) === TInt::class) {
$positive_types[] = new TPositiveInt();
$did_remove_type = true;
} else {
// for now allow this check everywhere else
if (!$atomic_type instanceof TNull
&& !$atomic_type instanceof TFalse
) {
$positive_types[] = $atomic_type;
}

$did_remove_type = true;
}
}

if (!$is_equality
&& !$existing_var_type->hasMixed()
&& (!$did_remove_type || !$positive_types)
) {
if ($key && $code_location) {
self::triggerIssueForImpossible(
$existing_var_type,
$old_var_type_string,
$key,
$assertion,
!$did_remove_type,
$negated,
$code_location,
$suppressed_issues
);
}
}

if ($positive_types) {
return new Union($positive_types);
}

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

return Type::getNever();
}

/**
* @param string[] $suppressed_issues
* @param Reconciler::RECONCILIATION_* $failed_reconciliation
Expand Down
30 changes: 0 additions & 30 deletions src/Psalm/Storage/Assertion/IsNotPositiveNumeric.php

This file was deleted.

38 changes: 0 additions & 38 deletions src/Psalm/Storage/Assertion/IsPositiveNumeric.php

This file was deleted.

0 comments on commit e9ac465

Please sign in to comment.