Skip to content

Commit

Permalink
Apply php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
scheb committed Nov 10, 2024
1 parent 2b872fd commit fa16a12
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/analyzer/Cli/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private function doExecute(): void
/** @var string $configFile */
$configFile = $this->input->getOption('config') ?? getcwd().DIRECTORY_SEPARATOR.'tombstone.yml';
if (!file_exists($configFile)) {
throw new \InvalidArgumentException(sprintf('Could not find configuration file %s', $configFile));
throw new \InvalidArgumentException(\sprintf('Could not find configuration file %s', $configFile));
}

$this->output->debug('Load config from '.$configFile);
Expand Down Expand Up @@ -117,7 +117,7 @@ private function createLogCollector(array $config, VampireIndex $vampireIndex):

$reflectionClass = new \ReflectionClass($config['logs']['custom']['class']);
if (!$reflectionClass->implementsInterface(LogProviderInterface::class)) {
throw new \Exception(sprintf('Class %s must implement %s', $config['logs']['custom']['class'], LogProviderInterface::class));
throw new \Exception(\sprintf('Class %s must implement %s', $config['logs']['custom']['class'], LogProviderInterface::class));
}

/** @var LogProviderInterface $logReader */
Expand Down
4 changes: 2 additions & 2 deletions src/analyzer/Cli/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function createProgressBar(int $width): ProgressBar

public function error(string $message, ?\Throwable $exception = null): void
{
$this->output->writeln(sprintf('<error>%s</error>', $message));
$this->output->writeln(\sprintf('<error>%s</error>', $message));
if (null !== $exception && $this->output->isDebug()) {
$this->output->writeln(sprintf(
$this->output->writeln(\sprintf(
'%s: %s at %s line %s',
\get_class($exception),
$exception->getMessage(),
Expand Down
4 changes: 2 additions & 2 deletions src/analyzer/Log/AnalyzerLogFileReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function readLogFile(string $file): \Traversable
{
$handle = @fopen($file, 'r');
if (false === $handle) {
throw new AnalyzerLogProviderException(sprintf('Could not read log file %s', $file));
throw new AnalyzerLogProviderException(\sprintf('Could not read log file %s', $file));
}

$lineNumber = 0;
Expand All @@ -44,7 +44,7 @@ public function readLogFile(string $file): \Traversable
try {
yield AnalyzerLogFormat::logToVampire($line, $this->rootDir);
} catch (AnalyzerLogFormatException $e) {
$this->output->error(sprintf('Ignoring invalid log data in "%s" on line %s', $file, $lineNumber), $e);
$this->output->error(\sprintf('Ignoring invalid log data in "%s" on line %s', $file, $lineNumber), $e);
}
}
fclose($handle);
Expand Down
4 changes: 2 additions & 2 deletions src/analyzer/Report/Checkstyle/CheckstyleReportGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function createError(\DOMDocument $dom, Tombstone $tombstone): \DOMEleme

private function getMessage(Tombstone $tombstone): string
{
return sprintf('Tombstone "%s" was called', (string) $tombstone).$this->getCalledBy($tombstone);
return \sprintf('Tombstone "%s" was called', (string) $tombstone).$this->getCalledBy($tombstone);
}

/**
Expand All @@ -82,7 +82,7 @@ private function getCalledBy(Tombstone $tombstone): string
}

$invoker = array_shift($vampires)->getInvoker();
$calledBy = sprintf(' by "%s"', null !== $invoker ? $invoker : 'global scope');
$calledBy = \sprintf(' by "%s"', null !== $invoker ? $invoker : 'global scope');

$numAdditionalVampires = $numVampires - 1;
if ($numAdditionalVampires > 0) {
Expand Down
16 changes: 8 additions & 8 deletions src/analyzer/Report/Console/ConsoleReportGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function generate(AnalyzerResult $result): void
$numDeleted = $result->getDeletedCount();

$this->newLine();
$this->output->writeln(sprintf('Vampires/Tombstones: %d/%d', $numUndead, $numUndead + $numDead));
$this->output->writeln(sprintf('Deleted tombstones: %d', $numDeleted));
$this->output->writeln(\sprintf('Vampires/Tombstones: %d/%d', $numUndead, $numUndead + $numDead));
$this->output->writeln(\sprintf('Deleted tombstones: %d', $numDeleted));

foreach ($result->getFileResults() as $fileResult) {
$this->newLine();
Expand Down Expand Up @@ -81,7 +81,7 @@ private function displayVampires(array $result): void
private function printCalledBy(array $invokers): void
{
foreach ($invokers as $invoker) {
$this->output->writeln(sprintf(' was called by <error>%s</error>', $invoker ?: 'global scope'));
$this->output->writeln(\sprintf(' was called by <error>%s</error>', $invoker ?: 'global scope'));
}
}

Expand All @@ -97,21 +97,21 @@ private function displayTombstones(array $result): void
if (null !== $date) {
$age = TimePeriodFormatter::formatAge($date);
if (null !== $age) {
$this->output->writeln(sprintf(' was not called for %s', $age));
$this->output->writeln(\sprintf(' was not called for %s', $age));
} else {
$this->output->writeln(sprintf(' was not called since %s', $date));
$this->output->writeln(\sprintf(' was not called since %s', $date));
}
}
}
}

private function printTombstone(Tombstone $tombstone, string $prefix): void
{
$this->output->writeln(sprintf(' [%s] <info>%s</info>', $prefix, (string) $tombstone));
$this->output->writeln(sprintf(' in <comment>line %s</comment>', $tombstone->getLine()));
$this->output->writeln(\sprintf(' [%s] <info>%s</info>', $prefix, (string) $tombstone));
$this->output->writeln(\sprintf(' in <comment>line %s</comment>', $tombstone->getLine()));
$method = $tombstone->getMethod();
if (null !== $method) {
$this->output->writeln(sprintf(' in method <comment>%s</comment>', $method));
$this->output->writeln(\sprintf(' in method <comment>%s</comment>', $method));
} else {
$this->output->writeln(' in global scope');
}
Expand Down
8 changes: 4 additions & 4 deletions src/analyzer/Report/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static function copyDirectoryFiles(string $templateDir, string $reportDir
self::ensureDirectoryCreated($reportDir);
$handle = @opendir($templateDir);
if (!$handle) {
throw new FileSystemException(sprintf('Could not read template files from %s', $templateDir));
throw new FileSystemException(\sprintf('Could not read template files from %s', $templateDir));
}

while ($file = readdir($handle)) {
Expand All @@ -30,7 +30,7 @@ public static function copyDirectoryFiles(string $templateDir, string $reportDir
}

if (!@copy($templateFile, $reportFile)) {
throw new FileSystemException(sprintf('Could not copy %s to %s', $templateFile, $reportFile));
throw new FileSystemException(\sprintf('Could not copy %s to %s', $templateFile, $reportFile));
}
}
closedir($handle);
Expand All @@ -40,10 +40,10 @@ public static function ensureDirectoryCreated(string $dir): void
{
if (!is_dir($dir)) {
if (!@mkdir($dir, 0777, true)) {
throw new FileSystemException(sprintf('Could not create directory %s', $dir));
throw new FileSystemException(\sprintf('Could not create directory %s', $dir));
}
} elseif (!is_writable($dir)) {
throw new FileSystemException(sprintf('Directory %s has to be writable', $dir));
throw new FileSystemException(\sprintf('Directory %s has to be writable', $dir));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/analyzer/Report/Html/Renderer/DashboardRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private function getTombstoneScope(Tombstone $tombstone): string
{
$method = $tombstone->getMethod();
if (null !== $method) {
return sprintf('method <samp>%s</samp>', htmlspecialchars($method));
return \sprintf('method <samp>%s</samp>', htmlspecialchars($method));
}

return 'global scope';
Expand All @@ -240,7 +240,7 @@ private function getTombstoneScope(Tombstone $tombstone): string
private function linkToTombstoneInCode(string $label, FilePathInterface $file, int $line): string
{
if ($file instanceof RelativeFilePath) {
return sprintf('<a href="./%s.html#%s">%s</a>', $file->getRelativePath(), $line, htmlspecialchars($label));
return \sprintf('<a href="./%s.html#%s">%s</a>', $file->getRelativePath(), $line, htmlspecialchars($label));
}

return htmlspecialchars($label);
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/Report/Html/Renderer/PhpSyntaxHighlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function formatBracket(string $value): string

private static function formatValue(string $value, string $color): string
{
return sprintf('<span class="%s">%s</span>', $color, $value);
return \sprintf('<span class="%s">%s</span>', $color, $value);
}

private static function getColorForToken(int $token): string
Expand Down
8 changes: 4 additions & 4 deletions src/analyzer/Stock/TombstoneExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function extractTombstones(string $filePath): array
$this->extractedTombstones = [];
$this->currentFilePath = $filePath;
if (!is_readable($filePath)) {
throw new TombstoneExtractorException(sprintf('File "%s" is not readable.', $filePath));
throw new TombstoneExtractorException(\sprintf('File "%s" is not readable.', $filePath));
}

$this->parseSourceCode($filePath);
Expand All @@ -68,17 +68,17 @@ private function parseSourceCode(string $absoluteFilePath): void
$content = file_get_contents($absoluteFilePath);
$stmts = $this->parser->parse($content);
if (null === $stmts) {
throw new TombstoneExtractorException(sprintf('PHP code in "%s" could not be parsed.', $absoluteFilePath));
throw new TombstoneExtractorException(\sprintf('PHP code in "%s" could not be parsed.', $absoluteFilePath));
}

// Calls back to onTombstoneFound()
$this->traverser->traverse($stmts);
} catch (TombstoneExtractorException $e) {
throw $e;
} catch (Error $e) {
throw new TombstoneExtractorException(sprintf('PHP code in "%s" could not be parsed.', $absoluteFilePath), 0, $e);
throw new TombstoneExtractorException(\sprintf('PHP code in "%s" could not be parsed.', $absoluteFilePath), 0, $e);
} catch (\Throwable $e) {
throw new TombstoneExtractorException(sprintf('Exception while parsing "%s".', $absoluteFilePath), 0, $e);
throw new TombstoneExtractorException(\sprintf('Exception while parsing "%s".', $absoluteFilePath), 0, $e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/Stock/TombstoneNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function getNamespacedName($node): string
/** @psalm-suppress DocblockTypeContradiction */
if (!isset($node->namespacedName)) {
$nodeName = isset($node->name) ? (string) $node->name : '<anonymous>';
throw new \RuntimeException(sprintf('Node %s of type %s did not provide attribute namespacedName', $nodeName, \get_class($node)));
throw new \RuntimeException(\sprintf('Node %s of type %s did not provide attribute namespacedName', $nodeName, \get_class($node)));
}

return (string) $node->namespacedName;
Expand Down
4 changes: 2 additions & 2 deletions src/core/Format/AnalyzerLogFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class AnalyzerLogFormatException extends \Exception
public static function createIncompatibleDataException(int $currentVersion, ?int $version): self
{
return new self(
sprintf('Log data provided in incompatible version, current version %s, provided version: %s', $currentVersion, $version ?? 'unknown'),
\sprintf('Log data provided in incompatible version, current version %s, provided version: %s', $currentVersion, $version ?? 'unknown'),
self::INCOMPATIBLE_VERSION
);
}

public static function createMissingDataException(array $missingData): self
{
return new self(
sprintf('Log data is missing fields: %s', implode(', ', $missingData)),
\sprintf('Log data is missing fields: %s', implode(', ', $missingData)),
self::MISSING_DATA
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Model/RootPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(string $rootPath)
}

if (!self::isPathAbsolute($rootPath)) {
throw new \InvalidArgumentException(sprintf('Root rootPath "%s" must be absolute.', $rootPath));
throw new \InvalidArgumentException(\sprintf('Root rootPath "%s" must be absolute.', $rootPath));
}

$rootPath = PathNormalizer::normalizeDirectorySeparator($rootPath);
Expand Down
2 changes: 1 addition & 1 deletion src/logger/Formatter/LineFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LineFormatter implements FormatterInterface
{
public function format(Vampire $vampire): string
{
$line = sprintf(
$line = \sprintf(
'%s - Vampire detected: %s, in file %s:%s',
$vampire->getInvocationDate(),
(string) $vampire->getTombstone(),
Expand Down
4 changes: 2 additions & 2 deletions src/logger/Graveyard/Graveyard.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function logTombstoneCall(array $arguments, array $trace, array $metadata
$handler->log($vampire);
}
} catch (\Throwable $e) {
$this->logger->error(sprintf('Exception while tracking a tombstone call: %s %s (%s)', \get_class($e), $e->getMessage(), $e->getCode()));
$this->logger->error(\sprintf('Exception while tracking a tombstone call: %s %s (%s)', \get_class($e), $e->getMessage(), $e->getCode()));
}
}

Expand All @@ -51,7 +51,7 @@ public function flush(): void
$handler->flush();
}
} catch (\Throwable $e) {
$this->logger->error(sprintf('Exception while flushing tombstones: %s %s (%s)', \get_class($e), $e->getMessage(), $e->getCode()));
$this->logger->error(\sprintf('Exception while flushing tombstones: %s %s (%s)', \get_class($e), $e->getMessage(), $e->getCode()));
}
}
}
2 changes: 1 addition & 1 deletion src/logger/Handler/AnalyzerLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function getLogFile(Vampire $vampire): string
$date = date('Ymd');
$hash = $vampire->getTombstone()->getHash();

return $this->logDir.'/'.sprintf(self::LOG_FILE_NAME, $hash, $date);
return $this->logDir.'/'.\sprintf(self::LOG_FILE_NAME, $hash, $date);
}

private function getLogStream(string $logFile): StreamHandler
Expand Down
4 changes: 2 additions & 2 deletions src/logger/Handler/StreamHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function log(Vampire $vampire): void
if (!\is_resource($this->stream)) {
$this->stream = null;
/** @psalm-suppress NullArgument */
throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: %s', $this->errorMessage, $this->url));
throw new \UnexpectedValueException(\sprintf('The stream or file "%s" could not be opened: %s', $this->errorMessage, $this->url));
}
}
if ($this->useLocking) {
Expand Down Expand Up @@ -145,7 +145,7 @@ private function createDir(): void
restore_error_handler();
if (false === $status && !is_dir($dir)) {
/** @psalm-suppress NullArgument */
throw new \UnexpectedValueException(sprintf('There is no existing directory at "%s" and its not buildable: %s', $dir, $this->errorMessage));
throw new \UnexpectedValueException(\sprintf('There is no existing directory at "%s" and its not buildable: %s', $dir, $this->errorMessage));
}
}
$this->dirCreated = true;
Expand Down
8 changes: 4 additions & 4 deletions tests/ComposerJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ public function packageDependenciesEqualRootDependencies(): void
continue;
}

$message = sprintf('Dependency "%s" from package "%s" is not defined in root composer.json', $dependency, $package);
$message = \sprintf('Dependency "%s" from package "%s" is not defined in root composer.json', $dependency, $package);
$this->assertArrayHasKey($dependency, $rootDependencies, $message);

$message = sprintf('Dependency "%s:%s" from package "%s" requires a different version in the root composer.json', $dependency, $version, $package);
$message = \sprintf('Dependency "%s:%s" from package "%s" requires a different version in the root composer.json', $dependency, $version, $package);
$this->assertEquals($version, $rootDependencies[$dependency], $message);

$usedDependencies[] = $dependency;
}
}

$unusedDependencies = array_diff(array_keys($rootDependencies), array_unique($usedDependencies));
$message = sprintf('Dependencies declared in root composer.json, which are not declared in any sub-package: %s', implode($unusedDependencies));
$message = \sprintf('Dependencies declared in root composer.json, which are not declared in any sub-package: %s', implode($unusedDependencies));
$this->assertCount(0, $unusedDependencies, $message);
}

Expand All @@ -47,7 +47,7 @@ public function rootReplacesSubPackages(): void
$rootReplaces = $this->getComposerReplaces(__DIR__.'/../composer.json');
foreach ($this->listSubPackages() as $package) {
$packageName = $this->getComposerPackageName(self::SRC_DIR.'/'.$package.'/composer.json');
$message = sprintf('Root composer.json must replace the sub-packages "%s"', $packageName);
$message = \sprintf('Root composer.json must replace the sub-packages "%s"', $packageName);
$this->assertArrayHasKey($packageName, $rootReplaces, $message);
}
}
Expand Down

0 comments on commit fa16a12

Please sign in to comment.