https://github.com/phan/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)

1
$ vim ~/.bash_profile 
2
export PATH=~/.composer/vendor/bin:$PATH
3
4
$ source ~/.bash_profile
5
$ composer global require phan/phan
6
$ pecl channel-update pecl.php.net;
7
$ 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)

1
$ cd ~/Projets/PlateformeDEV/rhlog
2
$ touch .phan/config.php
3
$ vim .phan/config.php

Dans lequel on vient préciser la version de PHP ciblée et les dossiers à analyser ou bien exclure.

1
<?php
2
3
/**
4
 * This configuration will be read and overlaid on top of the
5
 * default configuration. Command line arguments will be applied
6
 * after this file is read.
7
 */
8
return [
9
    'target_php_version' => 8.1,
10
11
    // A list of directories that should be parsed for class and
12
    // method information. After excluding the directories
13
    // defined in exclude_analysis_directory_list, the remaining
14
    // files will be statically analyzed for errors.
15
    //
16
    // Thus, both first-party and third-party code being used by
17
    // your application should be included in this list.
18
    'directory_list' => [
19
        'core/',
20
        'modules/',
21
    ],
22
23
    // A directory list that defines files that will be excluded
24
    // from static analysis, but whose class and method
25
    // information should be included.
26
    //
27
    // Generally, you'll want to include the directories for
28
    // third-party code (such as "vendor/") in this list.
29
    //
30
    // n.b.: If you'd like to parse but not analyze 3rd
31
    //       party code, directories containing that code
32
    //       should be added to both the `directory_list`
33
    //       and `exclude_analysis_directory_list` arrays.
34
    "exclude_analysis_directory_list" => [
35
        'vendor/'
36
    ],
37
];

Puis on lance l'analyse en redirigeant la sortie dans un fichier.

1
$ phan -d ~/Projets/PlateformeDEV/rhlog --progress-bar -o ~/phan.out

Voici 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.

1
$ cat ~/phan.out | grep 'php 8'
2
core/lib/interne/PHP/AffichageHTML.class.php:989 
3
UndeclaredConstant Reference to undeclared constant \MEMCACHE_COMPRESSED. This will cause a thrown Error in php 8.0+.
4
5
core/lib/interne/PHP/UndeadBrain.class.php:2075 
6
UndeclaredConstant Reference to undeclared constant \MEMCACHE_COMPRESSED. This will cause a thrown Error in php 8.0+.
7
8
core/lib/interne/PHP/Utiles.class.php:1432 
9
UndeclaredConstant Reference to undeclared constant \‘’. This will cause a thrown Error in php 8.0+.
10
11
core/lib/interne/PHP/Utiles.class.php:2310
12
UndeclaredConstant Reference to undeclared constant \nIncrementRepetitions. This will cause a thrown Error in php 8.0+. (Did you mean $nIncrementRepetitions)
13
14
modules/document/controllers/CronDocumentAdminAction.class.php:935 
15
UndeclaredConstant Reference to undeclared constant \CP_UID. This will cause a thrown Error in php 8.0+.
16
17
modules/document/controllers/CronDocumentAdminAction.class.php:978 
18
UndeclaredConstant Reference to undeclared constant \CP_UID. This will cause a thrown Error in php 8.0+.
19
20
modules/document/controllers/CronDocumentAdminAction.class.php:985 
21
UndeclaredConstant Reference to undeclared constant \CP_UID. This will cause a thrown Error in php 8.0+.
22
23
modules/document/controllers/CronDocumentAdminAction.class.php:1077 
24
UndeclaredConstant Reference to undeclared constant \SE_UID. This will cause a thrown Error in php 8.0+.
25
26
modules/document/controllers/CronDocumentAdminAction.class.php:1077 
27
UndeclaredConstant Reference to undeclared constant \SORTDATE. This will cause a thrown Error in php 8.0+.
28
29
modules/document/controllers/CronDocumentAdminAction.class.php:1085 
30
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 sur des réseaux sociaux
Partager le lien
Partager par email

S'il vous plaît S'identifier afin de partager ce webpage par email