Issues (35)

src/Command/AggregateCommand.php (6 issues)

1
<?php
2
3
namespace Xima\DepmonBundle\Command;
4
5
6
use Psr\Log\LoggerInterface;
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\Console\Style\SymfonyStyle;
0 ignored issues
show
The type Symfony\Component\Console\Style\SymfonyStyle was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Xima\DepmonBundle\Service\Aggregator;
10
use Xima\DepmonBundle\Service\Cache;
11
use Psr\Cache\InvalidArgumentException;
12
use Symfony\Component\Console\Helper\ProgressBar;
0 ignored issues
show
The type Symfony\Component\Console\Helper\ProgressBar was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
/**
17
 * Class AggregateCommand
18
 * @package Xima\DepmonBundle\Command
19
 */
20
class AggregateCommand extends ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated: since Symfony 4.2, use {@see Command} instead. ( Ignorable by Annotation )

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

20
class AggregateCommand extends /** @scrutinizer ignore-deprecated */ ContainerAwareCommand
Loading history...
21
{
22
23
    /**
24
     * @var Aggregator
25
     */
26
    private $aggregator;
27
28
    /**
29
     * @var Cache
30
     */
31
    private $cache;
32
33
    /**
34
     * @var LoggerInterface
35
     */
36
    private $logger;
37
38
    public function __construct(Aggregator $aggregator, Cache $cache, LoggerInterface $logger)
39
    {
40
        $this->aggregator = $aggregator;
41
        $this->cache = $cache;
42
        $this->logger = $logger;
43
44
        parent::__construct();
45
    }
46
47
    protected function configure()
48
    {
49
        $this
50
            // the name of the command (the part after "bin/console")
51
            ->setName('depmon:aggregate')
52
53
            // the short description shown while running "php bin/console list"
54
            ->setDescription('Aggregate command.')
55
56
            // the full command description shown when running the command with
57
            // the "--help" option
58
            ->setHelp('This command is fetching all composer information of every project.')
59
        ;
60
    }
61
62
    protected function execute(InputInterface $input, OutputInterface $output)
63
    {
64
65
        $io = new SymfonyStyle($input, $output);
66
67
        $io->text("<fg=red>██████╗ ███████╗██████╗ ███╗   ███╗ ██████╗ ███╗   ██╗</>");
68
        $io->text("<fg=red>██╔══██╗██╔════╝██╔══██╗████╗ ████║██╔═══██╗████╗  ██║</>");
69
        $io->text("<fg=red>██║  ██║█████╗  ██████╔╝██╔████╔██║██║   ██║██╔██╗ ██║</>");
70
        $io->text("<fg=red>██║  ██║██╔══╝  ██╔═══╝ ██║╚██╔╝██║██║   ██║██║╚██╗██║</>");
71
        $io->text("<fg=red>██████╔╝███████╗██║     ██║ ╚═╝ ██║╚██████╔╝██║ ╚████║</>");
72
        $io->text("<fg=red>╚═════╝ ╚══════╝╚═╝     ╚═╝     ╚═╝ ╚═════╝ ╚═╝  ╚═══╝</>");
73
74
        $io->title("Aggregate project data");
75
76
//        $projects = Yaml::parseFile('config/depmon.projects.yaml');
77
        $projects = $this->getContainer()->getParameter('xima_depmon.projects');
78
79
        $progressBar = new ProgressBar($output, count($projects));
80
        $progressBar->setFormat('verbose');
81
82
        $projectCount = count($projects);
83
        $io->text("Fetching data for $projectCount projects ...");
84
85
86
        $dependencyCount = 0;
87
88
        foreach ($projects as $project) {
89
            try {
90
91
                $data = $this->aggregator->fetchProjectData($project, $this->logger);
92
                $count = count($data['dependencies']);
93
                $requiredCount = $data['meta']['requiredPackagesCount'];
94
                $requiredStatesCount = $data['meta']['requiredStatesCount'];
95
                $dependencyCount += $count;
96
97
                $this->cache->set($project['name'], $data);
98
99
                switch ($data['meta']['projectState']) {
100
                    case 1:
101
                        $projectState = "<fg=green>up to date</>";
102
                        break;
103
                    case 2:
104
                        $projectState = "<fg=yellow>up to date</>";
105
                        break;
106
                    case 3:
107
                    default:
108
                        $projectState = "<fg=red>out of date</>";
109
                        break;
110
                    case 4:
111
                        $projectState = "<fg=black>insecure</>";
112
                        break;
113
                }
114
115
                $progressBar->advance();
116
                $output->writeln(" <fg=blue;options=bold>[" . $project['name'] . "]</> $count dependencies, $requiredCount required (<fg=green>$requiredStatesCount[1]</>, <fg=yellow>$requiredStatesCount[2]</>, <fg=red>$requiredStatesCount[3]</>, <fg=black>$requiredStatesCount[4]</>) ==> " . $projectState);
117
118
            } catch (InvalidArgumentException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
119
120
            }
121
122
            $this->aggregator->clearProjectData($project);
123
        }
124
125
126
        $metadata = [
127
            'time' => time(),
128
            'dependencyCount' => $dependencyCount
129
        ];
130
131
        $this->cache->set('metadata', $metadata);
132
    }
133
}