alexia / php7mar Goto Github PK
View Code? Open in Web Editor NEWPHP 7 Migration Assistant Report (MAR)
License: GNU General Public License v3.0
PHP 7 Migration Assistant Report (MAR)
License: GNU General Public License v3.0
very useful :-)
I can't tell why this is being thrown, but whatever class was being processed apparently causied $tokens = token_get_all("<?php ".$matches[1]."?>");
to throw this warning.
Warning: Unterminated comment starting line 1 in /path/to/php7mar/classes/tests/critical.php on line 71
Call Stack:
0.0011 383168 1. {main}() /path/to/php7mar/mar.php:0
0.0012 383296 2. alexia\mar\main->__construct() /path/to/php7mar/mar.php:189
0.9838 2562976 3. alexia\mar\main->run() /path/to/php7mar/mar.php:86
810.4077 3245656 4. alexia\mar\tests->testLine() /path/to/php7mar/mar.php:139
810.4077 3245656 5. call_user_func:{/path/to/php7mar/classes/tests.php:108}() /path/to/php7mar/classes/tests.php:108
810.4077 3245656 6. alexia\mar\tests\critical->_duplicateFunctionParameter() /path/to/php7mar/classes/tests.php:108
810.4077 3246328 7. token_get_all() /path/to/php7mar/classes/tests/critical.php:71
PHP: 5.6, 7.1 & 7.2
OS: Mac OS X High Sierra
When the file can not be accessed (broken symlink, etc.), there will be a warning.
PHP Warning: file(/home/user/project/some-file.php): failed to open stream: No such file or directory in /home/user/php7mar/classes/scanner.php on line 101
PHP Notice: Undefined index: line in /home/user/php7mar/mar.php on line 126
There should be a check for the actual and current value.
I used this on a test box at work to run against our code base to show how simple upgrading to PHP 7.2 will be (from 5.6) given the improvements, but the generated report showed probably 75% of errors originating from commented out lines (I don't know why we have so many, but that's a task for another time) these should be ignored to boot.
This included single line comments and block comments.
For example:
This code is clearly commented out, yet gets flagged.
It wouldn't be wrong to include this in a notices
section or something of the like, just to make users aware that they have comments full of deprecated code like we do for some unknown reason; but it shouldn't show in the main list of problems.
It is not new operator withh reference
# critical
#### D:\user.php
* newOperatorWithReference
* Line 174: ` if (isset($expiration_date) && new \DateTime($expiration_date)
When running mar.php i get the following error:
PHP Parse error: syntax error, unexpected '[', expecting ')' in /usr/local/share/php7mar/mar.php on line 58
Maybe php7mar itelf needs PHP 7? I don't see any mention of that in the readme.
:)
Some directories may have test failures immediately noticed, especially test folders (E.g. /tests/, vendor/phpunit and it's dependencies, etc.)
An exclude CLI flag with a regex to use to search the relative path within the folder would be useful.
e.g. to exclude /path/to/project/subdir/tests and /path/to/project/vendor/phpunit:
-f /path/to/project --exclude '@/[tT]ests/|^vendor/phpunit/@'
Hey,
great project, thanks so far :)
Under Windows Server there is a small problem with the name of the generated report file:
In reporter.php at L78 (https://github.com/Alexia/php7mar/blob/master/classes/reporter.php#L78):
$this->fullFilePath = $this->reportFolder.date('Y-m-d H:i:s ').basename($this->projectPath, '.php').".md";
The ':' inside the date-string lead to a filesystem error as ':' is not allowed inside file names under windows. I fixed it locally by using dots instead but maybe you can change it globally so it is working under all environments by default?
Thanks and regards
@Alexia, A wonderful tool, it has saved a lot of time - for me!
A suggestion and a tested 'patch' to eliminate some of the "php7mar" report noise:
Change file php7mar/classes/tests/critical.php
-$regex = "#(?:(?:->|\\$)\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+|::\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+\[.+?\]\(.*?\))#i";
+$regex = "#(?:(?:\\$)\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+|(?:->|\\$)\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+\[.+?\]|::\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+\[.+?\]\(.*?\))#i";
Before Patch Report:
2015-07-05T20:36:10+09:30
Scanning /root/drupal6-2015/al-orig/cck/content.module
Including file extensions: php,inc,module
Processed 2508 lines contained in 1 files.
Processing took 0.039178133010864 seconds.
# critical
#### /root/drupal6-2015/al-orig/cck/content.module
* variableInterpolation
* Line 227: ` $node->$key = $value;`
* Line 234: ` $node->$key = $value;`
* Line 240: ` $node->$key = $value;`
* Line 341: ` if (isset($node->$field['field_name'])) {`
* Line 342: ` $items = $node->$field['field_name'];`
* Line 351: ` $node->$field['field_name'] = $items;`
* Line 352: ` $$this->{protocolVersion} = $version; // peter`
* Line 353: ` $$varname = $v; // Peter`
* Line 668: ` $node->$field['field_name'] = $items;`
* Line 816: ` if (isset($node->translation_source->$field['field_name'])) {`
* Line 817: ` $addition[$field['field_name']] = $node->translation_source->$field['field_name'];`
* Line 943: ` if (isset($node->$field_name)) {`
* Line 980: ` if ($field['multiple'] && isset($node->$field['field_name'])) {`
* Line 986: ` foreach ($node->$field['field_name'] as $delta => $item) {`
* Line 1068: ` if (!isset($object->$field) && !count($update) && isset($info['default'])) {`
* Line 1069: ` $object->$field = $info['default'];`
* Line 1075: ` unset($object->$field);`
* Line 1078: ` if (isset($object->$field) || array_key_exists($field, $object)) {`
* Line 1080: ` if (isset($object->$field)) {`
* Line 1083: ` $values[] = $object->$field;`
* Line 1086: ` $values[] = serialize($object->$field);`
* Line 1110: ` $values[] = $object->$key;`
* Line 1120: ` $object->$field = db_last_insert_id($table, $field);`
* Line 1143: ` $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();`
* Line 1158: ` if (isset($node->$field['field_name']) || count($items)) {`
* Line 1159: ` $node->$field['field_name'] = $items;`
* Line 1179: ` $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();`
* Line 1187: ` if (isset($node->$field['field_name'])) {`
* Line 1188: ` $node->$field['field_name'] = $items;`
After Patch:
2015-07-05T20:37:05+09:30
Scanning /root/drupal6-2015/al-orig/cck/content.module
Including file extensions: php,inc,module
Processed 2508 lines contained in 1 files.
Processing took 0.039650917053223 seconds.
# critical
#### /root/drupal6-2015/al-orig/cck/content.module
* variableInterpolation
* Line 341: ` if (isset($node->$field['field_name'])) {`
* Line 342: ` $items = $node->$field['field_name'];`
* Line 351: ` $node->$field['field_name'] = $items;`
* Line 352: ` $$this->{protocolVersion} = $version; // peter`
* Line 353: ` $$varname = $v; // Peter`
* Line 668: ` $node->$field['field_name'] = $items;`
* Line 816: ` if (isset($node->translation_source->$field['field_name'])) {`
* Line 817: ` $addition[$field['field_name']] = $node->translation_source->$field['field_name'];`
* Line 980: ` if ($field['multiple'] && isset($node->$field['field_name'])) {`
* Line 986: ` foreach ($node->$field['field_name'] as $delta => $item) {`
* Line 1143: ` $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();`
* Line 1158: ` if (isset($node->$field['field_name']) || count($items)) {`
* Line 1159: ` $node->$field['field_name'] = $items;`
* Line 1179: ` $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();`
* Line 1187: ` if (isset($node->$field['field_name'])) {`
* Line 1188: ` $node->$field['field_name'] = $items;`
This simple change avoids a number of 'unneeded' reports on the PHP Uniform Variable Syntax changes. The main target being those changed “variable variable” syntax issues = $$foo['bar'], $foo->$bar['baz'], and Foo::$bar['baz'].
@Alexia: I have seen improvements in several forks:
It is possible to update the main code and solve bugs?
Thanks in advance.
Wondering what is going wrong, getting this message:
PHP Notice: Undefined index: line in /home/xxxxxxi/public_html/testbed/mar.php on line 126
The report reads like this:
2017-10-05T13:55:47-05:00
Scanning /home/xxxxxxi/public_html/testbed/mem
Including file extensions: php
ERROR! Syntax checking was selected and a PHP binary lower than 7.0.0-dev was specified.
Processed 8346 lines contained in 98 files.
Processing took 2.6360139846802 seconds.
Have php7.0 installed. Maybe I do not understand entering correct path to php7.0 in command line?
Hello,
if you need repo with exclude folder option here is fork, I fork it for personal use to exclude vendor directory, but feel free to use it :
https://github.com/nikopeikrishvili/php7mar
This may be useful on large codebases, to track issues that were investigated and found to be false positives (especially if changes will be made later before running php7mar again, and one wants to know which issues were already investigated)
Proposed syntax:
Add a comment with @suppress php7mar-<issue type> [optional description]
anywhere in the line where the issue would be emitted.
Example:
foreach ($foo as &$value) { // @suppress php7mar-syntax (nothing else is iterating over this array)
(Without this proposed suppression, php7mar would emit a syntax error in the report warning about changed behavior of foreach by reference)
The function split was deprecated on PHP 5.6 and removed on PHP 7 but is not detected when I ran php7mar
I don't seem to be able to create a report with the results of the test.
My report looks like this
2017-06-17T10:11:49+02:00
Scanning C:\xampp\htdocs\job\index.php
Including file extensions: php
Processed 99 lines contained in 1 files.
Processing took 0.16114497184753 seconds.
But shouldn't I see the problems identified?
As soon as the folder contains a space, I've got this notice continuously (Windows 7 with wampserver 3.0.0):
Notice: Undefined index: line in D:\wamp64\\www\php7mar\mar.php on line 126
Comments should not be scanned:
####/XXXXXX/XXXXXXXX.php
* reservedNames
* Line 99: // get class object
* Line 179: // get class object
According to http://php.net/manual/en/reserved.variables.httprawpostdata.php the global $HTTP_RAW_POST_DATA is removed in PHP 7+. It did not show up running the critical report.
Perhaps filtering it would be a good option? It catches all the tests as violations of themselves.
This is easy with Box. See https://github.com/elgentos/masquerade/blob/master/box.json for an example configuration.
Using /e within preg_replace() is no longer support.
Looks like it tries to return $syntax
even if it's not defined.
So, something like:
Put #!/usr/bin/env php at the begining of mar.php
chmod +x mar.php
Rename mar.php to mar
Put "bin": ["mar"] in composer.json
Then if vendor/bin is in the path, this could be much easier started, so just by typing mar.
If you like this, I can send a PR.
It is understood that intention is not supported by this tool but since list()
has changed dramatically, the tool should at least detect and report its use. The intention is not even important here. What's important is that the output from list()
was reversed.
Does php7mar detect ArgumentCountError?
http://php.net/manual/en/migration71.incompatible.php
I had that error recently when upgrading a codebase from php 5.6 to 7.1
It caused a critical error (white screen) but i didn't see it in my php7mar reports.
Do i need to set the reports to 7.1 somewhere? Or does t just not pick up that error?
Hi,
The line numbers in the logs are all wrong (approximatly 30 lines less).
#### /blabla.ph
* foreachByReference
* Line 195: ` foreach ($aStats as $sKey => &$mValue)`
This foreach is in line 235, not 195.
(Funnily) running php7mar with php 7.2 results in:
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /Users/xxx/php7mar/classes/scanner.php on line 95
Fix should be easy converting to a foreach
Spell undesirable in README.md
I did a lot of tests and i don't find a good resolution of my problems, maybe the code has to be atualized!!
A lot of questions of PHP 7 is ignored by de MARS, like constructs and others changes that happens into PHP 7
Other problem is the lexical sintaxs that is not verified by MARS. In my case, is a huge project and the MARS can't be used! But the project has a nice ideia!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.