Skip to content

Error - Could not process file.php file, due to System error - ClassMethodAndPropertyAnalyzer::isLocalPropertyVariableAssign #9568

@MasterGHD

Description

@MasterGHD

Bug Report

Subject Details
Rector version 2.2.14
PHP version 8.2.30 NTS x64 (Ubuntu)
Symfony version 5.4.40

Hello team,

I was testing the same project upgrade of the issue 9567, but the exception occured in a different file

The demo exception is the same as the other issue: "System error: "PhpParser\NodeAbstract::getComments(): Return value must be of type array, bool returned".

Minimal PHP Code Causing Issue

rector.php

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\SymfonySetList;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/src',
        __DIR__ . '/tests',
    ]);

    $rectorConfig->importNames(true, false);

    $rectorConfig->skip([
        __DIR__ . '/assets',
        __DIR__ . '/templates',
        __DIR__ . '/docs',
        __DIR__ . '/public',
        __DIR__ . '/web',
        __DIR__ . '/node_modules',
        __DIR__ . '/vendor',
        // Skip all naming rules in entities
        SetList::NAMING => [
            __DIR__ . '/src/GroupName/*/Entity/*',
        ],
    ]);

    $rectorConfig->sets([
        \Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_82,
        SymfonySetList::SYMFONY_54,
        SymfonySetList::SYMFONY_CODE_QUALITY,
        SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
        SetList::CODE_QUALITY,
        SetList::DEAD_CODE,
        SetList::TYPE_DECLARATION,
        SetList::PRIVATIZATION,
        SetList::INSTANCEOF,
        SetList::EARLY_RETURN,
    ]);
};

SiteNotification.php

<?php 

declare(strict_types=1);

namespace GroupName\PackageBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * SiteNotification
 *
 * @ORM\Table(name="site_notification")
 * @ORM\Entity
 */
class SiteNotification
{
    /**
     * @var int
     *
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     *
     * @ORM\ManyToOne(targetEntity="GroupName\PackageBundle\Entity\Site", inversedBy="notifications")
     * @ORM\JoinColumn(nullable=false)
     */
    protected Site $site;

    /**
     * @var Notification|null
     *
     * @ORM\ManyToOne(targetEntity="GroupName\PackageBundle\Entity\Notification", inversedBy="site_notifications")
     */
    protected $notification;

    /**
     * @var Collection|SiteNotificationLink[]
     *
     * @ORM\OneToMany(
     *     targetEntity="GroupName\PackageBundle\Entity\SiteNotificationLink",
     *     mappedBy="notification",
     *     cascade={"persist", "remove"}
     * )
     */
    private $links;

    public function __construct(Site $site)
    {
        $this->site = $site;
        $this->links = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getSite(): Site
    {
        return $this->site;
    }

    public function setNotification(Notification $notification): self
    {
        $this->notification = $notification;

        return $this;
    }

    public function getNotification(): ?Notification
    {
        return $this->notification;
    }

    public function addLink(SiteNotificationLink $link): self
    {
        if ($this->links->contains($link)) {
            return $this;
        }

        $this->links->add($link);
        $link->setNotification($this);

        return $this;
    }

    public function removeLink(SiteNotificationLink $link): self
    {
        $this->links->removeElement($link);

        $link->setNotification(null);

        return $this;
    }

    /**
     * @return Collection|SiteNotificationLink[]
     */
    public function getLinks(): Collection
    {
        return $this->links;
    }
}

Stack trace

[ERROR] Could not process                                                                                              
         "/home/username/projects/project-upgrade/src/GroupName/PackageBundle/Entity/SiteNotification.p
         hp" file, due to:                                                                                              
         "System error:                                                                                                 
         "Rector\TypeDeclaration\NodeAnalyzer\ClassMethodAndPropertyAnalyzer::isLocalPropertyVariableAssign(): Argument 
         #1 ($onlyClassMethodStmt) must be of type PhpParser\Node\Stmt, null given, called in                           
         vendor/rector/rector/rules/TypeDeclaration/NodeAnalyzer/ClassMethodAndPropertyAnalyzer.php48"                  
                                                                                                                        
         Stack trace:                                                                                                   
         #0 vendor/rector/rector/rules/TypeDeclaration/NodeAnalyzer/ClassMethodAndPropertyAnalyzer.php(48):             
         Rector\TypeDeclaration\NodeAnalyzer\ClassMethodAndPropertyAnalyzer->isLocalPropertyVariableAssign()            
         #1                                                                                                             
         vendor/rector/rector/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/SetterTypeDeclarationPropertyTypeInf
         erer.php(38): Rector\TypeDeclaration\NodeAnalyzer\ClassMethodAndPropertyAnalyzer->hasOnlyPropertyAssign()      
         #2 vendor/rector/rector/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php(163): 
         Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\SetterTypeDeclarationPropertyTypeInferer->inferProperty 
         ()                                                                                                             
         #3 vendor/rector/rector/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php(123): 
         Rector\TypeDeclaration\Rector\Class_\PropertyTypeFromStrictSetterGetterRector->matchGetterSetterIdenticalType( 
         )                                                                                                              
         #4 vendor/rector/rector/src/Rector/AbstractRector.php(115):                                                    
         Rector\TypeDeclaration\Rector\Class_\PropertyTypeFromStrictSetterGetterRector->refactor()                      
         #5 vendor/rector/rector/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php(160):                   
         Rector\Rector\AbstractRector->enterNode()                                                                      
         #6 vendor/rector/rector/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php(78):                    
         Rector\PhpParser\NodeTraverser\AbstractImmutableNodeTraverser->traverseArray()                                 
         #7 vendor/rector/rector/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php(187):                   
         Rector\PhpParser\NodeTraverser\AbstractImmutableNodeTraverser->traverseNode()                                  
         #8 vendor/rector/rector/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php(60):                    
         Rector\PhpParser\NodeTraverser\AbstractImmutableNodeTraverser->traverseArray()                                 
         #9 vendor/rector/rector/src/PhpParser/NodeTraverser/RectorNodeTraverser.php(51):                               
         Rector\PhpParser\NodeTraverser\AbstractImmutableNodeTraverser->traverse()                                      
         #10 vendor/rector/rector/src/Application/FileProcessor.php(95):                                                
         Rector\PhpParser\NodeTraverser\RectorNodeTraverser->traverse()                                                 
         #11 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(178):                                    
         Rector\Application\FileProcessor->processFile()                                                                
         #12 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(152):                                    
         Rector\Application\ApplicationFileProcessor->processFile()                                                     
         #13 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(128):                                    
         Rector\Application\ApplicationFileProcessor->processFiles()                                                    
         #14 vendor/rector/rector/src/Console/Command/ProcessCommand.php(182):                                          
         Rector\Application\ApplicationFileProcessor->run()                                                             
         #15 vendor/rector/rector/vendor/symfony/console/Command/Command.php(289):                                      
         Rector\Console\Command\ProcessCommand->execute()                                                               
         #16 vendor/rector/rector/vendor/symfony/console/Application.php(899):                                          
         RectorPrefix202512\Symfony\Component\Console\Command\Command->run()                                            
         #17 vendor/rector/rector/vendor/symfony/console/Application.php(279):                                          
         RectorPrefix202512\Symfony\Component\Console\Application->doRunCommand()                                       
         #18 vendor/rector/rector/src/Console/ConsoleApplication.php(60):                                               
         RectorPrefix202512\Symfony\Component\Console\Application->doRun()                                              
         #19 vendor/rector/rector/vendor/symfony/console/Application.php(162):                                          
         Rector\Console\ConsoleApplication->doRun()                                                                     
         #20 vendor/rector/rector/bin/rector.php(130): RectorPrefix202512\Symfony\Component\Console\Application->run()  
         #21 vendor/rector/rector/bin/rector(5): require_once('...')                                                    
         #22 vendor/bin/rector(117): include('...')                                                                     
         #23 {main}". On line: 70                                                                                       
                          

Expected Behaviour

The minimum behaviour is to warn the developer to refactor the code or to rector change it by itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions