Tuiter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 8
c 3
b 0
f 2
lcom 1
cbo 3
dl 0
loc 64
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 2
A fromArchive() 0 8 2
A tweets() 0 4 1
A getFrom() 0 6 3
1
<?php namespace Tuiter;
2
3
use League\Csv\Reader;
4
5
/**
6
 * Class Tuiter
7
 * @package Tuiter
8
 */
9
final class Tuiter
10
{
11
    /**
12
     * @var TweetCollection
13
     */
14
    private $tweetCollection;
15
16
    /**
17
     * @param Reader $reader
18
     */
19
    public function __construct(Reader $reader)
20
    {
21
        $tweets = [];
22
        foreach ($reader->fetchAssoc() as $tweet) {
23
            $tweets[] = new Tweet(
24
                $this->getFrom($tweet, 'tweet_id'),
25
                $this->getFrom($tweet, 'text'),
26
                $this->getFrom($tweet, 'source'),
27
                $this->getFrom($tweet, 'timestamp'),
28
                $this->getFrom($tweet, 'in_reply_to_status_id'),
29
                $this->getFrom($tweet, 'retweeted_status_id'),
30
                $this->getFrom($tweet, 'expanded_urls')
31
            );
32
        }
33
34
        $this->tweetCollection = new TweetCollection($tweets);
35
    }
36
37
    /**
38
     * @param mixed $path
39
     *
40
     * @return TweetCollection
41
     */
42
    public static function fromArchive($path)
43
    {
44
        $reader = $path instanceof Reader ? $path : new Reader($path);
45
46
        $self = new self($reader);
47
48
        return $self->tweets();
49
    }
50
51
    /**
52
     * @return TweetCollection
53
     */
54
    public function tweets()
55
    {
56
        return $this->tweetCollection;
57
    }
58
59
    /**
60
     * @param $array
61
     * @param string $key
62
     * @param mixed $default
63
     *
64
     * @return mixed
65
     */
66
    private function getFrom($array, $key, $default = null)
67
    {
68
        return (array_key_exists($key, $array) && $array[$key] !== '')
69
            ? $array[$key]
70
            : $default;
71
    }
72
}
73