Find all PEAR packages needed in the project (source code)

I ran into a problem for which I need a list of all PEAR packages that are needed (= used) in my project. Is there a tool that can get me a list of all PEAR packages used in my source code just by reading the code? To read all the packages that are installed is not enough, I really need only those that are actually used. I need this so that I can update the packages, or better, replace them with new libraries installed through the composer.

I came across the PEAR PHP_CompatInfo package , but this does not give me good results, and also displays only the list that are registered in the plugin itself.

+5
source share
1 answer

First I would evaluate which PEAR classes are installed on the system

if you think that some of the Libs used in the project may be missing, you need to download the entire Pear repository locally

To download all packages, do:

pear config-set preferred_state alpha pear remote-list | awk '{print $1}' > tmp-list ; tail -n +5 tmp-list > pear-list ; rm tmp-list cat pear-list | xargs -n 1 pear install 

Then, to create a list of all classes:

 cd /usr/share/php #( or different path to pear libs ) find . ! -path "*/tests/*" ! -path "*/examples/*" -name "*.php" -type f | xargs grep -Pho "^class ([a-zA-Z0-9_]+)" | sed -e "s/^class //" -e "" > all_pear.txt 

This will create a list of all the Pear classes stored in all_pear.txt

Then I would look for all the links in my code

 cd my_project; while read line; do find . -name "*.php" -type f | xargs grep -Pho $line; done < path/to/all_pear.txt | sort | uniq > used_classes.txt 

This will create a list of all the PEAR classes used in the project and save the list to the used_classes.txt file

+2
source

All Articles