Skip to content

Commit 5020976

Browse files
authored
Merge pull request #31 from javiereguiluz/misc_fixes
Misc. fixes and minor improvements
2 parents 70d226e + 13c9576 commit 5020976

10 files changed

+17
-19
lines changed

src/CI/MissingFilesChecker.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace SymfonyDocsBuilder\CI;
1313

1414
use Symfony\Component\Filesystem\Filesystem;
15-
use Symfony\Component\Finder\Finder;
1615
use SymfonyDocsBuilder\BuildContext;
1716

1817
class MissingFilesChecker
@@ -38,10 +37,10 @@ public function getMissingFiles(): array
3837
$htmlFile = sprintf(
3938
'%s/%s.html',
4039
$this->buildContext->getOutputDir(),
41-
substr($sourcePath, 0, \strlen($sourcePath) - 4)
40+
substr($sourcePath, 0, -4)
4241
);
4342

44-
$firstLine = fgets(fopen($file->getRealPath(), 'r'));
43+
$firstLine = fgets(fopen($file->getRealPath(), 'rb'));
4544
if (!$this->filesystem->exists($htmlFile) && ':orphan:' !== trim($firstLine)) {
4645
$orphanedFiles[] = $htmlFile;
4746
}

src/Command/BuildDocsCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
132132
$configFileParser->processConfigFile($sourceDir);
133133
}
134134

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

185-
return 0;
185+
return Command::SUCCESS;
186186
}
187187

188188
private function generateJson(Metas $metas)

src/Directive/AbstractAdmonitionDirective.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final public function processSub(Parser $parser, ?Node $document, string $variab
3434
[
3535
'name' => $this->name,
3636
'text' => $this->text,
37-
'class' => isset($options['class']) ? $options['class'] : null,
37+
'class' => $options['class'] ?? null,
3838
]
3939
);
4040

src/Directive/AdmonitionDirective.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function processSub(Parser $parser, ?Node $document, string $variable, st
2424
// had a class of 'admonition-"
2525
'name' => '',
2626
'text' => $data,
27-
'class' => isset($options['class']) ? $options['class'] : null,
27+
'class' => $options['class'] ?? null,
2828
]
2929
);
3030

src/Generator/HtmlForPdfGenerator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ private function fixInternalUrls(string $fileContent, string $dir): string
9999
{
100100
return preg_replace_callback(
101101
'/href="([^"]+?)"/',
102-
function ($matches) use ($dir) {
102+
static function ($matches) use ($dir) {
103103
if ('http' === substr($matches[1], 0, 4) || '#' === substr($matches[1], 0, 1)) {
104104
return $matches[0];
105105
}
106106

107107
$path = [];
108108
foreach (explode('/', $dir.'/'.str_replace(['.html', '#'], ['', '-'], $matches[1])) as $part) {
109-
if ('..' == $part) {
109+
if ('..' === $part) {
110110
array_pop($path);
111111
} else {
112112
$path[] = $part;
@@ -130,7 +130,7 @@ private function fixUniqueIdsAndAnchors(string $fileContent, string $uid): strin
130130
{
131131
return preg_replace_callback(
132132
'/id="([^"]+)"/',
133-
function ($matches) use ($uid) {
133+
static function ($matches) use ($uid) {
134134
return sprintf('id="%s-%s"', $uid, $matches[1]);
135135
},
136136
$fileContent
@@ -145,7 +145,7 @@ private function cleanupContent($content)
145145
// convert links to footnote
146146
$content = preg_replace_callback(
147147
'#<a href="(.*?)" class="reference external"(?:[^>]*)>(.*?)</a>#',
148-
function ($matches) {
148+
static function ($matches): string {
149149
if (0 === strpos($matches[2], 'http')) {
150150
return sprintf('<em><a href="%s">%s</a></em>', $matches[2], $matches[2]);
151151
}

src/Generator/JsonGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private function guessNext(string $parserFilename): ?array
117117
];
118118
}
119119

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

122122
if (!isset($toc[$indexCurrentFile + 1])) {
123123
return null;
@@ -147,7 +147,7 @@ private function guessPrev(string $parserFilename): ?array
147147
return null;
148148
}
149149

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

152152
// if current file is the first one of the chapter, prev is the direct parent
153153
if (0 === $indexCurrentFile) {

src/Listener/BuildProgressListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function preBuildParse(PreBuildParseEvent $event)
6767
public function postParseDocument(PostParseDocumentEvent $postParseDocumentEvent): void
6868
{
6969
$file = $postParseDocumentEvent->getDocumentNode()->getEnvironment()->getCurrentFileName();
70-
if (!\in_array($file, $this->parsedFiles)) {
70+
if (!\in_array($file, $this->parsedFiles, true)) {
7171
$this->parsedFiles[] = $file;
7272
$this->progressBar->advance();
7373
}

src/Reference/PhpMethodReference.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public function getName(): string
2929

3030
public function resolve(Environment $environment, string $data): ResolvedReference
3131
{
32-
$class = explode('::', $data)[0];
33-
$method = explode('::', $data)[1];
32+
[$class, $method] = explode('::', $data, 2);
3433

3534
return new ResolvedReference(
3635
$environment->getCurrentFileName(),

src/Renderers/CodeNodeRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ public static function isLanguageSupported(string $lang): bool
9191
$highlighter = new Highlighter();
9292
$supportedLanguages = array_merge(
9393
array_keys(self::LANGUAGES_MAPPING),
94-
$highlighter->listLanguages(true),
94+
$highlighter->listRegisteredLanguages(true),
9595
// not highlighted, but valid
9696
['text']
9797
);
9898

99-
return \in_array($lang, $supportedLanguages);
99+
return \in_array($lang, $supportedLanguages, true);
100100
}
101101

102102
private function getLines(string $code): array

src/Twig/AssetsExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function getFunctions(): array
2121
];
2222
}
2323

24-
public function asset($path)
24+
public function asset($path): string
2525
{
2626
return sprintf('assets/%s', $path);
2727
}

0 commit comments

Comments
 (0)