llaville / php-compatinfo

Library that find out the minimum version and the extensions required for a piece of code to run
https://llaville.github.io/php-compatinfo/7.1/
Other
371 stars 21 forks source link

class PhpParser\Node\Expr\PropertyFetch could not be converted to string #345

Closed remicollet closed 2 years ago

remicollet commented 2 years ago

Trying to analyse laminas-mail 2.16.0 sources tree


$ phpci laminas-mail-1ee1a384b96c8af29ecad9b3a7adc27a150ebc49/src/

 [ERROR] Handling "Bartlett\CompatInfo\Application\Query\Analyser\Compatibility\GetCompatibilityQuery" failed: Object of
         class PhpParser\Node\Expr\PropertyFetch could not be converted to string                                       
llaville commented 2 years ago

I've provided a screenshot in report 346 to see what it look like if you apply following patch.

diff --git a/src/Presentation/Console/Command/AnalyserCommand.php b/src/Presentation/Console/Command/AnalyserCommand.php
index 0c9e12c0..3ad51a6e 100644
--- a/src/Presentation/Console/Command/AnalyserCommand.php
+++ b/src/Presentation/Console/Command/AnalyserCommand.php
@@ -17,6 +17,8 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Messenger\Exception\HandlerFailedException;

+use function sprintf;
+
 /**
  * Analyse a data source to find out requirements.
  *
@@ -65,8 +67,29 @@ final class AnalyserCommand extends AbstractCommand implements CommandInterface
         try {
             $this->queryBus->query($compatibilityQuery);
         } catch (HandlerFailedException $e) {
+            $exceptions = [];
+            foreach($e->getNestedExceptions() as $exception) {
+                $exceptions[] = $exception->getMessage()
+                    . sprintf(' from file "%s" at line %d', $exception->getFile(), $exception->getLine());
+            }
             $io = new Style($input, $output);
-            $io->error($e->getMessage());
+            $io->error(
+                sprintf(
+                    'Cannot analyse data source "%s" for following reason(s)',
+                    $compatibilityQuery->getSource()
+                )
+            );
+            $io->listing($exceptions);
+            /** @var ApplicationInterface $app */
+            $app = $this->getApplication();
+            $io->note(
+                sprintf(
+                    'Issue found by %s version %s with DB version %s',
+                    $app->getName(),
+                    $app->getInstalledVersion(),
+                    $app->getInstalledVersion(true, 'bartlett/php-compatinfo-db')
+                )
+            );
             return self::FAILURE;
         }
llaville commented 2 years ago

And to fix error, patch to apply is :

diff --git a/src/Application/Sniffs/Fibers/FiberSniff.php b/src/Application/Sniffs/Fibers/FiberSniff.php
index b45a91a7..426f96bd 100644
--- a/src/Application/Sniffs/Fibers/FiberSniff.php
+++ b/src/Application/Sniffs/Fibers/FiberSniff.php
@@ -55,6 +55,10 @@ final class FiberSniff extends SniffAbstract
             return null;
         }

+        if (!$node->class instanceof Node\Name) {
+            return null;
+        }
+
         if ('Fiber' === (string) $node->class) {
             $this->updateNodeElementVersion($node, $this->attributeKeyStore, ['php.min' => '8.1.0alpha1']);
             $this->updateNodeElementRule($node, $this->attributeKeyStore, self::CA81);

Even if CompatibilityAnalyser, after that, display a report, I'm not yet sure about the minimum PHP value found ;-) But it's another problem !

llaville commented 2 years ago

Patches were applied on branch 6.3

llaville commented 2 years ago

@remicollet FYI when I said

Even if CompatibilityAnalyser, after that, display a report, I'm not yet sure about the minimum PHP value found ;-) But it's another problem !

I finally found origin of detection issue. Fix will follow !

llaville commented 2 years ago

After applying fix of issue 348, analysis of laminas mail 2.16.0 give me acceptable results.

laminas-mail-2160