PhpCodeAnalyzer scans codebase and analyzes which non-built-in php extensions used

Overview

PhpCodeAnalyzer

PhpCodeAnalyzer finds usage of different non-built-in extensions in your php code. This tool helps you understand how transportable your code between php installations is.

Latest Stable Version Total Downloads License

TOC

Example of usage

To scan your files or folder launch phpca and pass file or directory names.

> phpca ..\HttpServer
Scanning ..\HttpServer ...
[spl] Function "spl_autoload_register" used in file ..\HttpServer/vendor/composer/ClassLoader.php[258]
[spl] Function "spl_autoload_unregister" used in file ..\HttpServer/vendor/composer/ClassLoader.php[266]
[spl] Function "spl_autoload_register" used in file ..\HttpServer/vendor/composer/autoload_real.php[22]
[spl] Function "spl_autoload_unregister" used in file ..\HttpServer/vendor/composer/autoload_real.php[24]

Used non-built-in extensions in your code:
- [spl] Standard PHP Library (SPL). This extension is bundled with php since PHP 5.0.0. Extension is available in pecl: spl.

You can skip progress with --no-progress option:

> phpca --no-progress ..\yii-1.1.16.bca042\framework\caching
Scanning ..\yii-1.1.16.bca042\framework\caching ...

Used non-built-in extensions in your code:
- [apc] Alternative PHP Cache. Extension is available in pecl: apc.
- [wincache] Windows Cache for PHP. Extension is available in pecl: wincache.

Also, you can keep only progress with --no-report option:

> phpca --no-report ..\yii-1.1.16.bca042\framework\caching
Scanning ..\yii-1.1.16.bca042\framework\caching ...
[apc] Function "apc_fetch" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[46]
[apc] Function "apc_fetch" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[56]
[apc] Function "apc_store" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[70]
[apc] Function "apc_add" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[84]
[apc] Function "apc_delete" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[95]
[apc] Function "apc_clear_cache" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[107]
[apc] Function "apc_clear_cache" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[109]
[wincache] Function "wincache_ucache_get" used in file ..\yii-1.1.16.bca042\framework\caching/CWinCache.php[46]
[wincache] Function "wincache_ucache_get" used in file ..\yii-1.1.16.bca042\framework\caching/CWinCache.php[56]
[wincache] Function "wincache_ucache_set" used in file ..\yii-1.1.16.bca042\framework\caching/CWinCache.php[70]
[wincache] Function "wincache_ucache_add" used in file ..\yii-1.1.16.bca042\framework\caching/CWinCache.php[84]
[wincache] Function "wincache_ucache_delete" used in file ..\yii-1.1.16.bca042\framework\caching/CWinCache.php[95]
[wincache] Function "wincache_ucache_clear" used in file ..\yii-1.1.16.bca042\framework\caching/CWinCache.php[106]

If you want to see only usage of one specific extension, use --extension= option:

> phpca --extension=apc ..\yii-1.1.16.bca042\framework\caching
Scanning ..\yii-1.1.16.bca042\framework\caching ...
[apc] Function "apc_fetch" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[46]
[apc] Function "apc_fetch" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[56]
[apc] Function "apc_store" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[70]
[apc] Function "apc_add" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[84]
[apc] Function "apc_delete" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[95]
[apc] Function "apc_clear_cache" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[107]
[apc] Function "apc_clear_cache" used in file ..\yii-1.1.16.bca042\framework\caching/CApcCache.php[109]

Summary report in this case will not be added at the end.

Help

Full list of available options:

> phpca -h
PhpCodeAnalyzer
Usage:
    phpca [-v] [-q] [--output=<path>] [--no-report] [--no-progress] [--since-version=<version>] FILES...
    phpca [-v] [-q] [--output=<path>] --extension=<ext> FILES...
    phpca -h

Options:
  -h --help                 Show this text
  -v --verbose              Show more debug text
  -q --quiet                Don't print any messages
  --output=<path>           Path where to generate XML report
  --extension=<ext>         Look for usage a specific extension
  --no-report               Turn off summary report
  --no-progress             Turn off progress
  --since-version=<version> Only include extensions not included since version

Installation

Phar

  1. Just download a phar from releases page and make executable
chmod +x phpca.phar
  1. a. Local installation: use it from current folder:

    ./phpca.phar -h

    b. Global installation: move it in to one of folders listed in your $PATH and run from any folder:

    sudo mv phpca.phar /usr/local/bin/phpca
    phpca -h

Composer

Another way to install phpca is via composer.

  1. Install composer:
curl -sS https://getcomposer.org/installer | php
  1. Install phpcf in global composer dir:
./composer.phar global require wapmorgan/php-code-analyzer dev-master
  1. Run from any folder:
phpca -h
Comments
  • Read PHP Version from files or accept parameter to silence errors

    Read PHP Version from files or accept parameter to silence errors

    I have a tag like the following in my code defining the min-PHP-version required:

    /**
     * ... license, intro and so on...
     *
     * PHP Version 7.2
     *
     * ... phpdocs ...
     */
    

    phpca still complains about "non-built-in" extensions that are bundled for quite a while:

    Used non-built-in extensions in your code:
    - [filter] Data Filtering. This extension is bundled with php since PHP 5.2.0. Extension is available in pecl: filter.
    - [curl] Client URL Library. This extension is bundled with php since PHP 4.0.2. Extension is available in pecl: curl.
    - [json] JavaScript Object Notation. This extension is bundled with php since PHP 5.2.0. Extension is available in pecl: json.
    - [spl] Standard PHP Library (SPL). This extension is bundled with php since PHP 5.0.0. Extension is available in pecl: spl.
    - [pdo] PHP Data Objects. This extension is bundled with php since PHP 5.1.0. Extension is available in pecl: pdo.
    

    Idea 1: ignore extensions that are bundled since the last official supported version (currently 5.6) Idea 2: parse my comment (it seems to be official way to tell php version) and silence everything that is, in my example, bundled in PHP 7.2

    opened by davidsneighbour 2
  • Allow users to ignore old php version extention warnings with the --since-version argument.

    Allow users to ignore old php version extention warnings with the --since-version argument.

    Its not important if curl wasnt included in PHP 4.0.2 if the project your working requires PHP 5.6/7 anyway, this just gives users the option to ignore those messages in the report.

    opened by leemason 2
  • Version flag

    Version flag

    This is a feature request: could you add a --version flag, to check which version one is currently running? Or is there a better way to check the version?

    enhancement 
    opened by MetalArend 1
  • Search php binary in user's $PATH is more flexibel

    Search php binary in user's $PATH is more flexibel

    When I try to run phpca I get the following error:

    $ phpca
    bash: phpca: /usr/bin/php: bad interpreter: No such file or directory
    

    Not everyone has the php binary in /usr/bin. For example my binary is located in /usr/local/bin. I replaced the interpreter #!/usr/bin/php in phpca with #!/usr/bin/env php to search dynamically for the php binary in user's $PATH.

    opened by phaldan 1
  • False positive

    False positive

    I ran:

    php www/bin/phpca www/src/ --since-version=7.2 | tee reports/phpca-src.txt
    

    I got the following response, which identified this class: Pool

    Scanning www/src/ ...
    [pthreads] Class "Pool" used in file www/src/path/to/file[84]
    
    Used non-built-in extensions in your code:
    - pthreads. Extension is available in pecl: pthreads.
    

    However, this is a snippet of my actual code, which is clearly not from the pthreads extension.

    use GuzzleHttp\Pool;
    
    $pool = new Pool($client, $requests(), [
        'concurrency' => 10,
        'fulfilled'   => static function ($response, $index): void { … },
        'rejected'    => static function ($reason, $index): void { … },
    ]);
    

    Here is the version information:

    $ composer info wapmorgan/php-code-analyzer -d www
    name     : wapmorgan/php-code-analyzer
    descrip. : A program that finds usage of different non-built-in extensions in your php code.
    keywords : code analysis, command-line utility
    versions : * dev-master
    type     : package
    license  : BSD 3-Clause "New" or "Revised" License (BSD-3-Clause) (OSI approved) https://spdx.org/licenses/BSD-3-Clause.html#licenseText
    source   : [git] https://github.com/wapmorgan/PhpCodeAnalyzer.git b778f61ee24b9e97b92422d853a37a350bde69a5
    dist     : [zip] https://api.github.com/repos/wapmorgan/PhpCodeAnalyzer/zipball/b778f61ee24b9e97b92422d853a37a350bde69a5 b778f61ee24b9e97b92422d853a37a350bde69a5
    names    : wapmorgan/php-code-analyzer
    
    autoload
    psr-4
    wapmorgan\PhpCodeAnalyzer\ => src/
    
    requires
    docopt/docopt ~1.0
    

    Perhaps resolving the namespace aliases first could reduce the false positives?

    bug 
    opened by skyzyx 1
Releases(1.0.6)
Owner
Sergey
Sergey
Analyzes PHPStan baseline files and creates aggregated error trend-reports

Analyzes phpstan baseline files Analyzes PHPStan baseline files and creates aggregated error trend-reports.

Markus Staab 22 Dec 23, 2022
Shortest Path - have a function ShortestPath (strArr) take strArr which will be an array of strings which models a non-looping Graph.

Have the function ShortestPath(strArr) take strArr which will be an array of strings which models a non-looping Graph

null 1 Feb 5, 2022
An auto software that collects, scans and sends automatic instagram users

Instagram Advanced User Finder V1.0.0 With this PHP script, you can find users on Instagram and message them. Feedback Türkçe Get Key every week, you

Yasin 70 Jan 4, 2023
This repository contains the codebase PHP bridge using RoadRunner Jobs plugin.

RoadRunner Jobs Plugin This repository contains the codebase PHP bridge using RoadRunner Jobs plugin. Installation To install application server and J

Spiral Scout 15 Nov 9, 2022
Generate API documentation for humans from your Laravel codebase.✍

Scribe v3 is out now! Scribe helps you generate API documentation for humans from your Laravel/Lumen/Dingo codebase. See a live example at demo.scribe

Knuckles 1k Jan 9, 2023
Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.

OpenMage 782 Jan 3, 2023
WARNING! This software is currently non-functional. - A system which makes installing Jexactyl far, far easier.

Jexactyl Assistant A system which makes installing Jexactyl far, far easier. WARNING ?? This software is currently in heavy alpha testing and WILL NOT

Jexactyl 7 Nov 14, 2022
Custom code snippets and examples for SkyVerge-built WooCommerce extensions

SkyVerge WooCommerce Plugins Welcome to the wc-plugins-snippets repository! This repository stores code snippets related to SkyVerge WooCommerce plugi

SkyVerge 255 Nov 16, 2022
Skosmos is a web-based tool providing services for accessing controlled vocabularies, which are used by indexers describing documents and searchers looking for suitable keywords.

Skosmos is a web-based tool providing services for accessing controlled vocabularies, which are used by indexers describing documents and searchers looking for suitable keywords.

National Library of Finland 195 Dec 24, 2022
This library implements a fuzzer for PHP, which can be used to find bugs in libraries

PHP Fuzzer This library implements a fuzzer for PHP, which can be used to find bugs in libraries (particularly parsing libraries) by feeding them "ran

Nikita Popov 341 Dec 25, 2022
TYPO3 CMS extension which extends TYPO3 page cache, by tags based on entities used in fluid templates.

Fluid Page Cache for TYPO3 CMS This TYPO3 CMS extension allows you to clear frontend page caches, automatically when a displayed record has been updat

Armin Vieweg 1 Apr 8, 2022
Allows reflection of object attributes, including inherited and non-public ones

sebastian/object-reflector Allows reflection of object attributes, including inherited and non-public ones. Installation You can add this library as a

Sebastian Bergmann 6k Jan 4, 2023
IgAnalyzer - Find non-followers and potential stalkers.

igAnalyzer Features Shows mutual followers, non-followers and non-followings via pie chart Shows monthly followers via area chart Shows followers via

LIII 6 Sep 9, 2022
Cbe frontauth - A Textpattern plugin to manage backend connections from frontend and protect content from non-logged users

cbe_frontauth This client-side plugin lets your users (or you) manage backend connection from frontend, i.e. connect and disconnect as they (you) woul

null 4 Jan 31, 2020
A non-intrusive support form that can be displayed on any page

A non-intrusive support bubble that can be displayed on any page Using this package you can quickly add a chat bubble that opens a support form on any

Spatie 288 Dec 28, 2022
search non profitable charity or organization through api search

Non Profile Charity Search Search non profitable organization or get the details of an organization Installation Require the package using composer: c

Touhidur Rahman 5 Jan 20, 2022
Automatically retry non-atomic upsert operation when unique key constraints are violated.

Laravel Retry on Duplicate Key Automatically retry non-atomic upsert operation when unique constraints are violated. e.g. firstOrCreate() updateOrCrea

mpyw 8 Dec 7, 2022
This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions

This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions. It is intended to be used when portability across PHP versions and extensions is desired.

Symfony 2.2k Dec 29, 2022
GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.

GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.

Shivam Mathur 2.4k Jan 6, 2023