RunFeedReaderCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 14
c 1
b 0
f 1
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 11 2
A __construct() 0 5 1
A configure() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jellyfish\Feed\Command;
6
7
use InvalidArgumentException;
8
use Jellyfish\Feed\FeedReaderManagerInterface;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
use function is_string;
15
16
class RunFeedReaderCommand extends Command
17
{
18
    public const NAME = 'feed:feed-reader:run';
19
    public const DESCRIPTION = 'Run feed reader.';
20
21
    /**
22
     * @var \Jellyfish\Feed\FeedReaderManagerInterface
23
     */
24
    protected $feedReaderManager;
25
26
    /**
27
     * @param \Jellyfish\Feed\FeedReaderManagerInterface $feedReaderManager
28
     */
29
    public function __construct(FeedReaderManagerInterface $feedReaderManager)
30
    {
31
        parent::__construct();
32
33
        $this->feedReaderManager = $feedReaderManager;
34
    }
35
36
    /**
37
     * @return void
38
     */
39
    protected function configure(): void
40
    {
41
        parent::configure();
42
43
        $this->setName(static::NAME);
44
        $this->setDescription(static::DESCRIPTION);
45
        $this->addArgument('identifier', InputArgument::REQUIRED, 'Feed reader identifier.');
46
    }
47
48
    /**
49
     * @param \Symfony\Component\Console\Input\InputInterface $input
50
     * @param \Symfony\Component\Console\Output\OutputInterface $output
51
     *
52
     * @return int|null
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output): ?int
55
    {
56
        $identifier = $input->getArgument('identifier');
57
58
        if (!is_string($identifier)) {
59
            throw new InvalidArgumentException('Unsupported type for given argument');
60
        }
61
62
        $this->feedReaderManager->readFromFeedReader($identifier);
63
64
        return null;
65
    }
66
}
67