GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( f7c46f...5a08eb )
by Freek
03:22 queued 01:51
created

OutlineFileCommand::getOutputFilePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\CodeOutline\Commands;
4
5
use Spatie\Browsershot\Browsershot;
6
use Spatie\CodeOutline\DirectoryParser;
7
use Spatie\CodeOutline\FileParser;
8
use Spatie\CodeOutline\Parser;
9
use Spatie\CodeOutline\Renderer;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Helper\ProgressBar;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class OutlineFileCommand extends Command
18
{
19
    public function __construct()
20
    {
21
        parent::__construct('outline');
22
23
        $this->addArgument('path', InputArgument::REQUIRED);
24
25
        $this->addOption('output', null, InputOption::VALUE_OPTIONAL, 'Where to save the output file (it must be a PNG).');
26
27
        $this->addOption('extensions', null, InputOption::VALUE_OPTIONAL, 'The extensions of which files to scan for. Eg. `php,html`');
28
    }
29
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $parsed = $this->parseFiles($input, $output);
33
34
        $rendered = $this->renderParsed($parsed, $input, $output);
35
36
        $outputFilePath = $this->saveImage($rendered, $input, $output);
37
38
        $output->writeln("Saved to {$outputFilePath}");
39
    }
40
41
    protected function parseFiles(InputInterface $input, OutputInterface $output): array
42
    {
43
        $path = $input->getArgument('path');
44
45
        $output->writeln('Parsing files...');
46
47
        $progressBar = new ProgressBar($output);
48
49
        $parser = $this->getParser($path, $input->getOption('extensions'), $progressBar);
50
51
        $progressBar->finish();
52
53
        return $parser->getParsed();
54
    }
55
56
    protected function renderParsed(array $parsed, InputInterface $input, OutputInterface $output)
0 ignored issues
show
Unused Code introduced by
The parameter $input is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

56
    protected function renderParsed(array $parsed, /** @scrutinizer ignore-unused */ InputInterface $input, OutputInterface $output)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {
58
        $output->writeln("\nRendering...");
59
60
        $renderer = new Renderer($parsed);
61
62
        return $renderer->getRendered();
63
    }
64
65
    protected function saveImage(string $rendered, InputInterface $input, OutputInterface $output): string
66
    {
67
        $output->writeln('Saving as image...');
68
69
        $outputFilePath = $this->getOutputFilePath($input->getOption('output'));
70
71
        Browsershot::html($rendered)->select('body')->save($outputFilePath);
72
73
        return $outputFilePath;
74
    }
75
76
    protected function getOutputFilePath(?string $path): string
77
    {
78
        return $path ?? './outline-code.png';
79
    }
80
81
    protected function getParser(string $path, ?string $extensions, ProgressBar $progressBar): Parser
82
    {
83
        if (is_dir($path)) {
84
            return (new DirectoryParser($path))
85
                ->setExtensionsFromString($extensions ?? 'php')
86
                ->onStartParsing(function (int $count) use ($progressBar) {
87
                    $progressBar->start($count);
88
                })
89
                ->onFileParsed(function () use ($progressBar) {
90
                    $progressBar->advance();
91
                });
92
        }
93
94
        return new FileParser($path);
95
    }
96
}
97