Skip to content

fix: update threshold handling to support float values in all usages#528

Draft
mariusjp wants to merge 6 commits intoericsizemore:masterfrom
mariusjp:feature/517-symf8-float
Draft

fix: update threshold handling to support float values in all usages#528
mariusjp wants to merge 6 commits intoericsizemore:masterfrom
mariusjp:feature/517-symf8-float

Conversation

@mariusjp
Copy link
Copy Markdown

@mariusjp mariusjp commented Feb 12, 2026

Pull Request

Proposed Changes

Readiness Checklist

Author/Contributor

  • You have read CONTRIBUTING
  • If documentation is needed for this change, has that been included in this pull request
  • run composer run-script phpunit and ensure you have test coverage for the lines you are introducing
  • run composer run-script phpstan and fix any issues that you have introduced
  • run composer run-script psalm and fix any issues that you have introduced
  • run composer run-script phpcs:check and fix any issues that you have introduced

Reviewer

  • Label as either fix, documentation, or enhancement
  • Additionally label as verified or unverified

@mariusjp mariusjp mentioned this pull request Feb 12, 2026
2 tasks
@ericsizemore
Copy link
Copy Markdown
Owner

Thanks for starting on this. I'll review it once I am able. :) Looks like a good start.

@mariusjp
Copy link
Copy Markdown
Author

The only part I don't really like is:

->setThreshold(Utils::convertThresholdToFloat($threshold)) // (CoverageCheckCommand.php:162)

It feels like I should not use Utils here because now I also have to Cover this part in the UnitTest.
But I also feel like I HAVE to pass a float there, should be determined as soon as possible.

What's your take on this?

@ericsizemore
Copy link
Copy Markdown
Owner

My apologies Marius, been under the weather with COVID. I promise I'll take a look within the next few days. It's kicking my butt right now. :)

@mariusjp
Copy link
Copy Markdown
Author

No worries, get well soon!

@ericsizemore ericsizemore added enhancement New feature or request verified A bug/issue that has been verified labels Feb 20, 2026
final class ThresholdOutOfBoundsException extends InvalidArgumentException
{
public static function create(int $threshold): self
public static function create(float $threshold): self
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Instead of moving from int to float, perhaps we should just expand it to float|int.

Comment thread src/CoverageCheck.php Outdated
private bool $onlyPercentage = false;

private int $threshold = 100;
private float $threshold = 100;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Instead of moving from int to float, perhaps we should just expand it to float|int.

Comment thread src/CoverageCheck.php Outdated
}

public function getThreshold(): int
public function getThreshold(): float
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Instead of moving from int to float, perhaps we should just expand it to float|int.

Comment thread src/CoverageCheck.php Outdated
* defined range (>= 1 <= 100).
*/
public function nonConsoleCall(string $cloverFile, int $threshold = 100, bool $onlyPercentage = false): string
public function nonConsoleCall(string $cloverFile, float $threshold = 100, bool $onlyPercentage = false): string
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Instead of moving from int to float, perhaps we should just expand it to float|int.

Comment thread src/CoverageCheck.php Outdated
* @throws ThresholdOutOfBoundsException If the threshold is less than 1 or greater than 100.
*/
public function setThreshold(int $threshold): CoverageCheck
public function setThreshold(float $threshold): CoverageCheck
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Instead of moving from int to float, perhaps we should just expand it to float|int.

Comment thread src/Utils.php Outdated
* A simple check to determine if threshold is within accepted range (Min. 1, Max. 100).
*/
public static function validateThreshold(int $threshold): bool
public static function validateThreshold(float $threshold): bool
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Kind of tied in with previous commentds, instead of moving from int to float, perhaps we should just expand it to float|int.

Comment thread src/Utils.php Outdated
return ($cloverFile !== '' && file_exists($cloverFile));
}

public static function convertThresholdToFloat(string $threshold): float
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Should we look at potentially a different method? Perhaps instead of converting to, and returning as, float - we could check the input itself to see if it's "floaty" or "inty" and return either float|int?

@ericsizemore
Copy link
Copy Markdown
Owner

ericsizemore commented Feb 20, 2026

Gone through and made some comments, just some initial thoughts. I'm still a bit out of it, so my thinking could be a tad off haha.

ETA: Wondering if this should also be pushed to a new major version. Though that could depend on how we move forward I suppose, with the type safety changes.

@mariusjp
Copy link
Copy Markdown
Author

To respond to basically all your comments.
I could also go full OO. Make a Threshold ValueObject that can either be int or float (up to the object, not the application) and we can base our logic on that.
I'll look into it today/this week!

@mariusjp
Copy link
Copy Markdown
Author

mariusjp commented Mar 4, 2026

Just noticed some of my auto formatting changed the order of your docblocks. I'll fix those asap. I'll also try to figure out how to get below that 3% threshold

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
4.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@ericsizemore
Copy link
Copy Markdown
Owner

Appreciate all your work on this Marius. My apologies I haven't been able to be more involved with this. A lot going on at the moment, but hope I'll be able to make some time soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request verified A bug/issue that has been verified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants