├── .gitignore ├── LICENSE ├── PhpCodeSnifferStandards ├── .gitkeep └── PhpCompatibility │ └── .gitkeep ├── README.MD ├── composer.json └── phpcs.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | /vendor/ 3 | .idea 4 | PhpCodeSnifferStandards/* 5 | !PhpCodeSnifferStandards/.gitkeep 6 | !PhpCodeSnifferStandards/PhpCompatibility/.gitkeep -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 SWIS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PhpCodeSnifferStandards/.gitkeep: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !PhpCompatibility 4 | !PhpCompatibility/.gitkeep -------------------------------------------------------------------------------- /PhpCodeSnifferStandards/PhpCompatibility/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swisnl/php7-upgrade-tools/d2d77f4f5f0c1562d5dd6991b445226ebed327be/PhpCodeSnifferStandards/PhpCompatibility/.gitkeep -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # Php 7 upgrade tools 2 | 3 | This repository installs a set of tools for upgrading PHP installation to PHP 7. 4 | 5 | ## Installation 6 | 7 | Clone the repository and run ``composer install``, this will setup all the tool and configure them. This installation only works on Linux. 8 | 9 | ## Installed tools 10 | 11 | ### PHP Compatibility Coding Standard for PHP_CodeSniffer 12 | 13 | This is a set of sniffs for PHP_CodeSniffer that checks for PHP version compatibility. It will allow you to analyse your code for compatibility with higher and lower versions of PHP. 14 | 15 | [wimg/PHPCompatibility](https://github.com/wimg/PHPCompatibility) 16 | 17 | ### PHP 7 Compatibility Checker (php7cc) 18 | 19 | php7cc is a command line tool designed to make migration from PHP 5.3-5.6 to PHP 7 easier. It searches for potentially troublesome statements in existing code and generates reports containing file names, line numbers and short problem descriptions. It does not automatically fix code to work with the new PHP version. 20 | 21 | [sstalle/php7cc](https://github.com/sstalle/php7cc) 22 | 23 | ### Command 24 | 25 | In your console run ``./vendor/bin/php7cc /path/to/your/code`` to run PHP Compatibility checker. 26 | 27 | 28 | ## Example libraries 29 | 30 | For very old sites, where you want some quick fixes for old the `mysql_*` and `ereg_*` functions you can include the following shims. 31 | 32 | ### PHP 7 Shim for ext/mysql 33 | 34 | This library attempts to create a drop-in replacement for ext/mysql on PHP 7 using mysqli. 35 | 36 | [dshafik/php7-mysql-shim](https://github.com/dshafik/php7-mysql-shim) 37 | bbrala/php7-ereg-shim 38 | 39 | `composer require dshafik/php7-mysql-shim --dev` 40 | 41 | ### PHP 7 Ereg shim 42 | 43 | Simple shim that can be included in old PHP 5 projects to provide ereg functionality through preg. Makes your life upgrading to PHP 7 a lot easier. 44 | 45 | [bbrala/php7-ereg-shim](https://github.com/bbrala/php7-ereg-shim) 46 | 47 | `composer require bbrala/php7-ereg-shim --dev` 48 | 49 | ## Snippets 50 | 51 | ### Preg replace eval has been removed 52 | 53 | Preg match with the [eval flag (/e) has been removed](http://php.net/manual/en/reference.pcre.pattern.modifiers.php#reference.pcre.pattern.modifiers.eval). 54 | 55 | #### Before 56 | ``` 57 | (.*?))e', 63 | '"" . strtoupper("$2") . ""', 64 | $html 65 | ); 66 | ``` 67 | 68 | #### After 69 | ``` 70 | (.*?))', 76 | function ($m) { 77 | return "" . strtoupper($m[2]) . ""; 78 | }, 79 | $html 80 | ); 81 | ``` 82 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "swisnl/php7-upgrade-tools", 3 | "description": "Set of tools to simplyfy upgrading to PHP 7 from older versions \"sstalle/php7cc\": \"*\"", 4 | "type": "project", 5 | "require-dev": { 6 | "squizlabs/php_codesniffer": "^2.0 || ^3.0.1", 7 | "wimg/php-compatibility": "~7.1", 8 | "sstalle/php7cc": "^1.2", 9 | "dshafik/php7-mysql-shim": "^0.2.0", 10 | "bbrala/php7-ereg-shim": "^1.0" 11 | }, 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Björn Brala", 16 | "email": "bjorn@swis.nl" 17 | } 18 | ], 19 | "scripts": { 20 | "post-autoload-dump" : [ 21 | "rm -rf ./PhpCodeSnifferStandards/PhpCompatibility/*", 22 | "cp -R ./vendor/wimg/php-compatibility/* ./PhpCodeSnifferStandards/PhpCompatibility", 23 | "vendor/bin/phpcs --config-set installed_paths $(pwd)/PhpCodeSnifferStandards" 24 | ] 25 | }, 26 | "config": { 27 | "preferred-install": "dist" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /phpcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | The coding standard for PHP_CodeSniffer itself. 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | --------------------------------------------------------------------------------