squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

Fatal error: Uncaught ValueError: Path cannot be empty in phar:///home/user/.local/bin/phpcs.phar/src/Reporter.php:3 #3768

Closed NoxInmortus closed 1 year ago

NoxInmortus commented 1 year ago

Hello,

I just fetch PHPCS and PHPBCF phar files with curl.

Just tried to run it :

(devbox) user@user-ow2:~/git/OW2/umdev-fd (improvements) $ phpcs.phar user-account-create.php 

Notice: tempnam(): file created in the system's temporary directory in phar:///home/user/.local/bin/phpcs.phar/src/Reporter.php on line 3

Fatal error: Uncaught ValueError: Path cannot be empty in phar:///home/user/.local/bin/phpcs.phar/src/Reporter.php:3
Stack trace:
#0 phar:///home/user/.local/bin/phpcs.phar/src/Reporter.php(3): file_put_contents('', '')
#1 phar:///home/user/.local/bin/phpcs.phar/src/Runner.php(3): PHP_CodeSniffer\Reporter->__construct(Object(PHP_CodeSniffer\Config))
#2 phar:///home/user/.local/bin/phpcs.phar/src/Runner.php(3): PHP_CodeSniffer\Runner->run()
#3 /home/user/.local/bin/phpcs.phar(6): PHP_CodeSniffer\Runner->runPHPCS()
#4 {main}
  thrown in phar:///home/user/.local/bin/phpcs.phar/src/Reporter.php on line 3

I did not found anything able to help me in wiki/issues. Any hint ?

jrfnl commented 1 year ago

@NoxInmortus I cannot reproduce the issue, but based on the error message, it sounds like your system temp directory (sys_temp_dir ini value) is misconfigured or unwrittable, resulting in tempnam() returning false.

gsherwood commented 1 year ago

Also cannot reproduce. Closing due to lack of feedback.

tosiara commented 1 year ago

very weird, but I also get the same error

in my case it worked in docker, but after some changes and rebuilding the image, I cannot run it anymore:

# ./vendor/bin/phpcs
PHP Notice:  tempnam(): file created in the system's temporary directory in /vendor/squizlabs/php_codesniffer/src/Reporter.php on line 159
PHP Fatal error:  Uncaught ValueError: Path cannot be empty in /vendor/squizlabs/php_codesniffer/src/Reporter.php:160
Stack trace:
#0 /vendor/squizlabs/php_codesniffer/src/Reporter.php(160): file_put_contents()
#1 /vendor/squizlabs/php_codesniffer/src/Runner.php(356): PHP_CodeSniffer\Reporter->__construct()
#2 /vendor/squizlabs/php_codesniffer/src/Runner.php(116): PHP_CodeSniffer\Runner->run()
#3 /vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#4 /vendor/bin/phpcs(117): include('...')
#5 {main}
  thrown in /vendor/squizlabs/php_codesniffer/src/Reporter.php on line 160
tosiara commented 1 year ago

The issue was in temp env variable exported from host: TMPDIR=/var/folders/v_/4d7tl7nj28q37zyztkwqw4dh0000gn/T/ After removing this var phpcs works again

jrfnl commented 1 year ago

@tosiara Thanks for adding that info. Hopefully it will help someone else running into this in the future.