WebhookdCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 19
c 1
b 0
f 0
dl 0
loc 70
ccs 20
cts 20
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A execute() 0 14 3
A configure() 0 3 1
1
<?php
2
3
namespace App\Command;
4
5
use App\Config;
6
use App\EventSubject;
7
use App\EventObserver;
8
use App\Service\Logger;
9
use Swoole\Http\Server;
0 ignored issues
show
Bug introduced by
The type Swoole\Http\Server 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...
10
use App\Service\Webhookd;
11
use Psr\Log\LoggerInterface;
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Logger\ConsoleLogger;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * Webhookd command
19
 *
20
 * @see https://symfony.com/doc/current/components/console.html
21
 */
22
class WebhookdCommand extends Command
23
{
24
    /**
25
     * Webhookd instance
26
     *
27
     * @var \App\Service\Webhookd
28
     */
29
    private $_webhookd;
30
31
    /**
32
     * Event subject instance
33
     *
34
     * @var \App\EventSubject
35
     */
36
    private $_subject;
37
38
    /**
39
     * Logger instance
40
     *
41
     * @var \Psr\Log\LoggerInterface
42
     */
43
    private $_logger;
44
45
    /**
46
     * Construct a new webhookd command
47
     *
48
     * @param \App\Service\Webhookd    $webhookd Webhookd instance
49
     * @param \App\EventSubject        $subject  Event subject instance
50
     * @param \Psr\Log\LoggerInterface $logger   Logger instance
51
     */
52 1
    public function __construct(Webhookd $webhookd, EventSubject $subject, LoggerInterface $logger)
53
    {
54 1
        $this->_webhookd = $webhookd;
55 1
        $this->_subject = $subject;
56 1
        $this->_logger = $logger;
57 1
        parent::__construct();
58 1
    }
59
60
    /**
61
     * Configures the current command.
62
     *
63
     * @return void
64
     */
65 1
    protected function configure()
66
    {
67 1
        $this->setDescription('Start a http server to handle gitlab webhook events.');
68 1
    }
69
70
    /**
71
     * Executes the current command.
72
     *
73
     * @param \Symfony\Component\Console\Input\InputInterface   $input  Input instance
74
     * @param \Symfony\Component\Console\Output\OutputInterface $output Output instance
75
     *
76
     * @return int|null null or 0 if everything went fine, or an error code
77
     */
78 1
    protected function execute(InputInterface $input, OutputInterface $output)
79
    {
80 1
        if ($this->_logger instanceof Logger) {
81 1
            $this->_logger->setLogger(new ConsoleLogger($output));
82
        }
83 1
        $config = new Config();
84 1
        $config->loadYaml('config.yaml');
85 1
        foreach ($config['events'] as $event) {
86 1
            $observer = new EventObserver($event);
87 1
            $this->_subject->attach($observer);
88
        }
89 1
        $server = new Server('0.0.0.0', $config['port']);
90 1
        $this->_webhookd->setServer($server);
91 1
        $this->_webhookd->start();
92 1
    }
93
}
94