Skip to content

Rector error: "Internar error." - php80 to php83 #8985

@andersondefaria1980

Description

@andersondefaria1980

I just had this error, when run rector on a file (the file is at the end of this topic).
Trying to adapt from php80 to php83

vendor/bin/rector process --dry-run

[ERROR] Could not process
"/home/anderson/projects/realiza-2/src/Infrastructure/Validators/Opn/IsResponsavelOperadorValidator.php" file,
due to:
"System error: "Internal error."
Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line: 928

Runnig with --debug

vendor/bin/rector process --dry-run --debug

[ERROR] Could not process
"/home/anderson/projects/realiza-2/src/Infrastructure/Validators/Opn/IsResponsavelOperadorValidator.php" file,
due to:
"System error: "Internal error."

     Stack trace:                                                                                                   
     #0 phar://vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(546):                             
     PHPStan\Analyser\MutatingScope->resolveType()                                                                  
     #1 phar://vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1163):                            
     PHPStan\Analyser\MutatingScope->getType()                                                                      
     #2 phar://vendor/phpstan/phpstan/phpstan.phar/src/Reflection/InitializerExprTypeResolver.php(438):             
     PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()                                                   
     #3 phar://vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1163):                            
     PHPStan\Reflection\InitializerExprTypeResolver->getArrayType()                                                 
     #4 phar://vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(546):                             
     PHPStan\Analyser\MutatingScope->resolveType()                                                                  
     #5 phar://vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(760):                             
     PHPStan\Analyser\MutatingScope->getType()                                                                      
     #6 phar://vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(546):                             
     PHPStan\Analyser\MutatingScope->resolveType()                                                                  
     #7 phar://vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1869):                            
     PHPStan\Analyser\MutatingScope->getType()                                                                      
     #8 vendor/rector/rector/src/NodeTypeResolver/NodeTypeResolver.php(498):                                        
     PHPStan\Analyser\MutatingScope->getNativeType()                                                                
     #9 vendor/rector/rector/src/NodeTypeResolver/NodeTypeResolver.php(235):                                        
     Rector\NodeTypeResolver\NodeTypeResolver->resolveNativeTypeWithBuiltinMethodCallFallback()                     
     #10 vendor/rector/rector/rules/TypeDeclaration/NodeAnalyzer/NeverFuncCallAnalyzer.php(43):                     
     Rector\NodeTypeResolver\NodeTypeResolver->getNativeType()                                                      
     #11 vendor/rector/rector/rules/TypeDeclaration/NodeAnalyzer/NeverFuncCallAnalyzer.php(29):                     
     Rector\TypeDeclaration\NodeAnalyzer\NeverFuncCallAnalyzer->isWithNeverTypeExpr()                               
     #12 vendor/rector/rector/rules/TypeDeclaration/NodeManipulator/AddNeverReturnType.php(106):                    
     Rector\TypeDeclaration\NodeAnalyzer\NeverFuncCallAnalyzer->hasNeverFuncCall()                                  
     #13 vendor/rector/rector/rules/TypeDeclaration/NodeManipulator/AddNeverReturnType.php(78):                     
     Rector\TypeDeclaration\NodeManipulator\AddNeverReturnType->hasNeverNodesOrNeverFuncCalls()                     
     #14 vendor/rector/rector/rules/TypeDeclaration/NodeManipulator/AddNeverReturnType.php(59):                     
     Rector\TypeDeclaration\NodeManipulator\AddNeverReturnType->shouldSkip()                                        
     #15 vendor/rector/rector/rules/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector.php(73):               
     Rector\TypeDeclaration\NodeManipulator\AddNeverReturnType->add()                                               
     #16 vendor/rector/rector/src/Rector/AbstractRector.php(112):                                                   
     Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector->refactor()                                    
     #17 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(173):                         
     Rector\Rector\AbstractRector->enterNode()                                                                      
     #18 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(90):                          
     PhpParser\NodeTraverser->traverseArray()                                                                       
     #19 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(200):                         
     PhpParser\NodeTraverser->traverseNode()                                                                        
     #20 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(90):                          
     PhpParser\NodeTraverser->traverseArray()                                                                       
     #21 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(200):                         
     PhpParser\NodeTraverser->traverseNode()                                                                        
     #22 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(71):                          
     PhpParser\NodeTraverser->traverseArray()                                                                       
     #23 vendor/rector/rector/src/PhpParser/NodeTraverser/RectorNodeTraverser.php(49):                              
     PhpParser\NodeTraverser->traverse()                                                                            
     #24 vendor/rector/rector/src/Application/FileProcessor.php(95):                                                
     Rector\PhpParser\NodeTraverser\RectorNodeTraverser->traverse()                                                 
     #25 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(174):                                    
     Rector\Application\FileProcessor->processFile()                                                                
     #26 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(151):                                    
     Rector\Application\ApplicationFileProcessor->processFile()                                                     
     #27 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(128):                                    
     Rector\Application\ApplicationFileProcessor->processFiles()                                                    
     #28 vendor/rector/rector/src/Console/Command/ProcessCommand.php(157):                                          
     Rector\Application\ApplicationFileProcessor->run()                                                             
     #29 vendor/rector/rector/vendor/symfony/console/Command/Command.php(285):                                      
     Rector\Console\Command\ProcessCommand->execute()                                                               
     #30 vendor/rector/rector/vendor/symfony/console/Application.php(900):                                          
     RectorPrefix202501\Symfony\Component\Console\Command\Command->run()                                            
     #31 vendor/rector/rector/vendor/symfony/console/Application.php(279):                                          
     RectorPrefix202501\Symfony\Component\Console\Application->doRunCommand()                                       
     #32 vendor/rector/rector/src/Console/ConsoleApplication.php(53):                                               
     RectorPrefix202501\Symfony\Component\Console\Application->doRun()                                              
     #33 vendor/rector/rector/vendor/symfony/console/Application.php(162):                                          
     Rector\Console\ConsoleApplication->doRun()                                                                     
     #34 vendor/rector/rector/bin/rector.php(130): RectorPrefix202501\Symfony\Component\Console\Application->run()  
     #35 vendor/rector/rector/bin/rector(5): require_once('...')                                                    
     #36 vendor/bin/rector(119): include('...')                                                                     
     #37 {main}". On line: 928  

PHP File

<?php

namespace App\Infrastructure\Validators\Opn;

use App\Domain\Opn\OpnResponsavelOperador;
use App\Infrastructure\Application\Util\Validator\ValidatorInterface;

class IsResponsavelOperadorValidator implements ValidatorInterface
{
    private $value;
    public string $message = 'deve ser um array.';
    private array $rules;

    public function __construct($value)
    {
        $this->value = $value;

        $this->rules = [
            'chave' => function ($value) {
                return is_string($value) ? true : 'deve ser uma string';
            },
            'valor' => function ($value) {
                return is_string($value) || is_int($value) ? true : 'deve ser um inteiro ou string';
            },
            'acao' => function ($value) {
                $validOptions = ['CRIADOR', 'EDITOR', 'RESPONSAVEL'];
                return in_array(
                    $value,
                    $validOptions,
                true) ? true
                : 'deve ser uma string com opções: CRIADOR, EDITOR ou RESPONSAVEL';
            },
            'operador' => function ($value) {
                return in_array(
                    $value,
                    OpnResponsavelOperador::OPERADORES_PERMITIDOS,
                    true)
                    ? true
                : 'deve ser uma string com opções: EQ, NEQ, EX ou NEX';
            }
        ];
    }

    public function isValid(): bool
    {
        if (!is_array($this->value)) {
            return $this->invalidate('deve ser um array.');
        }

        foreach ($this->value as $operador) {
            foreach ($this->rules as $key => $validation) {
                if (!array_key_exists($key, $operador)) {
                    return $this->invalidate("Chave [{$key}] é obrigatória.");
                }

                $result = $validation($operador[$key]);
                if ($result !== true) {
                    return $this->invalidate("Chave [{$key}] {$result}.");
                }
            }
        }

        return true;
    }

    private function invalidate(string $message): bool
    {
        $this->message = $message;
        return false;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions