According to Issue #1754 PHP_CodeSniffer does not test PHP files with no extensions, it isn't supported out of the box. You need to write your own filter and pass it as argument.
Here's a little example, which you should tweak for your own needs. In particular, this filter is designed to find shell scripts written in PHP. It opens all extensionless files (fast for small projects, can be troublesome for large ones) looking for a specific she-bang pattern (builtin MIME detection functions weren't working for my use case). You could, for instance, add a white list of locations to look for scripts.
phpcs.xml
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<arg name="filter" value="lib/CustomPHP_CodeSniffer/Filters/ExtensionlessPhpScriptsFilter.php"/>
<rule ref="PSR12"></rule>
<file>.</file>
</ruleset>
lib/CustomPHP_CodeSniffer/Filters/ExtensionlessPhpScriptsFilter.php
<?php
namespace Lib\CustomPHP_CodeSniffer\Filters;
use PHP_CodeSniffer\Filters\Filter;
use PHP_CodeSniffer\Util\Common;
class ExtensionlessPhpScriptsFilter extends Filter
{
private const SCRIPT_SHEBANG = '@^#!/opt/php[\d.]+/bin/php@';
public function accept(): bool
{
$filePath = Common::realpath($this->current());
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
if (is_dir($filePath) || $extension !== '') {
return parent::accept();
}
if ($this->shouldIgnorePath($filePath)) {
return false;
}
return $this->isPhpShellScript($filePath);
}
private function isPhpShellScript(string $filePath): bool
{
if (is_dir($filePath)) {
return false;
}
$fp = fopen($filePath, 'rb');
if (!$fp) {
throw new \RuntimeException("Could not open file to determine type: $filePath");
}
$line = fgets($fp, 80);
fclose($fp);
if ($line === false) {
throw new \RuntimeException("Could not read file to determine type: $filePath");
}
return (bool)preg_match(self::SCRIPT_SHEBANG, $line);
}
}
php vendor/bin/phpcs ./bin/console
command behaves like I gave it an empty folder as an argument instead of a file. Will open a ticket just in case. – Encephalomyelitis