Titel wird nicht unterstützt ...
PHP:
<?php
declare(strict_types=1);
namespace
DevCommunityDE\CodeFormatter\CodeFormatter
;
/**
* Class PHPCSFixerCodeFormatter
*
* @package DevCommunityDE\CodeFormatter\CodeFormatter
*/
final class
PHPCSFixerCodeFormatter
extends CodeFormatter
{
/**
* @var array
*/
protected static
$supported_languages =
[
'php'
];
/**
* @override
*
* @param string $file
* @return void
*/
public function exec(string $file)
{
parent::exec($file);
// there is a bug with "<?php" and newlines
// somehow the first newline after <?php gets removed
$content = file_get_contents($file);$content = preg_replace('/(^|=php\])<\?php\s*(.*?)/mi', "$1<?php\n$2", $content);
file_put_contents($file, $content);
}
/**
* Executes php-cs-fixer
*
* A configuration-file can be automatically loaded using a ".php_cs" file,
* but for simple formatting the @Symfony and @PRS2 rules are sufficient.
*
* @param string $file
* @return string
*/
public function
getShellCommand(string $file): string
{
$file_arg = escapeshellarg($file);
return "php-cs-fixer fix {$file_arg} --rules=@Symfony,@PSR2 --show-progress=none";
}
}