Completed
Push — master ( 4f2fad...dd1cd3 )
by Guillaume
07:10
created

InitHandler::handle()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 36
rs 8.8571
cc 2
eloc 23
nc 2
nop 3
1
<?php
2
3
namespace Hogosha\Monitor\Console\Handler;
4
5
use Hogosha\Monitor\Configuration\ConfigurationDumper;
6
use Hogosha\Monitor\Configuration\ConfigurationLoader;
7
use Hogosha\Monitor\DependencyInjection\Exception\ConfigurationLoadingException;
8
use Symfony\Component\Filesystem\Filesystem;
9
use Webmozart\Console\Api\Args\Args;
10
use Webmozart\Console\Api\Command\Command;
11
use Webmozart\Console\Api\IO\IO;
12
13
/**
14
 * @author Guillaume Cavana <[email protected]>
15
 */
16
class InitHandler
17
{
18
    /**
19
     * $configurationLoader.
20
     * @var ConfigurationLoader
21
     */
22
    protected $configurationLoader;
23
24
    /**
25
     * $configurationDumper.
26
     * @var ConfigurationDumper
27
     */
28
    protected $configurationDumper;
29
30
    /**
31
     * Constructor.
32
     * @param ConfigurationLoader $configurationLoader
33
     * @param ConfigurationDumper $configurationDumper
34
     * @param Filesystem          $filesystem
35
     */
36
    public function __construct(
37
        ConfigurationLoader $configurationLoader,
38
        ConfigurationDumper $configurationDumper,
39
        Filesystem $filesystem
40
    ) {
41
        $this->configurationLoader = $configurationLoader;
42
        $this->configurationDumper = $configurationDumper;
43
        $this->filesystem = $filesystem;
0 ignored issues
show
Bug introduced by
The property filesystem does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
    }
45
46
    /**
47
     * handle.
48
     * @param  Args    $args
49
     * @param  IO      $io
50
     * @param  Command $command
51
     * @return integer
52
     */
53
    public function handle(Args $args, IO $io, Command $command)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from 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 $command is not used and could be removed.

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

Loading history...
54
    {
55
        try {
56
            $configuration = $this->configurationLoader->loadConfiguration();
57
        } catch (ConfigurationLoadingException $e) {
58
            $configuration = [
59
                'server' => [
60
                    'hostname' => null,
61
                    'port' => null,
62
                    'use_ssl' => null,
63
                    'auth' => [
64
                        'username' => null,
65
                        'password' => null,
66
                    ],
67
                ],
68
                'urls' => [
69
                    'google' => [
70
                        'url' => 'https://www.google.fr',
71
                        'timeout' => 1,
72
                        'status_code' => 200,
73
                        'service_uid' => '',
74
                    ],
75
                ],
76
            ];
77
        }
78
79
        // Dump configuration
80
        $content = $this->configurationDumper->dumpConfiguration($configuration);
81
82
        $this->filesystem->dumpFile(
83
            $this->configurationLoader->getConfigurationFilepath(),
84
            $content
85
        );
86
87
        $io->writeLine('<info>Creating monitor file</info>');
88
    }
89
}
90