Completed
Push — 2.1 ( 63ded9...b14dac )
by Paweł
23s queued 11s
created

ConvertArticleToAppleNewsFormatCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
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 Symfony\Component\Console\Command\Command;
22
use Symfony\Component\Console\Input\InputArgument;
23
use Symfony\Component\Console\Input\InputInterface;
24
use Symfony\Component\Console\Output\OutputInterface;
25
26
class ConvertArticleToAppleNewsFormatCommand extends Command
27
{
28
    protected static $defaultName = 'swp:apple:convert';
29
30
    private $converter;
31
32
    private $articleRepository;
33
34
    public function __construct(
35
        ArticleToAppleNewsFormatConverter $converter,
36
        ArticleRepositoryInterface $articleRepository
37
    ) {
38
        parent::__construct();
39
40
        $this->converter = $converter;
41
        $this->articleRepository = $articleRepository;
42
    }
43
44
    protected function configure(): void
45
    {
46
        $this
47
            ->setName(self::$defaultName)
48
            ->setDescription('Converts article to Apple News Format')
49
            ->addArgument('articleId', InputArgument::REQUIRED, 'Article ID');
50
    }
51
52
    protected function execute(InputInterface $input, OutputInterface $output): int
53
    {
54
        $article = $this->articleRepository->findOneBy(['id' => $input->getArgument('articleId')]);
55
56
        $json = $this->converter->convert($article);
0 ignored issues
show
Documentation introduced by
$article is of type object|null, but the function expects a object<SWP\Bundle\CoreBu...Model\ArticleInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
58
        $output->writeln($json);
59
60
        return 0;
61
    }
62
}
63