Code Monkey home page Code Monkey logo

phpcodefixer's Introduction

PhpCodeFixer

PhpCodeFixer - a console scanner that checks compatibility of your code with new interpreter versions.

Composer package Latest Stable Version Total Downloads License

PhpCodeFixer finds:

  • Usage of deprecated functionality (functions / variables / ini-directives / constants).
  • Usage of functions with changed behavior.
  • Usage of reserved identifiers in newer versions.

It literally helps you fix code that can fail after migration to newer PHP version.

  1. Usage
  2. Example
  3. Installation

Usage

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

Usage:
    phpcf [--target VERSION] [--max-size SIZE] [--exclude NAME] [--file-extensions EXT] FILES...
    phpcf --version

Options:
  -v --version             Show version.
  -t --target VERSION      Sets target php version. [default: 7.2]
  -e --exclude NAME        Sets excluded file or directory names for scanning. If need to pass few names, join it with comma.
  -s --max-size SIZE       Sets max size of php file. If file is larger, it will be skipped. [default: 1mb]
     --file-extensions EXT Sets file extensions to be parsed. [default: php, phtml, php5]
  • By providing additional parameter --target you can specify version of PHP to perform less checks. Available target versions: 5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2. A larger version includes rules for checking from all previous.
  • By providing --exclude paramenter you can exclude specific folders or files from analyze. For example, --exclude vendor will prevent checking third-party libraries.
  • If your files has unusual extension, you can specify all exts by --file-extensions argument. By default, it uses php, phtml and php5.

Example of usage

> bin/phpcf tests
Max file size set to: 1.000 MiB
Scanning D:\Документы\PhpCodeFixer\tests ...

Folder D:\Документы\PhpCodeFixer\tests
 PHP | File:Line                           |             Type | Issue
 5.3 | /5.3.php:2                          | function         | Function dl() is deprecated.
 5.3 | /5.3.php:3                          | ini              | Ini define_syslog_variables is deprecated.
 5.3 | /5.3.php:4                          | function_usage   | Function usage piet() (@call_with_passing_by_reference) is deprecated.
 5.4 | /5.4.php:2                          | function         | Function mcrypt_generic_end() is deprecated.
 5.4 | /5.4.php:3                          | function         | Function magic_quotes_runtime() is deprecated.
 5.5 | /5.5.php:2                          | function_usage   | Function usage preg_replace() (@preg_replace_e_modifier) is deprecated.
 5.6 | /5.6.php:6                          | ini              | Ini mbstring.http_output is deprecated.
 5.6 | /5.6.php:3                          | variable         | Variable $HTTP_RAW_POST_DATA is deprecated.
 7.0 | /7.0.php:8                          | function         | Function mssql_connect() is deprecated.
 7.0 | /7.0.php:10                         | ini              | Ini always_populate_raw_post_data is deprecated.
 7.0 | /7.0.php:12                         | function_usage   | Function usage password_hash() (@password_hash_salt_option) is deprecated.
 7.0 | /7.0.php:14                         | identifier       | Identifier float is reserved by PHP core.
 7.0 | /7.0.php:3                          | method_name      | Method name test:test (@php4_constructors) is deprecated.
 7.1 | /7.1.php:2                          | function         | Function mcrypt_decrypt() is deprecated.
 7.1 | /7.1.php:4                          | ini              | Ini session.hash_function is deprecated.
 7.1 | /7.1.php:9                          | identifier       | Identifier iterable is reserved by PHP core.
 7.2 | /7.2.php:2                          | function         | Function create_function() is deprecated.
 7.2 | /7.2.php:7                          | function         | Function read_exif_data() is deprecated.
 7.2 | /7.2.php:9                          | constant         | Constant INTL_IDNA_VARIANT_2003 is deprecated.
 7.2 | /7.2.php:3                          | ini              | Ini mbstring.func_overload is deprecated.
 7.2 | /7.2.php:5                          | function_usage   | Function usage assert() (@assert_on_string) is deprecated.
 7.2 | /7.2.php:12                         | function_usage   | Function usage parse_str() (@parse_str_without_argument) is deprecated.

Total problems: 22

Replace Suggestions:
1. Don't use function mcrypt_generic_end() => Consider replace to mcrypt_generic_deinit().
2. Don't use function read_exif_data() => Consider replace to exif_read_data().
3. Don't use ini mbstring.http_output => Consider replace to default_charset.
4. Don't use variable $HTTP_RAW_POST_DATA => Consider replace to php://input.
5. Don't use constant INTL_IDNA_VARIANT_2003 => Consider replace to INTL_IDNA_VARIANT_UTS46.

Notes:
1. Usage piet() (@call_with_passing_by_reference): Call with passing by reference is deprecated. Problem is "&$hoho"
2. Usage preg_replace() (@preg_replace_e_modifier): Usage of "e" modifier in preg_replace is deprecated: "asdasdsd~ie"
3. Usage password_hash() (@password_hash_salt_option): "salt" option is not secure and deprecated now
4. Usage assert() (@assert_on_string): You should avoid using string code: "'false'"
5. Usage parse_str() (@parse_str_without_argument): Call to parse_str() without second argument is deprecated
Peak memory usage: 1.135 MB

Installation

Phar

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

    ./phpcf-x.x.x.phar -h

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

    sudo mv phpcf-x.x.x.phar /usr/local/bin/phpcf
    phpcf -h

Composer

Another way to install phpcf 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-fixer dev-master
  1. Run from any folder:
phpcf -h

phpcodefixer's People

Contributors

evgenyorekhov avatar phaldan avatar wapmorgan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.