Completed
Push — master ( 7f2aa4...043ed1 )
by David
13s
created

CommonEvents   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatchService() 0 5 1
A canDispatchServiceOrFail() 0 2 1
1
<?php
2
3
4
namespace TheAentMachine;
5
6
use Symfony\Component\Console\Helper\QuestionHelper;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Question\Question;
10
use TheAentMachine\Exception\CannotHandleEventException;
11
use TheAentMachine\Service\Service;
12
13
class CommonEvents
14
{
15
    private const NEW_DOCKER_SERVICE_INFO = 'NEW_DOCKER_SERVICE_INFO';
16
17
    /**
18
     * @throws CannotHandleEventException
19
     */
20
    public function dispatchService(Service $service, QuestionHelper $helper, InputInterface $input, OutputInterface $output): void
21
    {
22
        $this->canDispatchServiceOrFail($helper, $input, $output);
23
24
        Hermes::dispatchJson(self::NEW_DOCKER_SERVICE_INFO, $service);
25
    }
26
27
    /**
28
     * @throws CannotHandleEventException
29
     */
30
    public function canDispatchServiceOrFail(QuestionHelper $helper, InputInterface $input, OutputInterface $output): void
0 ignored issues
show
Unused Code introduced by
The parameter $output 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

30
    public function canDispatchServiceOrFail(QuestionHelper $helper, InputInterface $input, /** @scrutinizer ignore-unused */ OutputInterface $output): void

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...
Unused Code introduced by
The parameter $helper 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

30
    public function canDispatchServiceOrFail(/** @scrutinizer ignore-unused */ QuestionHelper $helper, InputInterface $input, OutputInterface $output): void

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...
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

30
    public function canDispatchServiceOrFail(QuestionHelper $helper, /** @scrutinizer ignore-unused */ InputInterface $input, OutputInterface $output): void

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...
31
    {
32
        // Disableing this whole piece of code until we can properly add an Aent from a container
33
        /*$canHandle = Hercule::canHandleEvent(self::NEW_DOCKER_SERVICE_INFO);
34
35
        if (!$canHandle) {
36
            $output->writeln('<error>Heads up!</error>');
37
            $output->writeln('It seems that Aenthill does not know how or where to store this new service. You need to install a dedicated Aent for this.');
38
            $output->writeln('Most of the time, you want to put this service in a docker-compose.yml file. We have a pretty good Aent for this: <info>theaentmachine/aent-docker-compose</info>.');
39
            $question = new Question('Do you want me to add this Aent for you? (y/n) ', 'y');
40
            $question->setValidator(function (string $value) {
41
                $value = \strtolower(trim($value));
42
43
                if ($value !== 'y' && $value !== 'n') {
44
                    throw new \InvalidArgumentException('Please type "y" or "n"');
45
                }
46
47
                return $value;
48
            });
49
            $answer = $helper->ask($input, $output, $question);
50
51
            if ($answer === 'y') {
52
                Hercule::addAent('theaentmachine/aent-docker-compose');
53
            } else {
54
                throw CannotHandleEventException::cannotHandleEvent(self::NEW_DOCKER_SERVICE_INFO);
55
            }
56
        }*/
57
    }
58
}
59