Completed
Push — master ( 009411...7fe99b )
by Rafał
18:49 queued 07:10
created

ConvertArticleToAppleNewsFormatCommand::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2019 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2020 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Command;
18
19
use SWP\Bundle\CoreBundle\AppleNews\Converter\ArticleToAppleNewsFormatConverter;
20
use SWP\Bundle\CoreBundle\Repository\ArticleRepositoryInterface;
21
use SWP\Component\Common\Exception\ArticleNotFoundException;
22
use SWP\Component\MultiTenancy\Exception\TenantNotFoundException;
23
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface;
24
use Symfony\Component\Console\Command\Command;
25
use Symfony\Component\Console\Input\InputArgument;
26
use Symfony\Component\Console\Input\InputInterface;
27
use Symfony\Component\Console\Output\OutputInterface;
28
29
class ConvertArticleToAppleNewsFormatCommand extends Command
30
{
31
    protected static $defaultName = 'swp:apple:convert';
32
33
    private $converter;
34
35
    private $articleRepository;
36
37
    private $tenantRepository;
38
39
    public function __construct(
40
        ArticleToAppleNewsFormatConverter $converter,
41
        ArticleRepositoryInterface $articleRepository,
42
        TenantRepositoryInterface $tenantRepository
43
    ) {
44
        parent::__construct();
45
46
        $this->converter = $converter;
47
        $this->articleRepository = $articleRepository;
48
        $this->tenantRepository = $tenantRepository;
49
    }
50
51
    protected function configure(): void
52
    {
53
        $this
54
            ->setName(self::$defaultName)
55
            ->setDescription('Converts article to Apple News Format')
56
            ->addArgument('articleId', InputArgument::REQUIRED, 'Article ID')
57
            ->addArgument('tenantCode', InputArgument::REQUIRED, 'Tenant code');
58
    }
59
60
    protected function execute(InputInterface $input, OutputInterface $output): int
61
    {
62
        $article = $this->articleRepository->findOneBy(['id' => $input->getArgument('articleId')]);
63
64
        if (null === $article) {
65
            throw new ArticleNotFoundException();
66
        }
67
68
        $tenant = $this->tenantRepository->findOneBy(['code' => $input->getArgument('tenantCode')]);
69
70
        if (null === $tenant) {
71
            throw new TenantNotFoundException();
0 ignored issues
show
Bug introduced by
The call to TenantNotFoundException::__construct() misses a required argument $name.

This check looks for function calls that miss required arguments.

Loading history...
72
        }
73
74
        $json = $this->converter->convert($article, $tenant);
75
76
        $output->writeln($json);
77
78
        return 0;
79
    }
80
}
81