Passed
Push — master ( 71368b...ee9f04 )
by axel
02:15
created

EpisodeModel::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MalScraper\Model\Additional;
4
5
use MalScraper\Model\MainModel;
6
7
/**
8
 * EpisodeModel class.
9
 */
10
class EpisodeModel extends MainModel
11
{
12
    /**
13
     * Id of the anime.
14
     *
15
     * @var string|int
16
     */
17
    private $_id;
18
19
    /**
20
     * Page number.
21
     *
22
     * @var int
23
     */
24
    private $_page;
25
26
    /**
27
     * Default constructor.
28
     *
29
     * @param string|int $id
30
     * @param string     $parserArea
31
     *
32
     * @return void
33
     */
34
    public function __construct($id, $page, $parserArea = '.js-scrollfix-bottom-rel')
35
    {
36
        $this->_id = $id;
37
        $this->_page = $page;
38
        $this->_url = $this->_myAnimeListUrl.'/anime/'.$id;
39
        $this->_parserArea = $parserArea;
40
41
        parent::errorCheck($this);
42
    }
43
44
    /**
45
     * Default call.
46
     *
47
     * @param string $method
48
     * @param array  $arguments
49
     *
50
     * @return array|string|int
51
     */
52
    public function __call($method, $arguments)
53
    {
54
        if ($this->_error) {
55
            return $this->_error;
56
        }
57
58
        return call_user_func_array([$this, $method], $arguments);
59
    }
60
61
    /**
62
     * Get type.
63
     *
64
     * @return string
65
     */
66
    private function getType()
67
    {
68
        return 'anime';
69
    }
70
71
    /**
72
     * Get anime id.
73
     *
74
     * @return string
75
     */
76
    private function getId()
77
    {
78
        return $this->_id;
79
    }
80
81
    /**
82
     * Get page.
83
     *
84
     * @return string
85
     */
86
    private function getPage()
87
    {
88
        return $this->_page;
89
    }
90
91
    /**
92
     * Get episode video link.
93
     *
94
     * @param \simplehtmldom_1_5\simple_html_dom $each_episode
95
     *
96
     * @return string
97
     */
98
    private function getEpisodeLink($each_episode)
99
    {
100
        return $each_episode->find('.episode-video a', 0)->href;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $each_episode->fi...sode-video a', 0)->href also could return the type boolean which is incompatible with the documented return type string.
Loading history...
101
    }
102
103
    /**
104
     * Get episode video number.
105
     *
106
     * @param \simplehtmldom_1_5\simple_html_dom $each_episode
107
     *
108
     * @return string
109
     */
110
    private function getEpisodeNo($each_episode)
111
    {
112
        return $each_episode->find('.episode-number', 0)->plaintext;
113
    }
114
115
    /**
116
     * Get episode video title.
117
     *
118
     * @param \simplehtmldom_1_5\simple_html_dom $each_episode
119
     * @param string                             $type
120
     *
121
     * @return string
122
     */
123
    private function getEpisodeTitle($each_episode, $type = false)
124
    {
125
        $title = $each_episode->find('.episode-title', 0);
126
        if ($type) {
127
            if ($title->find('span', 1)) {
128
                return trim($title->find('span', 1)->plaintext);
129
            }
130
131
            return trim($title->find('span', 0)->plaintext);
132
        } else {
133
            return $title->find('a', 0)->plaintext;
134
        }
135
    }
136
137
    /**
138
     * Get episode video aired date.
139
     *
140
     * @param \simplehtmldom_1_5\simple_html_dom $each_episode
141
     *
142
     * @return string
143
     */
144
    private function getEpisodeAired($each_episode)
145
    {
146
        $aired = $each_episode->find('.episode-aired', 0)->plaintext;
147
148
        return str_replace('N/A', '', $aired);
149
    }
150
151
    /**
152
     * Get anime videos.
153
     *
154
     * @return array
155
     */
156
    private function getAllInfo()
157
    {
158
        $data = [];
159
        $episode_area = $this->_parser->find('table.episode_list', 0);
160
        if ($episode_area) {
161
            foreach ($episode_area->find('.episode-list-data') as $each_episode) {
162
                $temp = [];
163
164
                $temp['episode'] = $this->getEpisodeNo($each_episode);
165
                $temp['link'] = $this->getEpisodeLink($each_episode);
166
                $temp['title'] = $this->getEpisodeTitle($each_episode);
167
                $temp['japanese_title'] = $this->getEpisodeTitle($each_episode, true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $type of MalScraper\Model\Additio...odel::getEpisodeTitle(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

167
                $temp['japanese_title'] = $this->getEpisodeTitle($each_episode, /** @scrutinizer ignore-type */ true);
Loading history...
168
                $temp['aired'] = $this->getEpisodeAired($each_episode);
169
170
                $data[] = $temp;
171
            }
172
        }
173
174
        return $data;
175
    }
176
}
177