mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-20 07:42:17 +02:00
N°8834 - Add compatibility with PHP 8.4 (#819)
* N°8834 - Add compatibility with PHP 8.4 * Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
@@ -48,7 +48,7 @@ class DebugCommand extends Command
|
||||
|
||||
private ?FileLinkFormatter $fileLinkFormatter;
|
||||
|
||||
public function __construct(Environment $twig, string $projectDir = null, array $bundlesMetadata = [], string $twigDefaultPath = null, FileLinkFormatter $fileLinkFormatter = null)
|
||||
public function __construct(Environment $twig, ?string $projectDir = null, array $bundlesMetadata = [], ?string $twigDefaultPath = null, ?FileLinkFormatter $fileLinkFormatter = null)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
@@ -68,7 +68,7 @@ class DebugCommand extends Command
|
||||
->setDefinition([
|
||||
new InputArgument('name', InputArgument::OPTIONAL, 'The template name'),
|
||||
new InputOption('filter', null, InputOption::VALUE_REQUIRED, 'Show details for all entries matching this filter'),
|
||||
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'text'),
|
||||
new InputOption('format', null, InputOption::VALUE_REQUIRED, \sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'text'),
|
||||
])
|
||||
->setHelp(<<<'EOF'
|
||||
The <info>%command.name%</info> command outputs a list of twig functions,
|
||||
@@ -101,13 +101,13 @@ EOF
|
||||
$filter = $input->getOption('filter');
|
||||
|
||||
if (null !== $name && [] === $this->getFilesystemLoaders()) {
|
||||
throw new InvalidArgumentException(sprintf('Argument "name" not supported, it requires the Twig loader "%s".', FilesystemLoader::class));
|
||||
throw new InvalidArgumentException(\sprintf('Argument "name" not supported, it requires the Twig loader "%s".', FilesystemLoader::class));
|
||||
}
|
||||
|
||||
match ($input->getOption('format')) {
|
||||
'text' => $name ? $this->displayPathsText($io, $name) : $this->displayGeneralText($io, $filter),
|
||||
'json' => $name ? $this->displayPathsJson($io, $name) : $this->displayGeneralJson($io, $filter),
|
||||
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
|
||||
default => throw new InvalidArgumentException(\sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
|
||||
};
|
||||
|
||||
return 0;
|
||||
@@ -132,7 +132,7 @@ EOF
|
||||
$io->section('Matched File');
|
||||
if ($file->valid()) {
|
||||
if ($fileLink = $this->getFileLink($file->key())) {
|
||||
$io->block($file->current(), 'OK', sprintf('fg=black;bg=green;href=%s', $fileLink), ' ', true);
|
||||
$io->block($file->current(), 'OK', \sprintf('fg=black;bg=green;href=%s', $fileLink), ' ', true);
|
||||
} else {
|
||||
$io->success($file->current());
|
||||
}
|
||||
@@ -142,9 +142,9 @@ EOF
|
||||
$io->section('Overridden Files');
|
||||
do {
|
||||
if ($fileLink = $this->getFileLink($file->key())) {
|
||||
$io->text(sprintf('* <href=%s>%s</>', $fileLink, $file->current()));
|
||||
$io->text(\sprintf('* <href=%s>%s</>', $fileLink, $file->current()));
|
||||
} else {
|
||||
$io->text(sprintf('* %s', $file->current()));
|
||||
$io->text(\sprintf('* %s', $file->current()));
|
||||
}
|
||||
$file->next();
|
||||
} while ($file->valid());
|
||||
@@ -169,7 +169,7 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
$this->error($io, sprintf('Template name "%s" not found', $name), $alternatives);
|
||||
$this->error($io, \sprintf('Template name "%s" not found', $name), $alternatives);
|
||||
}
|
||||
|
||||
$io->section('Configured Paths');
|
||||
@@ -182,7 +182,7 @@ EOF
|
||||
if (FilesystemLoader::MAIN_NAMESPACE === $namespace) {
|
||||
$message = 'No template paths configured for your application';
|
||||
} else {
|
||||
$message = sprintf('No template paths configured for "@%s" namespace', $namespace);
|
||||
$message = \sprintf('No template paths configured for "@%s" namespace', $namespace);
|
||||
foreach ($this->getFilesystemLoaders() as $loader) {
|
||||
$namespaces = $loader->getNamespaces();
|
||||
foreach ($this->findAlternatives($namespace, $namespaces) as $namespace) {
|
||||
@@ -210,14 +210,14 @@ EOF
|
||||
$data['overridden_files'] = $files;
|
||||
}
|
||||
} else {
|
||||
$data['matched_file'] = sprintf('Template name "%s" not found', $name);
|
||||
$data['matched_file'] = \sprintf('Template name "%s" not found', $name);
|
||||
}
|
||||
$data['loader_paths'] = $paths;
|
||||
|
||||
$io->writeln(json_encode($data));
|
||||
}
|
||||
|
||||
private function displayGeneralText(SymfonyStyle $io, string $filter = null): void
|
||||
private function displayGeneralText(SymfonyStyle $io, ?string $filter = null): void
|
||||
{
|
||||
$decorated = $io->isDecorated();
|
||||
$types = ['functions', 'filters', 'tests', 'globals'];
|
||||
@@ -279,7 +279,7 @@ EOF
|
||||
$io->writeln($decorated ? OutputFormatter::escape($data) : $data);
|
||||
}
|
||||
|
||||
private function getLoaderPaths(string $name = null): array
|
||||
private function getLoaderPaths(?string $name = null): array
|
||||
{
|
||||
$loaderPaths = [];
|
||||
foreach ($this->getFilesystemLoaders() as $loader) {
|
||||
@@ -375,7 +375,7 @@ EOF
|
||||
return '(unknown?)';
|
||||
}
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
return sprintf(' <error>%s</error>', $decorated ? OutputFormatter::escape($e->getMessage()) : $e->getMessage());
|
||||
return \sprintf(' <error>%s</error>', $decorated ? OutputFormatter::escape($e->getMessage()) : $e->getMessage());
|
||||
}
|
||||
|
||||
if ('globals' === $type) {
|
||||
@@ -385,7 +385,7 @@ EOF
|
||||
|
||||
$description = substr(@json_encode($meta), 0, 50);
|
||||
|
||||
return sprintf(' = %s', $decorated ? OutputFormatter::escape($description) : $description);
|
||||
return \sprintf(' = %s', $decorated ? OutputFormatter::escape($description) : $description);
|
||||
}
|
||||
|
||||
if ('functions' === $type) {
|
||||
@@ -432,14 +432,14 @@ EOF
|
||||
{
|
||||
$messages = [];
|
||||
foreach ($wrongBundles as $path => $alternatives) {
|
||||
$message = sprintf('Path "%s" not matching any bundle found', $path);
|
||||
$message = \sprintf('Path "%s" not matching any bundle found', $path);
|
||||
if ($alternatives) {
|
||||
if (1 === \count($alternatives)) {
|
||||
$message .= sprintf(", did you mean \"%s\"?\n", $alternatives[0]);
|
||||
$message .= \sprintf(", did you mean \"%s\"?\n", $alternatives[0]);
|
||||
} else {
|
||||
$message .= ", did you mean one of these:\n";
|
||||
foreach ($alternatives as $bundle) {
|
||||
$message .= sprintf(" - %s\n", $bundle);
|
||||
$message .= \sprintf(" - %s\n", $bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -492,7 +492,7 @@ EOF
|
||||
{
|
||||
if (isset($name[0]) && '@' === $name[0]) {
|
||||
if (false === ($pos = strpos($name, '/')) || $pos === \strlen($name) - 1) {
|
||||
throw new InvalidArgumentException(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name));
|
||||
throw new InvalidArgumentException(\sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name));
|
||||
}
|
||||
|
||||
$namespace = substr($name, 1, $pos - 1);
|
||||
@@ -561,7 +561,7 @@ EOF
|
||||
|
||||
private function isAbsolutePath(string $file): bool
|
||||
{
|
||||
return strspn($file, '/\\', 0, 1) || (\strlen($file) > 3 && ctype_alpha($file[0]) && ':' === $file[1] && strspn($file, '/\\', 2, 1)) || null !== parse_url($file, \PHP_URL_SCHEME);
|
||||
return strspn($file, '/\\', 0, 1) || (\strlen($file) > 3 && ctype_alpha($file[0]) && ':' === $file[1] && strspn($file, '/\\', 2, 1)) || parse_url($file, \PHP_URL_SCHEME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,7 +54,7 @@ class LintCommand extends Command
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())))
|
||||
->addOption('format', null, InputOption::VALUE_REQUIRED, \sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())))
|
||||
->addOption('show-deprecations', null, InputOption::VALUE_NONE, 'Show deprecations as errors')
|
||||
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
|
||||
->setHelp(<<<'EOF'
|
||||
@@ -151,7 +151,7 @@ EOF
|
||||
return Finder::create()->files()->in($filename)->name($this->namePatterns);
|
||||
}
|
||||
|
||||
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
|
||||
throw new RuntimeException(\sprintf('File or directory "%s" is not readable.', $filename));
|
||||
}
|
||||
|
||||
private function validate(string $template, string $file): array
|
||||
@@ -178,7 +178,7 @@ EOF
|
||||
'txt' => $this->displayTxt($output, $io, $files),
|
||||
'json' => $this->displayJson($output, $files),
|
||||
'github' => $this->displayTxt($output, $io, $files, true),
|
||||
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
|
||||
default => throw new InvalidArgumentException(\sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ EOF
|
||||
|
||||
foreach ($filesInfo as $info) {
|
||||
if ($info['valid'] && $output->isVerbose()) {
|
||||
$io->comment('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
|
||||
$io->comment('<info>OK</info>'.($info['file'] ? \sprintf(' in %s', $info['file']) : ''));
|
||||
} elseif (!$info['valid']) {
|
||||
++$errors;
|
||||
$this->renderException($io, $info['template'], $info['exception'], $info['file'], $githubReporter);
|
||||
@@ -197,9 +197,9 @@ EOF
|
||||
}
|
||||
|
||||
if (0 === $errors) {
|
||||
$io->success(sprintf('All %d Twig files contain valid syntax.', \count($filesInfo)));
|
||||
$io->success(\sprintf('All %d Twig files contain valid syntax.', \count($filesInfo)));
|
||||
} else {
|
||||
$io->warning(sprintf('%d Twig files have valid syntax and %d contain errors.', \count($filesInfo) - $errors, $errors));
|
||||
$io->warning(\sprintf('%d Twig files have valid syntax and %d contain errors.', \count($filesInfo) - $errors, $errors));
|
||||
}
|
||||
|
||||
return min($errors, 1);
|
||||
@@ -224,35 +224,35 @@ EOF
|
||||
return min($errors, 1);
|
||||
}
|
||||
|
||||
private function renderException(SymfonyStyle $output, string $template, Error $exception, string $file = null, GithubActionReporter $githubReporter = null): void
|
||||
private function renderException(SymfonyStyle $output, string $template, Error $exception, ?string $file = null, ?GithubActionReporter $githubReporter = null): void
|
||||
{
|
||||
$line = $exception->getTemplateLine();
|
||||
|
||||
$githubReporter?->error($exception->getRawMessage(), $file, $line <= 0 ? null : $line);
|
||||
|
||||
if ($file) {
|
||||
$output->text(sprintf('<error> ERROR </error> in %s (line %s)', $file, $line));
|
||||
$output->text(\sprintf('<error> ERROR </error> in %s (line %s)', $file, $line));
|
||||
} else {
|
||||
$output->text(sprintf('<error> ERROR </error> (line %s)', $line));
|
||||
$output->text(\sprintf('<error> ERROR </error> (line %s)', $line));
|
||||
}
|
||||
|
||||
// If the line is not known (this might happen for deprecations if we fail at detecting the line for instance),
|
||||
// we render the message without context, to ensure the message is displayed.
|
||||
if ($line <= 0) {
|
||||
$output->text(sprintf('<error> >> %s</error> ', $exception->getRawMessage()));
|
||||
$output->text(\sprintf('<error> >> %s</error> ', $exception->getRawMessage()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->getContext($template, $line) as $lineNumber => $code) {
|
||||
$output->text(sprintf(
|
||||
$output->text(\sprintf(
|
||||
'%s %-6s %s',
|
||||
$lineNumber === $line ? '<error> >> </error>' : ' ',
|
||||
$lineNumber,
|
||||
$code
|
||||
));
|
||||
if ($lineNumber === $line) {
|
||||
$output->text(sprintf('<error> >> %s</error> ', $exception->getRawMessage()));
|
||||
$output->text(\sprintf('<error> >> %s</error> ', $exception->getRawMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user