Test Setup Failed
Push — feature/super-model ( 86f2ea...9eaa75 )
by axel
09:29 queued 07:56
created

HistoryModel   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 156
rs 10
c 0
b 0
f 0
wmc 14

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getProgress() 0 3 1
A getTitle() 0 3 1
A __construct() 0 11 2
A getAllInfo() 0 23 4
A getType() 0 6 1
A getDate() 0 10 2
A getId() 0 6 1
A __call() 0 7 2
1
<?php
2
3
namespace MalScraper\Model\User;
4
5
use MalScraper\Model\MainModel;
6
7
/**
8
 * HistoryModel class.
9
 */
10
class HistoryModel extends MainModel
11
{
12
    /**
13
     * Username.
14
     *
15
     * @var string
16
     */
17
    private $_user;
18
19
    /**
20
     * Either anime or manga.
21
     *
22
     * @var string
23
     */
24
    private $_type;
25
26
    /**
27
     * Default constructor.
28
     *
29
     * @param string $user
30
     * @param string $type
31
     * @param string $parserArea
32
     *
33
     * @return void
34
     */
35
    public function __construct($user, $type, $parserArea = '#content')
36
    {
37
        $this->_user = $user;
38
        $this->_type = $type;
39
        $this->_url = $this->_myAnimeListUrl.'/history/'.$user;
40
        if ($this->_type) {
41
            $this->_url .= '/'.$type;
42
        }
43
        $this->_parserArea = $parserArea;
44
45
        parent::errorCheck($this);
46
    }
47
48
    /**
49
     * Default call.
50
     *
51
     * @param string $method
52
     * @param array  $arguments
53
     *
54
     * @return array|string|int
55
     */
56
    public function __call($method, $arguments)
57
    {
58
        if ($this->_error) {
59
            return $this->_error;
60
        }
61
62
        return call_user_func_array([$this, $method], $arguments);
63
    }
64
65
    /**
66
     * Get id.
67
     *
68
     * @param \simplehtmldom_1_5\simple_html_dom $name_area
69
     *
70
     * @return string
71
     */
72
    private function getId($name_area)
73
    {
74
        $temp_id = $name_area->find('a', 0)->href;
75
        $temp_id = explode('=', $temp_id);
76
77
        return $temp_id[1];
78
    }
79
80
    /**
81
     * Get title.
82
     *
83
     * @param \simplehtmldom_1_5\simple_html_dom $name_area
84
     *
85
     * @return string
86
     */
87
    private function getTitle($name_area)
88
    {
89
        return $name_area->find('a', 0)->plaintext;
90
    }
91
92
    /**
93
     * Get type.
94
     *
95
     * @param \simplehtmldom_1_5\simple_html_dom $name_area
96
     *
97
     * @return string
98
     */
99
    private function getType($name_area)
100
    {
101
        $type = $name_area->find('a', 0)->href;
102
        $type = explode('.php', $type);
103
104
        return substr($type[0], 1);
105
    }
106
107
    /**
108
     * Get progress.
109
     *
110
     * @param \simplehtmldom_1_5\simple_html_dom $name_area
111
     *
112
     * @return string
113
     */
114
    private function getProgress($name_area)
115
    {
116
        return $name_area->find('strong', 0)->plaintext;
117
    }
118
119
    /**
120
     * Get date.
121
     *
122
     * @param \simplehtmldom_1_5\simple_html_dom $history
123
     *
124
     * @return string
125
     */
126
    private function getDate($history)
127
    {
128
        $date = $history->find('td', 1);
129
        $useless_date = $date->find('a', 0);
130
        $date = $date->plaintext;
131
        if ($useless_date) {
132
            $date = str_replace($useless_date, '', $date);
133
        }
134
135
        return trim($date);
136
    }
137
138
    /**
139
     * Get user history list.
140
     *
141
     * @return string
142
     */
143
    private function getAllInfo()
144
    {
145
        $data = [];
146
        $history_area = $this->_parser->find('table', 0);
147
        if ($history_area) {
148
            foreach ($history_area->find('tr') as $history) {
149
                if ($history->find('td', 0)->class != 'borderClass') {
150
                    continue;
151
                }
152
                $h_temp = [];
153
                $name_area = $history->find('td', 0);
154
155
                $h_temp['id'] = $this->getId($name_area);
156
                $h_temp['title'] = $this->getTitle($name_area);
157
                $h_temp['type'] = $this->getType($name_area);
158
                $h_temp['progress'] = $this->getProgress($name_area);
159
                $h_temp['date'] = $this->getDate($history);
160
161
                $data[] = $h_temp;
162
            }
163
        }
164
165
        return $data;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $data returns the type array|array<mixed,array> which is incompatible with the documented return type string.
Loading history...
166
    }
167
}
168