PHP-CF-Fixer Integration Tests

asc

Mitglied
devCommunity-Experte
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";
    }
}
 
PHP:
<?php
        function test (  )
: int {
$value = 42;
            return $value; }?>

das ist ein test

HTML:
<i>
test</i>
 
Zuletzt bearbeitet:
Uff, da ist wohl noch mehr im Argen aktuell haha
Muss mir das Repo mal ohne Docker installieren und den PHP-Fixer isoliert testen.
 
Zurück
Oben Unten