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: Fix some phan typing in actions_massactions.inc.php #30733

Closed
wants to merge 2 commits into from

Conversation

mdeweerd
Copy link
Contributor

@mdeweerd mdeweerd commented Aug 22, 2024

Qual: Fix some phan typing in actions_massactions.inc.php

Fix phan in actions_massactions.inc.php

@mdeweerd mdeweerd marked this pull request as ready for review August 22, 2024 23:59
@@ -47,6 +47,13 @@
}
$error = 0;

// Note: list of strings for objectclass could be extended to accepted/expected classes
'
@phan-var-force "Societe"|"Contact"|"ExpenseReport"|"Partnership"|"Holiday"|"ConferenceOrBoothAttendee"|"Facture"|"CommandeFournisseur" $objectclass
Copy link
Member

Choose a reason for hiding this comment

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

$objectclass can be any Dolibarr business object here.
Is it possible to have instead a generic object class, may be CommonObject class ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I find often that putting CommonObject alone generates issues with the typing as some fields are missing and expected by the algorithm.

I propose to "add" CommonObject and also leave the other options that are tested for in the code. In case there is a typing issue it will indicate which classes are not compatible.

Ideally - in some future - the code would do a test using "instanceof" rather than relying on the 'element' field and the typing hints.
That implies risks of course: the "instanceof" condition could be too strict vs. what the code was actually expecting and introduce some bugs in the process.

Copy link
Member

@eldy eldy Aug 23, 2024

Choose a reason for hiding this comment

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

I propose to "add" CommonObject and also leave the other options that are tested for in the code. In case there is a typing issue it will indicate which classes are not compatible.

You mean having this
@phan-var-force "CommonObject"|"Societe"|"Contact"|"ExpenseReport"|"Partnership"|"Holiday"|"ConferenceOrBoothAttendee"|"Facture"|"CommandeFournisseur" $objectclass ?

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.

FYI, phan has more than 50 notices for this file.

For instance, we have:

htdocs\core\actions_massactions.inc.php:1288 PhanUndeclaredProperty Reference to undeclared property \CommonObject->price
htdocs\core\actions_massactions.inc.php:1289 PhanUndeclaredProperty Reference to undeclared property \CommonObject->price_min

There is no check on the object type: it is implied by the 'updateprice' action.

Copy link
Member

@eldy eldy Aug 23, 2024

Choose a reason for hiding this comment

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

Yes, but most of them are strange. For example this one:
UndefError PhanUndeclaredProperty Reference to undeclared property \CommonObject->rowid on line 1175

The $obj is a result of fetch_object() with no declaration that it is CommonObject, so I don't understand this warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is because we have the following in the configuration for phan:

dev/tools/phan/config.php:              'obj' => '\CommonObject',     // Deprecated

We could check what the result is if this is commented in a separate PR (I guess there will be some notifications that pop up).

@eldy eldy added the Discussion Some questions or discussions are opened and wait answers of author or other people to be processed label Aug 23, 2024
@mdeweerd mdeweerd force-pushed the fix/nextValue branch 2 times, most recently from 35a5ad3 to ee5424b Compare August 23, 2024 15:15
@mdeweerd
Copy link
Contributor Author

mdeweerd commented Aug 23, 2024

I've now extended to fixing all the notices in htdocs/core/actions_massactions.inc.php.

Some observations:

  • The file arguments to pdftk use '/' which is not system dependent. Maybe this works for pdftk on Windows but technically it's better that this is the path according to the system rules;
  • I'ld rather have a dol_exec rather than the native exec to allow the addition of security checks. dol_exec would take an string[][] as the argument with each item being a command to execute in the format array{command,arg1,arg2,...}.
    dol_exec would take care of escaping those and executing them in order (either by separating them with ';' or executing one after the other.
    Also - not verified in detail - according to a summary for the following information, escapeshellarg was designed for bash/... not a windows shell, so that's a potential security issue: https://gist.github.com/Zenexer/40d02da5e07f151adeaeeaa11af9ab36 . And therefore a good reason to have a dol_exec taking care of escaping (or refusing execution) .

Regarding the issues:

  • fk_soc and socid on common object not defined: not fixed because when that happens the type of CommonObject does not seem to be limited a a specific set of child classes;
  • $pagecount possibly undefined - not fixed because the use seems invalid in case there is more than one document - it uses the pagecount of the last document;
  • Issue regarding ModeleNumRefTask: not for me to decide;
  • Other cases: I am looking into them. @eldy These are now fixed - your turn to "play".

@mdeweerd mdeweerd force-pushed the fix/nextValue branch 2 times, most recently from 3999143 to 0e1a2d3 Compare August 23, 2024 22:48
mdeweerd added a commit to mdeweerd/dolibarr that referenced this pull request Aug 23, 2024
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
@mdeweerd mdeweerd force-pushed the fix/nextValue branch 2 times, most recently from 0efa150 to bc5114c Compare August 23, 2024 23:31
@mdeweerd
Copy link
Contributor Author

I've reduced this PR to only the changes in actions_massactions.inc.php . The rest of the PR was moved to #30747

@mdeweerd mdeweerd changed the title Qual: Fix some phan typing related to getNextValue() Qual: Fix some phan typing in actions_massactions.inc.php Aug 23, 2024
mdeweerd added a commit to mdeweerd/dolibarr that referenced this pull request Aug 27, 2024
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
mdeweerd added a commit to mdeweerd/dolibarr that referenced this pull request Aug 27, 2024
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
mdeweerd added a commit to mdeweerd/dolibarr that referenced this pull request Aug 28, 2024
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
mdeweerd added a commit to mdeweerd/dolibarr that referenced this pull request Aug 29, 2024
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
mdeweerd added a commit to mdeweerd/dolibarr that referenced this pull request Aug 30, 2024
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
mdeweerd added a commit to mdeweerd/dolibarr that referenced this pull request Sep 5, 2024
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
eldy added a commit that referenced this pull request Sep 10, 2024
* Qual: Fix phan notices in actions_massactions.inc

# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from #30733.

* Adjust baseline for actions_massactions.inc improvements

* Update actions_massactions.inc.php

---------

Co-authored-by: Laurent Destailleur <[email protected]>
mdeweerd added a commit to mdeweerd/dolibarr that referenced this pull request Sep 10, 2024
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
mdeweerd added a commit to mdeweerd/dolibarr that referenced this pull request Sep 12, 2024
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
mdeweerd added a commit to mdeweerd/dolibarr that referenced this pull request Sep 25, 2024
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
@@ -49,6 +49,18 @@
@phan-var-force ?string $deliveryreceipt
';

'
@phan-var-force ?string $permissiontoread
Copy link
Member

Choose a reason for hiding this comment

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

Seems duplicate of line 41 to 49

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possibly because this PR and changes still pending here are "old" and repeated in more recent PRs. I'll clean that up.

The main reason this PR is still open is for these phan notices:

Warning: actions_massactions.inc.php: PhanUndeclaredProperty: Reference to undeclared property \CommonObject-&gt;fk_soc
Warning: actions_massactions.inc.php: PhanUndeclaredProperty: Reference to undeclared property \User-&gt;email_aliases
Warning: actions_massactions.inc.php: PhanPossiblyUndeclaredGlobalVariable: Global variable $pagecount is possibly undeclared

I am tending to think that I should simply extract the code changes to a separate PR and close this one - the real technical debt is likely not going to be fixed until almost all of the pending phpdoc changes and false positives are identified.

@eldy eldy added PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do) and removed Discussion Some questions or discussions are opened and wait answers of author or other people to be processed labels Sep 28, 2024
@mdeweerd mdeweerd closed this Sep 29, 2024
@mdeweerd mdeweerd deleted the fix/nextValue branch September 29, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants