Carnet Wiki

Analyse statique

Version 5 — Juin 2023 James

Voir bootstrap, framework, sdk

#!/usr/bin/env bash


# Récupération de la liste des baselines
find plugins-dist/spip -name phpstan-baseline.neon \
    | grep -v vendor > tmp/baselines.txt


# Récupération de la liste des fonctions non trouvées par phpstan
rm  - f  tmp/_called cat  tmp/baselines .txt tmp/called.txt
while  read  |   xargs  -r  baseline
 do
     I  %   grep " Function "  "$ baseline "   %  \ |   grep 'not found' \
         | sed -e 's/.*Function //' -e 's/ not found.*//' >> tmp/_called.txt
 done  < *//'  |  wc  - l 
#  2052
 cat  tmp/baselines.txt | xargs -I % grep Function % | grep 'not found' \
    | sed -e 's/.*Function //' -e 's/ not found.txt
wc -l tmp/_called tmp/called .txt
# 2052 tmp/_called.txt
rm -f tmp/baselines.txt
sort tmp/_called.txt *//'  |  sort  | uniq > tmp/called.txt
rm -f tmp/_called.txt
wc -l tmp/called.txt
# 330 tmp/called.txt


# Trouver les fichiers spip déclarant ces fonctions
rm -f tmp/_files tmp/baselines .txt tmp/files.txt
while  read  |   xargs  -r  fonction
 do
     grep I  %   egrep  -E  - rn --exclude-dir tests "^  '^ function $ fonction \("   %\('   ecrire \
        | cut -d: -f1 >>  |   sort  |   uniq  >  tmp/_files tmp/files .txt
done  <   cat  tmp/called.txt
sort tmp/_files.txt | uniq > tmp/files.txt
rm -f tmp/_files.txt
wc -l tmp/files.txt
# 64 tmp/files.txt


rm -f tmp/spip_files_functions.txt
while read - r  fichier
do
    grep  - E for  f  in  $( egrep  '^function (.*)\(' "$fichier "  $fichier |   sed -e 's/function //' -e 's/(.*//'  |  while  read  - r  f
     *//')
     do
        echo "$  $ fichier,$f"  >>   tmp/spip_files_functions.txt
    done
done < tmp/files.txt
wc -l tmp/spip_files_functions.txt
# 1244 tmp/spip_files_functions.txt


echo "ecrire/inc/utils.php
ecrire/base/connect_sql.php
ecrire/base/objets.php
ecrire/inc/flock.php" > tmp/bootstrap.txt
rm -f tmp/bootstrap_files_functions.txt
while read - r  fichier
do
    grep  - E for  f  in  $( egrep  '^function (.*)\(' "$fichier "  $fichier |   sed -e 's/function //' -e 's/(.*//'  |  while  read  - r  f
     *//')
     do
        echo "$  $ fichier,$f"  >>   tmp/bootstrap_files_functions.txt
    done
done &lt; tmp/bootstrap.txt
wc -l tmp/bootstrap_files_functions.txt
# 135 tmp/bootstrap_files_functions.txt


rm -f tmp/non_called_bootstrap.txt
while  read  - r  f
 `
 do
    fonction=$(cut -d, -f2 &lt;<< "$  $ f")
     )
     if ! grep egrep  -E  - c "^${fonction}$" tmp/called.txt > /dev/null
    then
        echo "$  $ fonction"  >>   tmp/non_called_bootstrap.txt
    fi
 done  &lt;   for  f  in  ` cat  tmp/bootstrap_files_functions.txt
fi
 done
 wc -l tmp/non_called_bootstrap.txt
Fichiers
Liste des fichiers contenant au moins une fonction appelée par un plugin dist
Fonctions
Liste des fonctions appelées au moins une fois dans du code php des plugins dist

Séquence de démarrage de SPIP

Site « public » :

index.php(spip.php)
ecrire/inc_version.php
config/ecran_securite.php (sous condition*)
vendor/autoload.php
side effect @umask(0) ;
ecrire/inc/utils.php
side effect déclaration 2 globales
ecrire/base/connect_sql.php
ecrire/base/objets.php
config/mes_options.php (si existe)
call spip_initialisation_core()
config/chmod.php
ecrire/inc/flock.php
inc/nfslock (par défaut ecrire/inc/nsflock.php, surchargeable) sous condition
inc/acces (par défaut ecrire/inc/acces.php, surchargeable)
side effect déclaration 1 globale
call load_path_cache()
inc/cookie sous condition + call recuperer_cookies_spip()
tmp/cache/charger_plugins_options.php (si existe) OU call spip_initialisation_suite()+inc/plugin (par défaut ecrire/inc/plugin.php, surchargeable)+ call actualise_plugins_actifs()
call spip_initialisation_suite()
call init_var_mode()
inc/autoriser (par défaut ecrire/inc/autoriser.php, surchargeable) sous condiftion
call autoriser()
inc/autoriser
aiguilleur d’installation**
cas particulier memoriser un tri sessionne eventuel***
side effect envoie d’entêtes http
side effect spip_log****
ecrire/public.php
call recuperer_fond() OU
ecrire/inc_version.php sous condition ??
aiguillage fond/page/action
...

Site privé :

ecrire/index.php
ecrire/inc_version.php
config/ecran_securite.php (sous condition*)
vendor/autoload.php
side effect @umask(0) ;
ecrire/inc/utils.php
side effect déclaration 2 globales
ecrire/base/connect_sql.php
ecrire/base/objets.php
config/mes_options.php (si existe)
call spip_initialisation_core()
config/chmod.php
ecrire/inc/flock.php
inc/nfslock (par défaut ecrire/inc/nsflock.php, surchargeable) sous condition
inc/acces (par défaut ecrire/inc/acces.php, surchargeable)
side effect déclaration 1 globale
call load_path_cache()
inc/cookie sous condition + call recuperer_cookies_spip()
tmp/cache/charger_plugins_options.php (si existe) OU call spip_initialisation_suite()+inc/plugin (par défaut ecrire/inc/plugin.php, surchargeable)+ call actualise_plugins_actifs()
call spip_initialisation_suite()
call init_var_mode()
inc/autoriser (par défaut ecrire/inc/autoriser.php, surchargeable) sous condiftion
call autoriser()
inc/autoriser (par défaut ecrire/inc/autoriser.php, surchargeable)
aiguilleur d’installation**
cas particulier memoriser un tri sessionne eventuel***
envoie d’entêtes http
spip_log****
inc/cookie (par défaut ecrire/inc/cookie.php, surchargeable)
...