DiscoverCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 1
A execute() 0 13 2
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the feed-io package.
4
 *
5
 * (c) Alexandre Debril <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace FeedIo\Command;
12
13
use FeedIo\Factory;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * Class DiscoverCommand
22
 * @codeCoverageIgnore
23
 */
24
class DiscoverCommand extends Command
25
{
26
    protected function configure()
27
    {
28
        $this->setName('discover')
29
            ->setDescription('discovers feeds inside a web page')
30
            ->addArgument(
31
                'url',
32
                InputArgument::REQUIRED,
33
                'Please provide the URL'
34
            )
35
        ;
36
    }
37
38
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40
        $url = $input->getArgument('url');
41
        $output->writeln("<info>Discovering feeds from {$url}</info>");
42
        $feedIo = Factory::create()->getFeedIo();
43
        $feeds = $feedIo->discover($url);
0 ignored issues
show
Bug introduced by
It seems like $url defined by $input->getArgument('url') on line 40 can also be of type array<integer,string> or null; however, FeedIo\FeedIo::discover() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
44
45
        foreach ($feeds as $feed) {
46
            $output->writeln("<info>found : {$feed}</info>");
47
        }
48
49
        return 0;
50
    }
51
}
52