Passed
Push — master ( 1bce37...29d889 )
by Alexis
01:34
created

StatusesHomeTimelineTestCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
8
class StatusesHomeTimelineTestCommand extends StatusesHomeTimelineCommand
9
{
10 9
    protected function configure()
11
    {
12 9
        parent::configure();
13
14
        $this
15 9
            ->setName('statuses:hometimelinetest')
16 9
            ->setDescription('Fetch home timeline test')
17 9
            ->addArgument(
18 9
                'test',
19 9
                InputArgument::OPTIONAL,
20 9
                'Return data for tests'
21
            );
22 9
    }
23
24
    /**
25
     * Read tweet(s) from a JSON file.
26
     *
27
     * @param string $filename
28
     *
29
     * @return array
30
     */
31 3
    protected function getTestContent($filename)
32
    {
33 3
        return json_decode(file_get_contents(
34 3
            sprintf(__DIR__.'/../../tests/Command/data/%s', $filename)
35
        ));
36
    }
37
38
    /**
39
     * @param InputInterface $input
40
     *
41
     * @return string|null|array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null|object?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
42
     */
43 7
    protected function getContent(InputInterface $input)
44
    {
45 7
        switch ($input->getArgument('test')) {
46 7
            case 'json':
47 2
                return $this->getTestContent(
48 2
                    'tweets_32_bits.json');
49 5
            case 'json_with_retweet':
50 1
                return $this->getTestContent(
51 1
                    'tweet_with_retweet.json');
52 4
            case 'not_array':
53
                // Return null instead of JSON
54 1
                return;
55 3
            case 'empty_array':
56
                // Return an empty array instead of JSON
57 2
                return [];
58
            default:
59
                // Normal behaviour
60 1
                return parent::getContent($input);
61
        }
62
    }
63
}
64