Alexia / php7mar

PHP 7 Migration Assistant Report (MAR)
GNU General Public License v3.0
795 stars 133 forks source link

Less clutter on the report (avoiding those items that are not requiring changes) #11

Closed peterbowey closed 9 years ago

peterbowey commented 9 years ago

@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 commented 9 years ago

I was thinking about this same issue last week how to reduce the clutter. I definitely approve of the change. I also want to work in a "relaxed" and "strict" mode so that people can go hog wild with PHP 7 changes if they like.

I am a bit occupied today with some outside work so I will look at this later.

peterbowey commented 9 years ago

@Alexia I discovered a good reason to run 'php7mar' under PHP 7:

Example, PHP7 will catch these types of syntax changes (unexpected 'new' (T_NEW)):

$client = & new xmlrpc_client('/xml-rpc-server/','software.realtyna.com',80);

Under php7 (only), php7mar will now report:

#### /root/www-backup-23-june-prior-ereg-clean/virtual/gobuylocal.com.au/plugins/xmlrpc/magicupdaterpro.php
* syntax
 * Line 154: `  { //PHP Parse error:  syntax error, unexpected 'new' (T_NEW) on line 154`

Thus, we know to remove the '&' (via = & new) and change the code to:

$client = new xmlrpc_client('/xml-rpc-server/','software.realtyna.com',80);

An earlier PHP (say 5.x) will ignore this unexpected 'new' (T_NEW) state using php -l :)

Alexia commented 9 years ago

@peterbowey It can be ran under both, but running it can be given a path to the PHP 7 binary with the --php switch for syntax checking.

--php="/path/to/php/binary/php"
peterbowey commented 9 years ago

@Alexia Thanks for that alternative as a [PHP run-time option]. I can state my intention was a 'forewarning' to other users, of 'php7mar', to use PHP 7 as the final 'syntax check', thus no grief on the unexpected 'new' (T_NEW) silence (using an older PHP).

Alexia commented 9 years ago

Just had an idea. Then syntax check can warn if the version of PHP being used is not high enough.

peterbowey commented 9 years ago

@Alexia

"Absolutely" a great idea!

Notes: I am happy to state that your 'php7mar' (along with the new regex) has helped me to migrate 12 mixed older sites to using PHP 7. I see over a 120 hours saved...

Many thanks :)

Alexia commented 9 years ago

I ended up extending @LawnGnome's regex he put up on Twitter back in May. The one I created and subsequently modifications to it still were not producing proper test results.

Fixed in commit: https://github.com/Alexia/php7mar/commit/357630aad78f9f7ae7526104bd3995095fd79062

I will work on the other things noted here this week.

peterbowey commented 9 years ago

@Alexia

New regex @ https://github.com/Alexia/php7mar/commit/357630aad78f9f7ae7526104bd3995095fd79062 looks good!

Alexia commented 9 years ago

It will now spit out a warning in the report if something lower than PHP 7.0.0-dev was used for syntax checking. https://github.com/Alexia/php7mar/commit/1e26de191758454d92cfa9a3cedf145c5c170e39

peterbowey commented 9 years ago

@Alexia https://github.com/Alexia/php7mar/commit/1e26de191758454d92cfa9a3cedf145c5c170e39 looks good!

Alexia commented 9 years ago

At this time it looks like these issues are solved. Going to close this ticket.