ApiEndpointCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 1
A execute() 0 15 2
1
<?php
2
/**
3
 * (c) shopware AG <[email protected]>
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace ShopwarePlugins\Connect\Commands;
9
10
use Shopware\Commands\ShopwareCommand;
11
use Shopware\Components\ConfigWriter;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use Symfony\Component\Console\Style\SymfonyStyle;
16
17
class ApiEndpointCommand extends ShopwareCommand
18
{
19
    protected function configure()
20
    {
21
        $this
22
            ->setName('connect:endpoint:set')
23
            ->setDescription('Set the API endpoint to a custom location')
24
            ->addArgument(
25
                'api-endpoint',
26
                InputArgument::REQUIRED,
27
                'URL to of the API endpoint.'
28
            );
29
    }
30
31
    /**
32
     * @param InputInterface $input
33
     * @param OutputInterface $output
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        /** @var ConfigWriter $configWriter */
38
        $configWriter = $this->container->get('config_writer');
39
        $symfonyStyle = new SymfonyStyle($input, $output);
40
        $apiEndpoint = $input->getArgument('api-endpoint');
41
42
        $host = parse_url($apiEndpoint, PHP_URL_HOST);
43
        if (!$host) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $host of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
44
            $host = $apiEndpoint;
45
        }
46
47
        $configWriter->save('connectDebugHost', $host);
48
        $symfonyStyle->success('Endpoint was updated successfully to ' . $host);
49
    }
50
}
51