UpdateSubDomains   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 49
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A runCommand() 0 13 3
A __construct() 0 5 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 *
5
 * Copyright (C) 2018  Ross Mitchell
6
 *
7
 * This file is part of RossMitchell/UpdateCloudFlare.
8
 *
9
 * RossMitchell/UpdateCloudFlare is free software: you can redistribute
10
 * it and/or modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
namespace RossMitchell\UpdateCloudFlare\Command;
24
25
use RossMitchell\UpdateCloudFlare\Abstracts\Command;
26
use RossMitchell\UpdateCloudFlare\Exceptions\CloudFlareException;
27
use RossMitchell\UpdateCloudFlare\Interfaces\ConfigInterface;
28
use RossMitchell\UpdateCloudFlare\Model\UpdateSubDomain;
0 ignored issues
show
Bug introduced by
The type RossMitchell\UpdateCloud...e\Model\UpdateSubDomain 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...
29
use Symfony\Component\Console\Exception\InvalidArgumentException;
30
use Symfony\Component\Console\Exception\LogicException;
31
use Symfony\Component\Console\Input\InputInterface;
32
use Symfony\Component\Console\Output\OutputInterface;
33
34
/**
35
 * Class UpdateSubDomains
36
 * @package RossMitchell\UpdateCloudFlare\Command
37
 */
38
class UpdateSubDomains extends Command
39
{
40
    /**
41
     * @var UpdateSubDomain
42
     */
43
    private $subDomain;
44
    /**
45
     * @var ConfigInterface
46
     */
47
    private $config;
48
49
    /**
50
     * UpdateSubDomains constructor.
51
     *
52
     * @param UpdateSubDomain $subDomain
53
     * @param ConfigInterface $config
54
     * @param string|null     $name
55
     *
56
     * @throws LogicException
57
     */
58
    public function __construct(UpdateSubDomain $subDomain, ConfigInterface $config, string $name = null)
59
    {
60
        parent::__construct($name);
61
        $this->subDomain = $subDomain;
62
        $this->config    = $config;
63
    }
64
65
    /**
66
     * @param InputInterface  $input
67
     * @param OutputInterface $output
68
     *
69
     * @throws LogicException
70
     * @throws \RuntimeException
71
     * @throws InvalidArgumentException
72
     * @throws CloudFlareException
73
     */
74
    public function runCommand(InputInterface $input, OutputInterface $output)
75
    {
76
        $newIpAddress = $input->getOption('ip-address');
77
        if (!empty($newIpAddress)) {
78
            $this->subDomain->setIpAddress($newIpAddress);
79
        }
80
        $subDomains = $this->config->getSubDomains();
81
        foreach ($subDomains as $subDomain) {
82
            $this->subDomain->setSubDomain($subDomain);
83
            $message = $this->subDomain->updateSubDomain();
84
            $output->writeln($message);
85
        }
86
        $output->writeln('All sub domains have been updated');
87
    }
88
}
89