Completed
Push — master ( 05c35a...2edd45 )
by Alexis
06:51
created

StatusesHomeTimelineTestCommand::getContent()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
ccs 15
cts 15
cp 1
rs 8.8571
cc 5
eloc 14
nc 5
nop 1
crap 5
1
<?php
2
3
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Input\InputArgument;
7
8
class StatusesHomeTimelineTestCommand extends StatusesHomeTimelineCommand
9
{
10
    private $displayTable;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $displayTable is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
11
    private $table;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $table is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
    private $progress;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $progress is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
13
    
14
    /** @see https://dev.twitter.com/rest/reference/get/statuses/home_timeline */
15
    private $parameters = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $parameters is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        'count' => 200,
17
        'exclude_replies' => true
18
    );
19
    
20 7
    protected function configure()
21
    {
22 7
        parent::configure();
23
        
24 7
        $this
25 7
            ->setName('statuses:hometimelinetest')
26 7
            ->setDescription('Fetch home timeline test')
27 7
            ->addArgument(
28 7
                'test',
29 7
                InputArgument::OPTIONAL,
30
                'Return data for tests'
31 7
            )    
32
        ;
33 7
    }
34
    
35
    /**
36
     * Read tweet(s) from a JSON file
37
     * 
38
     * @param string $filename
39
     * @return array
40
     */
41 3
    protected function getTestContent($filename)
42
    {
43
        /** @see https://insight.sensiolabs.com/what-we-analyse/symfony.dependency_injection.use_dir_file_constant */
44 3
        return(json_decode(file_get_contents(
45 3
            $this->container->get('kernel')->locateResource(
46
                '@AsyncTweetsBundle/Tests/Command/data/'.$filename
47 3
            )
48 3
        )));
49
    }
50
    
51
    /**
52
     * @param InputInterface $input
53
     */
54 7
    protected function getContent(InputInterface $input)
55
    {
56 7
        switch($input->getArgument('test')) {
57 7
            case 'json':
58 2
                return($this->getTestContent(
59 2
                    'tweets_32_bits.json'));
60 5
            case 'json_with_retweet':
61 1
                return($this->getTestContent(
62 1
                    'tweet_with_retweet.json'));
63 4
            case 'not_array':
64
                // Return null instead of JSON
65 1
                return(null);
66 3
            case 'empty_array':
67
                // Return an empty array instead of JSON
68 2
                return(array());
69 1
            default:
70
                // Normal behaviour
71 1
                return(parent::getContent($input)); 
72 1
        }
73
    }
74
}
75