Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/CI/MissingFilesChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace SymfonyDocsBuilder\CI;

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use SymfonyDocsBuilder\BuildContext;

class MissingFilesChecker
Expand All @@ -38,10 +37,10 @@ public function getMissingFiles(): array
$htmlFile = sprintf(
'%s/%s.html',
$this->buildContext->getOutputDir(),
substr($sourcePath, 0, \strlen($sourcePath) - 4)
substr($sourcePath, 0, -4)
);

$firstLine = fgets(fopen($file->getRealPath(), 'r'));
$firstLine = fgets(fopen($file->getRealPath(), 'rb'));
if (!$this->filesystem->exists($htmlFile) && ':orphan:' !== trim($firstLine)) {
$orphanedFiles[] = $htmlFile;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/BuildDocsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$configFileParser->processConfigFile($sourceDir);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$builder = new Builder(
KernelFactory::createKernel($this->buildContext, $this->urlChecker ?? null)
Expand Down Expand Up @@ -182,7 +182,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->io->success('Build completed successfully!');
}

return 0;
return Command::SUCCESS;
}

private function generateJson(Metas $metas)
Expand Down
2 changes: 1 addition & 1 deletion src/Directive/AbstractAdmonitionDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final public function processSub(Parser $parser, ?Node $document, string $variab
[
'name' => $this->name,
'text' => $this->text,
'class' => isset($options['class']) ? $options['class'] : null,
'class' => $options['class'] ?? null,
]
);

Expand Down
2 changes: 1 addition & 1 deletion src/Directive/AdmonitionDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function processSub(Parser $parser, ?Node $document, string $variable, st
// had a class of 'admonition-"
'name' => '',
'text' => $data,
'class' => isset($options['class']) ? $options['class'] : null,
'class' => $options['class'] ?? null,
]
);

Expand Down
8 changes: 4 additions & 4 deletions src/Generator/HtmlForPdfGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ private function fixInternalUrls(string $fileContent, string $dir): string
{
return preg_replace_callback(
'/href="([^"]+?)"/',
function ($matches) use ($dir) {
static function ($matches) use ($dir) {
if ('http' === substr($matches[1], 0, 4) || '#' === substr($matches[1], 0, 1)) {
return $matches[0];
}

$path = [];
foreach (explode('/', $dir.'/'.str_replace(['.html', '#'], ['', '-'], $matches[1])) as $part) {
if ('..' == $part) {
if ('..' === $part) {
array_pop($path);
} else {
$path[] = $part;
Expand All @@ -130,7 +130,7 @@ private function fixUniqueIdsAndAnchors(string $fileContent, string $uid): strin
{
return preg_replace_callback(
'/id="([^"]+)"/',
function ($matches) use ($uid) {
static function ($matches) use ($uid) {
return sprintf('id="%s-%s"', $uid, $matches[1]);
},
$fileContent
Expand All @@ -145,7 +145,7 @@ private function cleanupContent($content)
// convert links to footnote
$content = preg_replace_callback(
'#<a href="(.*?)" class="reference external"(?:[^>]*)>(.*?)</a>#',
function ($matches) {
static function ($matches): string {
if (0 === strpos($matches[2], 'http')) {
return sprintf('<em><a href="%s">%s</a></em>', $matches[2], $matches[2]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/JsonGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private function guessNext(string $parserFilename): ?array
];
}

list($toc, $indexCurrentFile) = $this->getNextPrevInformation($parserFilename);
[$toc, $indexCurrentFile] = $this->getNextPrevInformation($parserFilename);

if (!isset($toc[$indexCurrentFile + 1])) {
return null;
Expand Down Expand Up @@ -147,7 +147,7 @@ private function guessPrev(string $parserFilename): ?array
return null;
}

list($toc, $indexCurrentFile) = $this->getNextPrevInformation($parserFilename);
[$toc, $indexCurrentFile] = $this->getNextPrevInformation($parserFilename);

// if current file is the first one of the chapter, prev is the direct parent
if (0 === $indexCurrentFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/BuildProgressListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function preBuildParse(PreBuildParseEvent $event)
public function postParseDocument(PostParseDocumentEvent $postParseDocumentEvent): void
{
$file = $postParseDocumentEvent->getDocumentNode()->getEnvironment()->getCurrentFileName();
if (!\in_array($file, $this->parsedFiles)) {
if (!\in_array($file, $this->parsedFiles, true)) {
$this->parsedFiles[] = $file;
$this->progressBar->advance();
}
Expand Down
3 changes: 1 addition & 2 deletions src/Reference/PhpMethodReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public function getName(): string

public function resolve(Environment $environment, string $data): ResolvedReference
{
$class = explode('::', $data)[0];
$method = explode('::', $data)[1];
[$class, $method] = explode('::', $data, 2);

return new ResolvedReference(
$environment->getCurrentFileName(),
Expand Down
4 changes: 2 additions & 2 deletions src/Renderers/CodeNodeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public static function isLanguageSupported(string $lang): bool
$highlighter = new Highlighter();
$supportedLanguages = array_merge(
array_keys(self::LANGUAGES_MAPPING),
$highlighter->listLanguages(true),
$highlighter->listRegisteredLanguages(true),
// not highlighted, but valid
['text']
);

return \in_array($lang, $supportedLanguages);
return \in_array($lang, $supportedLanguages, true);
}

private function getLines(string $code): array
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/AssetsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getFunctions(): array
];
}

public function asset($path)
public function asset($path): string
{
return sprintf('assets/%s', $path);
}
Expand Down