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.

OutlineFileCommand   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getParser() 0 14 2
A parseFiles() 0 13 1
A saveImage() 0 9 1
A getOutputFilePath() 0 3 1
A execute() 0 9 1
A renderParsed() 0 7 1
1
<?php
2
3
namespace Spatie\CodeOutline\Commands;
4
5
use Spatie\Browsershot\Browsershot;
6
use Spatie\CodeOutline\Elements\Page;
7
use Spatie\CodeOutline\Parser\DirectoryParser;
8
use Spatie\CodeOutline\Parser\FileParser;
9
use Spatie\CodeOutline\Parser\Parser;
10
use Spatie\CodeOutline\Renderer\Renderer;
11
use Symfony\Component\Console\Command\Command;
12
use Symfony\Component\Console\Helper\ProgressBar;
13
use Symfony\Component\Console\Input\InputArgument;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class OutlineFileCommand extends Command
19
{
20
    public function __construct()
21
    {
22
        parent::__construct('outline');
23
24
        $this->addArgument('path', InputArgument::REQUIRED);
25
26
        $this->addOption('output', null, InputOption::VALUE_OPTIONAL, 'Where to save the output file (it must be a PNG).');
27
28
        $this->addOption('extensions', null, InputOption::VALUE_OPTIONAL, 'The extensions of which files to scan for. Eg. `php,html`');
29
    }
30
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $page = $this->parseFiles($input, $output);
34
35
        $rendered = $this->renderParsed($page, $input, $output);
36
37
        $outputFilePath = $this->saveImage($rendered, $input, $output);
38
39
        $output->writeln("Saved to {$outputFilePath}");
40
    }
41
42
    protected function parseFiles(InputInterface $input, OutputInterface $output): Page
43
    {
44
        $path = $input->getArgument('path');
45
46
        $output->writeln('Parsing files...');
47
48
        $progressBar = new ProgressBar($output);
49
50
        $parser = $this->getParser($path, $input->getOption('extensions'), $progressBar);
0 ignored issues
show
Bug introduced by
It seems like $path can also be of type null and string[]; however, parameter $path of Spatie\CodeOutline\Comma...ileCommand::getParser() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

50
        $parser = $this->getParser(/** @scrutinizer ignore-type */ $path, $input->getOption('extensions'), $progressBar);
Loading history...
51
52
        $progressBar->finish();
53
54
        return $parser->getParsed();
55
    }
56
57
    protected function renderParsed(Page $page, 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

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