laravel / pint

Laravel Pint is an opinionated PHP code style fixer for minimalists.

Home Page:https://laravel.com/docs/pint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP Fatal error: Allowed memory size of 536870912 bytes exhausted

stebogit opened this issue · comments

  • Pint Version: 1.2.1
  • PHP Version: 8.0.25
  • Running inside the latest Homestead

Description:

Running pint on my Laravel 8 project I get this error after most files (a total of less than 400 get checked by pint) have been fixed/checked:

.....PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 67108872 bytes) in  on line 161314
Segmentation fault (core dumped)

Steps To Reproduce:

As suggested here I ran pint -vvv >output.txt 2>&1 and this is the output:

Box Requirements Checker
========================

> Using PHP 8.0.25
> PHP is using the following php.ini file:
  /etc/php/8.0/cli/php.ini

> Checking Box requirements:
  ✔ The application requires the version "^8.0" or greater.
  ✔ The application requires the extension "zlib".
  ✔ The application requires the extension "json".
  ✔ The application requires the extension "mbstring".
  ✔ The application requires the extension "tokenizer".
  ✔ The application requires the extension "xml".
  
                                                                                                                                                                                                                                                                                                                                           
 [OK] Your system is ready to run the application.                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                                           


  .......................................................................................................................................................................................................................................................................................................................................
  ................................PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 67108872 bytes) in  on line 161314

Adding ini_set("memory_limit", -1); inside vendor/bin/pint it just hangs forever where it would otherwise breaks.

After some more digging excluding different folders, it turns out the script passes if I exclude one specific tests folder ("exclude": ["tests/Feature/Interfaces"],) - which only includes 5 files. The odd part is that if I run pint on any single file inside that folder (e.g. pint tests/Feature/Interfaces/CrestonApiTest.php) it works just fine. If I however run it on the folder (e.g. pint tests/Feature/Interfaces) it does break with the same memory error.

As I was trying to identify the exact file breaking, I noticed also that if I - instead of excluding the entire folder - instead exclude all the files inside that same folder individually ("notPath": ["tests/Feature/Interfaces/...", "..."]), it breaks as if the files were not in fact excluded.

Do you have any suggestions on how I can further debug this, like outputting additional logs so I can figure out why and exactly where it breaks?

My pint.json:

{
  "preset": "laravel",
  "rules": {
    "binary_operator_spaces": {
      "default": "single_space",
      "operators": {
        "=>": "align_single_space_minimal",
        "|": "no_space"
      }
    },
    "function_declaration": {
      "closure_function_spacing": "none"
    },
    "cast_spaces": {
      "space": "none"
    },
    "blank_line_before_statement": {
      "statements": [
        "try",
        "declare"
      ]
    },
    "not_operator_with_space": false,
    "not_operator_with_successor_space": false
  }
}

Hi @stebogit, thanks for sharing. Can you maybe share the full folder where it breaks? Then we can try to recreate this ourselves.

I am sorry, but this is something we cannot really investigate ourselves, as it is very likely to be related to the underlying dependency Pint uses: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.

I would advise you to try to set up PHP-CS-Fixer in your project, using Laravel's coding style, and see if you can reproduce the issue. If yes, you are free to report the issue on the PHP-CS-Fixer, or ideally, try to identify and pull request a solution for PHP-CS-Fixer directly.