rector icon indicating copy to clipboard operation
rector copied to clipboard

System error: \"PHPStan\\Type\\Constant\\ConstantIntegerType::__construct(): Argument #1 ($value) must be of type int, string given

Open frederic100 opened this issue 3 years ago • 8 comments

Probably it is php file size because I could not isolate the bug.

Here is the demo : https://getrector.org/demo/df558d72-0bf5-4ac6-9293-9c623232a7ea

I joined the asked report.

Inside the report I have seen: [37;41m PHPStan\Type\Constant\ConstantIntegerType->__construct('1_048_576') [39;49m report.txt

frederic100 avatar Jul 25 '22 15:07 frederic100

Hi @frederic100 ,

thanks for reporting. The code is too long to find out the broken lines. We'll need it narrowed down to ~10 lines first.

TomasVotruba avatar Jul 25 '22 17:07 TomasVotruba

I isolated the code that make the failure: https://getrector.org/demo/072a39db-35c8-4b24-928d-33ceeec81c4c Here is the code:

<?php

class PclZip
{
    var $zipname = '';
    var $zip_fd = 0;

  function PclZip($p_zipname)
  {
    $this->zipname = $p_zipname;
    $this->zip_fd = 0;
  }

  function privOptionDefaultThreshold(&$p_options)
  {
    $v_memory_limit = $v_memory_limit*1048576;
  }
}

but strange comportement:

  • if I put in comment the code inside the constructor it works: https://getrector.org/demo/97b4ac68-6485-4695-81f8-e9e0e8292dee
//    $this->zipname = $p_zipname;
//    $this->zip_fd = 0;
  • if I change the big balue value into a smaller one it works: https://getrector.org/demo/302cbad8-422f-43b8-ac8d-e3a343467e3c $v_memory_limit = $v_memory_limit*1024;

frederic100 avatar Jul 27 '22 09:07 frederic100

I fixed it using an operation 1024*1024 instead of 1048576 but isn't it a bug ?

frederic100 avatar Jul 27 '22 10:07 frederic100

$v_memory_limit variable seems never defined before used for multiply:

function privOptionDefaultThreshold(&$p_options)
  {
    $v_memory_limit = $v_memory_limit*1048576;
  }

samsonasik avatar Jul 27 '22 10:07 samsonasik

There was the previous code:

    // ----- Get 'memory_limit' configuration value
    $v_memory_limit = ini_get('memory_limit');
    $v_memory_limit = trim($v_memory_limit);
    $last = strtolower(substr($v_memory_limit, -1));
 
    if($last == 'g')
        //$v_memory_limit = $v_memory_limit*1024*1024*1024;
        $v_memory_limit = $v_memory_limit*1073741824;
    if($last == 'm')
        //$v_memory_limit = $v_memory_limit*1024*1024;
        $v_memory_limit = $v_memory_limit*1048576;
    if($last == 'k')
        $v_memory_limit = $v_memory_limit*1024;

frederic100 avatar Jul 27 '22 10:07 frederic100

But I didn't fix attributes failure

frederic100 avatar Jul 27 '22 10:07 frederic100

that's possibly phpstan bug since it error on phpstan side:

vendor/phpstan/phpstan/phpstan.phar/src/Reflection/InitializerExprTypeResolver.php on line 104

samsonasik avatar Jul 27 '22 10:07 samsonasik

Very strange... This is the way how I fixed(?) failure with attributes:

    $this->zipname = ''.$p_zipname;
    $this->zip_fd = 1-1;

frederic100 avatar Jul 27 '22 13:07 frederic100

I'm trying the latest Rector 0.14 and it seems passing well :+1: :slightly_smiling_face:

If this happens again, please create a reproducible repository on Github with failing CI job. That way we can isolate it, reproduce and fix :muscle:

TomasVotruba avatar Aug 17 '22 22:08 TomasVotruba

Hi @TomasVotruba,

I can reproduce the issue with the 0.14.2 version with this file:

<?php

namespace App\SampleRector;

class LongNumberHolder
{
    public const MY_LONG_NUMBER = 1000000;
}

In the version 0.14.0 it was ok, however. If I set the value with a value with 6 numbers, it is ok. I believe there might be some issue with the rule AddLiteralSeparatorToNumberRector, that transforms the value into a decimal value (1_234_567).

If I exclude the rule AddLiteralSeparatorToNumberRector in the config file, everything is ok in the 0.14.2 version.

hcerveragarc avatar Sep 05 '22 15:09 hcerveragarc