SearchByInstanceCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 7
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 17 1
A execute() 0 14 1
1
<?php
2
3
namespace Stp\SndApi\News\Command;
4
5
use SoapBox\Formatter\Formatter;
6
use Stp\SndApi\Common\Command\BaseCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class SearchByInstanceCommand extends BaseCommand
12
{
13
    use NewsClientCommandTrait;
14
15
    protected function configure()
16
    {
17
        parent::configure();
18
19
        $this
20
            ->setName('news:search:instance')
21
            ->addArgument(
22
                'id',
23
                InputArgument::REQUIRED,
24
                'Content ID'
25
            )
26
            ->addArgument(
27
                'contentType',
28
                InputArgument::REQUIRED,
29
                'Content type (article, person)'
30
            );
31
    }
32
33
    /**
34
     * @param InputInterface $input
35
     * @param OutputInterface $output
36
     * @return int
37
     * @throws \Stp\SndApi\News\Exception\InvalidContentTypeException
38
     */
39
    protected function execute(InputInterface $input, OutputInterface $output)
40
    {
41
        $newsClient = $this->getNewsClient($input);
42
43
        $contentId = $input->getArgument('id');
44
        $contentType = $input->getArgument('contentType');
45
46
        $result = $newsClient->searchByInstance($contentId, $contentType);
47
        $formatter = Formatter::make($result, Formatter::ARR);
48
49
        $output->writeln($formatter->toYaml());
50
51
        return 0;
52
    }
53
}
54