Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qual: PHPStan for tva.class.php #30711

Merged
merged 5 commits into from
Aug 21, 2024
Merged

qual: PHPStan for tva.class.php #30711

merged 5 commits into from
Aug 21, 2024

Conversation

thibdrev
Copy link
Contributor

htdocs/compta/tva/class/tva.class.php 57 Property Tva::$total has no type specified.

htdocs/compta/tva/class/tva.class.php 59 Property Tva::$datep has no type specified.

htdocs/compta/tva/class/tva.class.php 60 Property Tva::$datev has no type specified.

htdocs/compta/tva/class/tva.class.php 61 Property Tva::$amount has no type specified.

htdocs/compta/tva/class/tva.class.php 62 Property Tva::$type_payment has no type specified.

htdocs/compta/tva/class/tva.class.php 924 Method Tva::getKanbanView() has parameter $arraydata with no value type specified in iterable type array.

htdocs/compta/tva/class/tva.class.php	57	Property Tva::$total has no type specified.

htdocs/compta/tva/class/tva.class.php	59	Property Tva::$datep has no type specified.

htdocs/compta/tva/class/tva.class.php	60	Property Tva::$datev has no type specified.

htdocs/compta/tva/class/tva.class.php	61	Property Tva::$amount has no type specified.

htdocs/compta/tva/class/tva.class.php	62	Property Tva::$type_payment has no type specified.

htdocs/compta/tva/class/tva.class.php	924	Method Tva::getKanbanView() has parameter $arraydata with no value type specified in iterable type array.
@@ -163,7 +163,7 @@ public function create($user)
$now = dol_now();

// Clean parameters
$this->amount = trim($this->amount);
$this->amount = (float) $this->amount;
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been "PHPDoc typing" in several cases that monetary values can be either string or float because price2num will ensure that they have the desired count of digits after the decimal dot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's what I figured out with the phan warnings.
So I've updated to:

	/**
	 * @var float|string VAT amount
	 */
	public $amount;

and

// Clean parameters
$this->amount = (float) price2num($this->amount);

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, you can keep

$this->amount = price2num($this->amount);

And whenever $this->amount is used in a computation, cast it with (float).

It would be better to have a class represent monetary and quantity values IMHO, but that's a task in itself. That class would be able to handle all the operators +, -, /, ... .

@eldy eldy merged commit 4e5ea52 into Dolibarr:develop Aug 21, 2024
7 checks passed
@thibdrev thibdrev deleted the patch-2 branch August 21, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants