dolibarr/dev/tools/phan
Frédéric FRANCE a0b0e44278
NEW Link manage extrafields and phpunit test for the class (#39514)
* NEW: Add extrafields support to Link class

Link now declares isextrafieldmanaged and wires fetch_optionals()/
insertExtraFields()/deleteExtraFields() into fetch(), fetchAll(),
create(), update() and delete(), matching the llx_links_extrafields
table added previously.

* FIX: Several bugs in Link class review

- create(): wrong duplicate-record error message (copy-pasted from
  Societe, referenced undefined $this->name) replaced by the generic
  ErrorDuplicateField, consistent with update().
- create()/update(): missing "NoURL" translation key replaced by the
  standard ErrorFieldRequired pattern.
- fetch(): guard against running an unfiltered query (no rowid, no
  hashforshare) that could silently return an arbitrary link; a caller
  in actions_linkedfiles.inc.php could hit this when 'linkid' was
  missing from the request.
- actions_linkedfiles.inc.php: check fetch() result with `> 0` instead
  of a truthy test, since -1 (error) is truthy in PHP.
- delete(): add User type hint (consistent with create()/update()) and
  a $notrigger parameter to optionally skip the LINK_DELETE trigger.
- update(): fix copy-pasted docblock ("third party" -> "link").

* NEW: Add PHPUnit test for Link class

Covers create/fetch/update/fetchAll/count/delete, plus regression
tests for the two bugs fixed in the previous commit: create() rejects
an empty url, and fetch() rejects a call with neither rowid nor
hashforshare instead of returning an arbitrary record.

* FIX Phan false positive on $object in actions_linkedfiles.inc.php

Phan's ambient type inference for the loosely-typed global $object in
this shared include file was picking up CommonSocialNetworks (an
unrelated trait, not even a class), reported as undeclared
->id/->entity/->addThumbs()/->delThumbs() in a real CI Phan run on
this branch, once this file was analyzed on its own via the
changed-files file-list (this file has no prior baseline entry, so it
was apparently never previously exercised in isolation like this).

Force $object's type explicitly to CommonObject via the same
@phan-var-force string-literal idiom this file already uses for
$upload_dir/$upload_dirold/$confirm/$forceFullTextIndexation -
CommonObject genuinely declares addThumbs()/delThumbs(), which
resolves those two errors outright. $id/$entity remain reported as
PhanUndeclaredProperty (CommonObject itself does not declare them,
only its concrete subclasses do at runtime) - baseline-suppress that
for this file the same way it is already suppressed for the sibling
shared-include files actions_addupdatedelete.inc.php,
actions_massactions.inc.php and actions_sendmails.inc.php, which have
the exact same $object typing situation.
2026-08-19 02:18:46 +02:00
..
plugins QUAL: Add SqlInjectionPlugin to detect unsafe SQL variable usage (fixes, notices) (#38722) 2026-08-08 11:19:04 +02:00
stubs Qual: Fix Phan notices (#39281) 2026-07-27 13:03:04 +02:00
.gitignore
allow_phan_in_precommit.sh Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into 2026-04-27 14:43:34 +02:00
baseline.txt NEW Link manage extrafields and phpunit test for the class (#39514) 2026-08-19 02:18:46 +02:00
baseline_extended.txt Qual: Fix phan notices (reception) 2025-02-13 15:39:39 +01:00
config.php QUAL: Add SqlInjectionPlugin to detect unsafe SQL variable usage (fixes, notices) (#38722) 2026-08-08 11:19:04 +02:00
config_extended.php QUAL: Add SqlInjectionPlugin to detect unsafe SQL variable usage (fixes, notices) (#38722) 2026-08-08 11:19:04 +02:00
config_fixer.php Qual: Fix phan notices (facture/2) 2025-03-05 21:17:58 +01:00
PHAN.BAT Qual: Enable detection of deprecated modulename & GETPOST(...,'int') (#28457) 2024-02-28 23:25:16 +01:00
README.md
run-phan.sh
runPhanDocker.sh

Static Code Checks using phan

Installation, running

run-phan.sh can install and run phan.

See instructions in run-phan.sh for installing (or just run it).

The configuration file in PROJECT_DIR/.phan/config.php also allows you to run phan independently from the script.

Run options:

No option : Runs the minimum checks

Option 'full' : Runs all an extensive set of checks

Option '1' : Writes the baseline

Examples:

  • run-phan.sh runs the default checks
  • run-phan.sh 1 updates the baseline for the default checks
  • run-phan.sh full runs the extended checks
  • run-phan.sh full 1 updates the baseline for the extended checks

Baseline

The baseline.txt file in this directory defines the issues that are currently excluded from the final report. In principle you should not add any more exceptions to that file, but rather fix the issues or add phan annotations that provide more information or to exclude specific cases.

Configuration

config.php : Default configuration file

config_extended.php : Configuration that enables more checks.

baseline.txt : Ignored issues (with config.php)

baseline_extended.txt : Ignored issues (with config_extended.php), not currently in git