Skip to content

Commit

Permalink
Fix cs build (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Jul 26, 2024
1 parent 2d821c0 commit 308e66b
Show file tree
Hide file tree
Showing 41 changed files with 80 additions and 78 deletions.
2 changes: 2 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$rules = [
// Default
Expand Down Expand Up @@ -41,6 +42,7 @@

$config = new Config();
$config
->setParallelConfig(ParallelConfigFactory::detect())
->setFinder($finder)
->setRiskyAllowed(true)
->setRules($rules)
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function has(string $file): bool
public function get(string $file): string
{
if (!$this->has($file)) {
throw new \InvalidArgumentException(sprintf('The file "%s" is not cached', $file));
throw new \InvalidArgumentException(\sprintf('The file "%s" is not cached', $file));
}

return $this->hashes[$file];
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/CacheEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function fromJson(string $json): Cache
try {
$data = json_decode($json, true, flags: \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(\sprintf(
'Value needs to be a valid JSON string, got "%s", error: "%s".',
$json,
$e->getMessage()
Expand Down
4 changes: 2 additions & 2 deletions src/Cache/Manager/FileCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __destruct()
*/
public function __sleep(): array
{
throw new \BadMethodCallException(sprintf('Cannot serialize %s.', self::class));
throw new \BadMethodCallException(\sprintf('Cannot serialize %s.', self::class));
}

/**
Expand All @@ -62,7 +62,7 @@ public function __sleep(): array
*/
public function __wakeup(): void
{
throw new \BadMethodCallException(sprintf('Cannot unserialize %s.', self::class));
throw new \BadMethodCallException(\sprintf('Cannot unserialize %s.', self::class));
}

public function needFixing(string $file, string $fileContent): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private function getPackageVersion(string $package): string
return $version;
}

return sprintf('%s@%s', $version, substr($reference, 0, 7));
return \sprintf('%s@%s', $version, substr($reference, 0, 7));
}

return 'UNKNOWN';
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/TwigCsFixerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$config = $this->resolveConfig($input, $output);
$report = $this->runLinter($config, $input, $output);
} catch (\Throwable $exception) {
$output->writeln(sprintf('<error>Error: %s</error>', $exception->getMessage()));
$output->writeln(\sprintf('<error>Error: %s</error>', $exception->getMessage()));

return self::INVALID;
}
Expand All @@ -119,7 +119,7 @@ private function resolveConfig(InputInterface $input, OutputInterface $output):

$cacheFile = $config->getCacheFile();
if (null !== $cacheFile && is_file($cacheFile)) {
$output->writeln(sprintf('Using cache file "%s".', $cacheFile), OutputInterface::VERBOSITY_DEBUG);
$output->writeln(\sprintf('Using cache file "%s".', $cacheFile), OutputInterface::VERBOSITY_DEBUG);
}

return $config;
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/CannotResolveConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ private function __construct(string $message, int $code = 0, ?\Throwable $previo

public static function fileNotFound(string $path): self
{
return new self(sprintf('Cannot find the config file "%s".', $path));
return new self(\sprintf('Cannot find the config file "%s".', $path));
}

public static function fileMustReturnConfig(string $path): self
{
return new self(sprintf('The config file "%s" must return a "%s" object.', $path, Config::class));
return new self(\sprintf('The config file "%s" must return a "%s" object.', $path, Config::class));
}
}
6 changes: 3 additions & 3 deletions src/Exception/CannotTokenizeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ private function __construct(string $message, int $code = 0, ?\Throwable $previo

public static function unclosedBracket(string $character, int $line): self
{
return new self(sprintf('Unclosed "%s" at line %s.', $character, $line));
return new self(\sprintf('Unclosed "%s" at line %s.', $character, $line));
}

public static function unclosedComment(int $line): self
{
return new self(sprintf('Unclosed comment at line %s.', $line));
return new self(\sprintf('Unclosed comment at line %s.', $line));
}

public static function unexpectedCharacter(string $character, int $line): self
{
return new self(sprintf('Unexpected character "%s" at line %s.', $character, $line));
return new self(\sprintf('Unexpected character "%s" at line %s.', $character, $line));
}

public static function unknownError(): self
Expand Down
8 changes: 4 additions & 4 deletions src/Exception/CannotWriteCacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ private function __construct(string $message, int $code = 0, ?\Throwable $previo
public static function jsonException(\JsonException $exception): self
{
return new self(
sprintf('Cannot encode cache to JSON, error: "%s".', $exception->getMessage()),
\sprintf('Cannot encode cache to JSON, error: "%s".', $exception->getMessage()),
$exception->getCode(),
$exception
);
}

public static function locationIsDirectory(string $path): self
{
return new self(sprintf('Cannot write cache file "%s" as the location exists as directory.', $path));
return new self(\sprintf('Cannot write cache file "%s" as the location exists as directory.', $path));
}

public static function locationIsNotWritable(string $path): self
{
return new self(sprintf('Cannot write to file "%s" as it is not writable.', $path));
return new self(\sprintf('Cannot write to file "%s" as it is not writable.', $path));
}

public static function missingDirectory(string $path): self
{
return new self(sprintf('Directory of cache file "%s" does not exists.', $path));
return new self(\sprintf('Directory of cache file "%s" does not exists.', $path));
}
}
8 changes: 4 additions & 4 deletions src/Report/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function addViolation(Violation $violation): self
$filename = $violation->getFilename();
if (!isset($this->violationsByFile[$filename])) {
throw new \InvalidArgumentException(
sprintf('The file "%s" is not handled by this report.', $filename)
\sprintf('The file "%s" is not handled by this report.', $filename)
);
}

Expand Down Expand Up @@ -84,7 +84,7 @@ public function getFileViolations(string $filename, ?string $level = null): arra
{
if (!isset($this->violationsByFile[$filename])) {
throw new \InvalidArgumentException(
sprintf('The file "%s" is not handled by this report.', $filename)
\sprintf('The file "%s" is not handled by this report.', $filename)
);
}

Expand Down Expand Up @@ -131,7 +131,7 @@ public function getRealPath(string $filename): string
{
if (!isset($this->realPaths[$filename])) {
throw new \InvalidArgumentException(
sprintf('The file "%s" is not handled by this report.', $filename)
\sprintf('The file "%s" is not handled by this report.', $filename)
);
}

Expand All @@ -147,7 +147,7 @@ public function addFixedFile(string $filename): self
{
if (!isset($this->violationsByFile[$filename])) {
throw new \InvalidArgumentException(
sprintf('The file "%s" is not handled by this report.', $filename)
\sprintf('The file "%s" is not handled by this report.', $filename)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Report/Reporter/CheckstyleReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function display(
}

$realPath = $report->getRealPath($file);
$text .= sprintf(' <file name="%s">', $this->xmlEncode($realPath)).\PHP_EOL;
$text .= \sprintf(' <file name="%s">', $this->xmlEncode($realPath)).\PHP_EOL;
foreach ($fileViolations as $violation) {
$line = (string) $violation->getLine();
$linePosition = (string) $violation->getLinePosition();
Expand Down
8 changes: 4 additions & 4 deletions src/Report/Reporter/JUnitReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function display(

$text = '<?xml version="1.0" encoding="UTF-8"?>'.\PHP_EOL;
$text .= '<testsuites>'.\PHP_EOL;
$text .= ' '.sprintf(
$text .= ' '.\sprintf(
'<testsuite name="Twig CS Fixer" tests="%d" failures="%d">',
max($count, 1),
$count
Expand All @@ -37,7 +37,7 @@ public function display(
if ($count > 0) {
foreach ($violations as $violation) {
$text .= $this->createTestCase(
sprintf('%s:%s', $report->getRealPath($violation->getFilename()), $violation->getLine() ?? 0),
\sprintf('%s:%s', $report->getRealPath($violation->getFilename()), $violation->getLine() ?? 0),
strtolower(Violation::getLevelAsString($violation->getLevel())),
$violation->getDebugMessage($debug)
);
Expand All @@ -54,11 +54,11 @@ public function display(

private function createTestCase(string $name, string $type = '', ?string $message = null): string
{
$result = ' '.sprintf('<testcase name="%s">', $this->xmlEncode($name)).\PHP_EOL;
$result = ' '.\sprintf('<testcase name="%s">', $this->xmlEncode($name)).\PHP_EOL;

if (null !== $message) {
$result .= ' '
.sprintf('<failure type="%s" message="%s" />', $this->xmlEncode($type), $this->xmlEncode($message))
.\sprintf('<failure type="%s" message="%s" />', $this->xmlEncode($type), $this->xmlEncode($message))
.\PHP_EOL;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Report/Reporter/TextReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function display(
foreach ($report->getFiles() as $file) {
$fileViolations = $report->getFileViolations($file, $level);
if (\count($fileViolations) > 0) {
$io->text(sprintf('<fg=red>KO</fg=red> %s', $file));
$io->text(\sprintf('<fg=red>KO</fg=red> %s', $file));
}

$content = @file_get_contents($file);
Expand All @@ -63,7 +63,7 @@ public function display(
} else {
$context = $this->getContext($lines, $line);
foreach ($context as $no => $code) {
$formattedText[] = sprintf(
$formattedText[] = \sprintf(
self::ERROR_LINE_FORMAT,
$no,
wordwrap($code, self::ERROR_LINE_WIDTH, \PHP_EOL)
Expand All @@ -81,7 +81,7 @@ public function display(

$messageLevel = Violation::getLevelAsString($violation->getLevel());
$rows[] = [
new TableCell(sprintf('<comment>%s</comment>', $messageLevel)),
new TableCell(\sprintf('<comment>%s</comment>', $messageLevel)),
implode(\PHP_EOL, $formattedText),
];
}
Expand All @@ -91,7 +91,7 @@ public function display(
}
}

$summaryString = sprintf(
$summaryString = \sprintf(
'Files linted: %d, notices: %d, warnings: %d, errors: %d',
$report->getTotalFiles(),
$report->getTotalNotices(),
Expand Down Expand Up @@ -133,8 +133,8 @@ private function getContext(array $templatesLines, int $line): array

private function formatErrorMessage(Violation $message, bool $debug): string
{
return sprintf(
sprintf('<fg=red>%s</fg=red>', self::ERROR_LINE_FORMAT),
return \sprintf(
\sprintf('<fg=red>%s</fg=red>', self::ERROR_LINE_FORMAT),
self::ERROR_CURSOR_CHAR,
wordwrap($message->getDebugMessage($debug), self::ERROR_LINE_WIDTH, \PHP_EOL)
);
Expand Down
2 changes: 1 addition & 1 deletion src/Report/ReporterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getReporter(string $format = TextReporter::NAME): ReporterInterf
JUnitReporter::NAME => new JUnitReporter(),
GithubReporter::NAME => new GithubReporter(),
default => throw new \InvalidArgumentException(
sprintf('No reporter supports the format "%s".', $format)
\sprintf('No reporter supports the format "%s".', $format)
),
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/Report/Violation.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function getLevelAsString(int $level): string
self::LEVEL_ERROR => Report::MESSAGE_TYPE_ERROR,
self::LEVEL_FATAL => Report::MESSAGE_TYPE_FATAL,
default => throw new \InvalidArgumentException(
sprintf('Level "%s" is not supported.', $level)
\sprintf('Level "%s" is not supported.', $level)
),
};
}
Expand All @@ -49,7 +49,7 @@ public static function getLevelAsInt(string $level): int
Report::MESSAGE_TYPE_ERROR => self::LEVEL_ERROR,
Report::MESSAGE_TYPE_FATAL => self::LEVEL_FATAL,
default => throw new \InvalidArgumentException(
sprintf('Level "%s" is not supported.', $level)
\sprintf('Level "%s" is not supported.', $level)
),
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/Report/ViolationId.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public static function fromString(string $string, ?int $line = null): self

public function toString(): string
{
$name = rtrim(sprintf(
$name = rtrim(\sprintf(
'%s.%s',
$this->ruleIdentifier ?? '',
$this->messageIdentifier ?? '',
), '.');

return rtrim(sprintf(
return rtrim(\sprintf(
'%s:%s:%s',
$name,
$this->line ?? '',
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/AbstractSpacingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private function checkSpaceAfter(int $tokenIndex, Tokens $tokens, int $expected)
}

$fixer = $this->addFixableError(
sprintf('Expecting %d whitespace after "%s"; found %s.', $expected, $token->getValue(), $found),
\sprintf('Expecting %d whitespace after "%s"; found %s.', $expected, $token->getValue(), $found),
$token,
'After'
);
Expand Down Expand Up @@ -109,7 +109,7 @@ private function checkSpaceBefore(int $tokenIndex, Tokens $tokens, int $expected
}

$fixer = $this->addFixableError(
sprintf('Expecting %d whitespace before "%s"; found %s.', $expected, $token->getValue(), $found),
\sprintf('Expecting %d whitespace before "%s"; found %s.', $expected, $token->getValue(), $found),
$token,
'Before'
);
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/File/DirectoryNameRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function process(int $tokenIndex, Tokens $tokens): void

if ($expected !== $directory) {
$this->addFileError(
sprintf('The directory name must use %s; expected %s.', $this->case, $prefix.$expected),
\sprintf('The directory name must use %s; expected %s.', $this->case, $prefix.$expected),
$token,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/File/FileExtensionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function process(int $tokenIndex, Tokens $tokens): void

if (\count($fileParts) < 2) {
$this->addFileError(
sprintf('The file must use two extensions; found ".%s".', $fileExtension),
\sprintf('The file must use two extensions; found ".%s".', $fileExtension),
$token,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/File/FileNameRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function process(int $tokenIndex, Tokens $tokens): void

if ($expected !== $fileName) {
$this->addFileError(
sprintf('The file name must use %s; expected %s.', $this->case, $prefix.$expected),
\sprintf('The file name must use %s; expected %s.', $this->case, $prefix.$expected),
$token,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Function/IncludeFunctionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function process(int $tokenIndex, Tokens $tokens): void
$endInclude = ', true'.$endInclude;
}
if ($ignoreMissing || $withoutContext) {
$endInclude = sprintf(', %s', $withoutContext ? 'false' : 'true').$endInclude;
$endInclude = \sprintf(', %s', $withoutContext ? 'false' : 'true').$endInclude;

if (!$withVariable) {
$endInclude = ', []'.$endInclude;
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Node/ForbiddenBlockRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function enterNode(Node $node, Environment $env): Node
}

$this->addError(
sprintf('Block "%s" is not allowed.', $blockName),
\sprintf('Block "%s" is not allowed.', $blockName),
$node,
);

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Node/ForbiddenFilterRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function enterNode(Node $node, Environment $env): Node
}

$this->addError(
sprintf('Filter "%s" is not allowed.', $filterName),
\sprintf('Filter "%s" is not allowed.', $filterName),
$node,
);

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Node/ForbiddenFunctionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function enterNode(Node $node, Environment $env): Node
}

$this->addError(
sprintf('Function "%s" is not allowed.', $functionName),
\sprintf('Function "%s" is not allowed.', $functionName),
$node,
);

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Node/ValidConstantFunctionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function enterNode(Node $node, Environment $env): Node
);
} else {
$this->addError(
sprintf('Constant "%s" is undefined.', $constant),
\sprintf('Constant "%s" is undefined.', $constant),
$node,
'ConstantUndefined'
);
Expand Down
Loading

0 comments on commit 308e66b

Please sign in to comment.