Introduction à Phan
Phan est un analyseur statique pour PHP qui préfère minimiser les faux positifs. Phan tente de prouver l'inexactitude plutôt que l'exactitude. Phan recherche les problèmes courants et vérifie la compatibilité des types sur diverses opérations lorsque les informations de type sont disponibles ou peuvent être déduites.
On ajoute le chemin ~/.composer/vendor/bin dans le PATH, puis on installe phan de manière globale via composer sans oublier d' installer la dépendance ast avec pecl. (profil à adapter si ZSH au lieu de Bash)
$ vim ~/.bash_profile export PATH=~/.composer/vendor/bin:$PATH$ source ~/.bash_profile$ composer global require phan/phan$ pecl channel-update pecl.php.net;$ pecl install ast-1.0.16;On crée un fichier de config dans un dossier caché à la racine du projet (penser à l'ajouter dans .gitignore)
$ cd ~/Projets/PlateformeDEV/rhlog$ touch .phan/config.php$ vim .phan/config.phpDans lequel on vient préciser la version de PHP ciblée et les dossiers à analyser ou bien exclure.
<?php/** * This configuration will be read and overlaid on top of the * default configuration. Command line arguments will be applied * after this file is read. */return [ 'target_php_version' => 8.1, // A list of directories that should be parsed for class and // method information. After excluding the directories // defined in exclude_analysis_directory_list, the remaining // files will be statically analyzed for errors. // // Thus, both first-party and third-party code being used by // your application should be included in this list. 'directory_list' => [ 'core/', 'modules/', ], // A directory list that defines files that will be excluded // from static analysis, but whose class and method // information should be included. // // Generally, you'll want to include the directories for // third-party code (such as "vendor/") in this list. // // n.b.: If you'd like to parse but not analyze 3rd // party code, directories containing that code // should be added to both the `directory_list` // and `exclude_analysis_directory_list` arrays. "exclude_analysis_directory_list" => [ 'vendor/' ],];Puis on lance l'analyse en redirigeant la sortie dans un fichier.
$ phan -d ~/Projets/PlateformeDEV/rhlog --progress-bar -o ~/phan.outVoici un extrait du fichier ~/phan.out avec uniquement les lignes qui contiennent php 8. Les lignes 1432 et 2310 devaient effectivement être corrigées, pour le reste ce ne sont que des faux positifs rencontrés avec des constantes.
$ cat ~/phan.out | grep 'php 8'core/lib/interne/PHP/AffichageHTML.class.php:989 UndeclaredConstant Reference to undeclared constant \MEMCACHE_COMPRESSED. This will cause a thrown Error in php 8.0+.core/lib/interne/PHP/UndeadBrain.class.php:2075 UndeclaredConstant Reference to undeclared constant \MEMCACHE_COMPRESSED. This will cause a thrown Error in php 8.0+.core/lib/interne/PHP/Utiles.class.php:1432 UndeclaredConstant Reference to undeclared constant \‘’. This will cause a thrown Error in php 8.0+.core/lib/interne/PHP/Utiles.class.php:2310UndeclaredConstant Reference to undeclared constant \nIncrementRepetitions. This will cause a thrown Error in php 8.0+. (Did you mean $nIncrementRepetitions)modules/document/controllers/CronDocumentAdminAction.class.php:935 UndeclaredConstant Reference to undeclared constant \CP_UID. This will cause a thrown Error in php 8.0+.modules/document/controllers/CronDocumentAdminAction.class.php:978 UndeclaredConstant Reference to undeclared constant \CP_UID. This will cause a thrown Error in php 8.0+.modules/document/controllers/CronDocumentAdminAction.class.php:985 UndeclaredConstant Reference to undeclared constant \CP_UID. This will cause a thrown Error in php 8.0+.modules/document/controllers/CronDocumentAdminAction.class.php:1077 UndeclaredConstant Reference to undeclared constant \SE_UID. This will cause a thrown Error in php 8.0+.modules/document/controllers/CronDocumentAdminAction.class.php:1077 UndeclaredConstant Reference to undeclared constant \SORTDATE. This will cause a thrown Error in php 8.0+.modules/document/controllers/CronDocumentAdminAction.class.php:1085 UndeclaredConstant Reference to undeclared constant \FT_UID. This will cause a thrown Error in php 8.0+.| Vues | |
|---|---|
| 10 | Total des vues |
| 10 | Vues Membres |
| 0 | Vues publiques |
| Actions | |
|---|---|
| 0 | Aime |
| 0 | N'aime pas |
| 0 | Commentaires |
Partager par email
S'il vous plaît S'identifier afin de partager ce webpage par email