Skip to content

Conversation

@Dropelikeit
Copy link
Contributor

@Dropelikeit Dropelikeit commented Jul 10, 2024

No description provided.

@Dropelikeit
Copy link
Contributor Author

Unfortunately, I had accidentally deleted the fork in my profile.

An older discussion can be found under the closed PR: #297

Copy link
Collaborator

@shadowhand shadowhand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a duplicate of positiveInteger and notPositiveInteger?

@Dropelikeit
Copy link
Contributor Author

@shadowhand

Not directly, notNegativeInt simply checks whether it is 0 or greater than 0 to definitively avoid it being a negative integer. With this assert, as with the other assert functions, Psalm directly understands that the number can never be negative. In the other case, negative-int, Psalm should understand that the given integer can never be 0 (neutral) or positive.

That is my goal with this PR here, a small clarification that Psalm would then also understand:

class MyObject {
/**
* @psalm-param non-negative-int $age
*/
public function __construct(private readonly $age)
{
}

public static function create(int $age): self
{
      Assert::nonNegativeInteger($age);

      return new self($age);
}

/**
* @psalm-return non-negative-int
*/
public function getAge(): int
{
      return $this->age;
}

@shadowhand shadowhand added this to the v2.0 milestone Nov 25, 2025
@shadowhand
Copy link
Collaborator

@Dropelikeit so, positive-int means > 0 but non-negative-int means ! < 0?

@shadowhand
Copy link
Collaborator

@Dropelikeit in any case, this would need to be rebased to current master.

@Dropelikeit
Copy link
Contributor Author

Dropelikeit commented Nov 25, 2025

@Dropelikeit so, positive-int means > 0 but non-negative-int means ! < 0?

@shadowhand Exactly. 0 (zero) is neither positive nor negative. Non-negative is similar to positive-int, but also includes zero. The only difference is that negative numbers are excluded here.

I have rebased my branch so that there are no more conflicts. I have also fixed a small bug in the Assert.php file. In the propertyExists method, $value was undefined in the return value. I replaced the variable with the variable $classOrObject, as in the methodExist method.

@shadowhand shadowhand mentioned this pull request Dec 1, 2025
@shadowhand shadowhand changed the title Addition of two new assert functions for better validation of differe… Add isNegativeInteger and nonNegativeInteger Dec 1, 2025
@shadowhand shadowhand changed the title Add isNegativeInteger and nonNegativeInteger Add isNegativeInteger and notNegativeInteger Dec 1, 2025
Copy link
Collaborator

@shadowhand shadowhand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more small fix, then looks good.

@shadowhand shadowhand merged commit 911bf98 into webmozarts:master Dec 1, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants