rector icon indicating copy to clipboard operation
rector copied to clipboard

System error: "Rector\NodeTypeResolver\NodeTypeResolver::getType(): Argument #1 ($node) must be of type PhpParser\Node, null given

Open petitj opened this issue 4 years ago • 7 comments

Bug Report

Subject Details
Rector version 0.13.10

Hi there. First, thanks for the great work put in this project!

While trying to run rector on an old project, i encoutered the following error:

System error: "Rector\NodeTypeResolver\NodeTypeResolver::getType(): Argument #1 ($node) must be of type PhpParser\Node, null given

Minimal PHP Code Causing Issue

You can reproduce the issue using the following link: https://getrector.org/demo/dabca986-73d1-4391-95eb-3650654bb966

Expected Behaviour

I'm just starting with rector but this doesn't seem like the appropriate behaviour.

petitj avatar Aug 15 '22 12:08 petitj

crypt() function require 2 args, while you only provide 1 arg, it already error when check on https://3v4l.org/hrdFU , you need to pass 2 args instead, see https://www.php.net/manual/en/function.crypt.php

samsonasik avatar Aug 15 '22 13:08 samsonasik

Ok, it seems got notice in php < 8, while it still run https://3v4l.org/GaksR

samsonasik avatar Aug 15 '22 13:08 samsonasik

Ok ! Since i'm using rector to update old code, i didn't think it would break on such error but warn instead or even fix the old code. I'm asking too much :D

Thanks for your insight !

petitj avatar Aug 15 '22 13:08 petitj

You're welcome, the optional notice happen since php 5.6 https://3v4l.org/GaksR#v5.6.1, so we may need to create new rule to fill default arg value on 2nd arg on crypt() function for it, eg: FillSecondArgCryptRector on php 5.6 rules set.

samsonasik avatar Aug 15 '22 14:08 samsonasik

That might be harder than that since the second parameter must be a generated salt. A rule replacing crypt() by password_hash() could be more appropriate but might break code because of algorithm changes.

petitj avatar Aug 15 '22 14:08 petitj

Ok, it seems the solution is to skip it instead for this

samsonasik avatar Aug 15 '22 16:08 samsonasik

Thanks again :)

petitj avatar Aug 15 '22 18:08 petitj