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

VideoModel::getEpisodeTitle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MalScraper\Model\Additional;
4
5
use MalScraper\Helper\Helper;
6
use MalScraper\Model\MainModel;
7
8
/**
9
 * VideoModel class.
10
 */
11
class VideoModel extends MainModel
12
{
13
    /**
14
     * Id of the anime.
15
     *
16
     * @var string|int
17
     */
18
    private $_id;
19
20
    /**
21
     * Page number.
22
     *
23
     * @var int
24
     */
25
    private $_page;
26
27
    /**
28
     * Default constructor.
29
     *
30
     * @param string|int $id
31
     * @param string     $parserArea
32
     *
33
     * @return void
34
     */
35
    public function __construct($id, $page, $parserArea = '.js-scrollfix-bottom-rel')
36
    {
37
        $this->_id = $id;
38
        $this->_page = $page;
39
        $this->_url = $this->_myAnimeListUrl.'/anime/'.$id;
40
        $this->_parserArea = $parserArea;
41
42
        parent::errorCheck($this);
43
    }
44
45
    /**
46
     * Default call.
47
     *
48
     * @param string $method
49
     * @param array  $arguments
50
     *
51
     * @return array|string|int
52
     */
53
    public function __call($method, $arguments)
54
    {
55
        if ($this->_error) {
56
            return $this->_error;
57
        }
58
59
        return call_user_func_array([$this, $method], $arguments);
60
    }
61
62
    /**
63
     * Get type.
64
     *
65
     * @return string
66
     */
67
    private function getType()
68
    {
69
        return 'manga';
70
    }
71
72
    /**
73
     * Get anime id.
74
     *
75
     * @return string
76
     */
77
    private function getId()
78
    {
79
        return $this->_id;
80
    }
81
82
    /**
83
     * Get page.
84
     *
85
     * @return string
86
     */
87
    private function getPage()
88
    {
89
        return $this->_page;
90
    }
91
92
    /**
93
     * Get anime episode.
94
     *
95
     * @return array
96
     */
97
    private function getEpisode()
98
    {
99
        $episode = [];
100
        $episode_area = $this->_parser->find('.episode-video', 0);
101
        if ($episode_area) {
102
            foreach ($episode_area->find('.video-list-outer') as $v) {
103
                $temp = [];
104
105
                $link_area = $v->find('a', 0);
106
                $temp['episode'] = $this->getEpisodeTitle($link_area, 0);
107
                $temp['title'] = $this->getEpisodeTitle($link_area, 1);
108
                $temp['link'] = $link_area->href;
109
110
                $episode[] = $temp;
111
            }
112
        }
113
114
        return $episode;
115
    }
116
117
    /**
118
     * Get episode video title.
119
     *
120
     * @param \simplehtmldom_1_5\simple_html_dom $link_area
121
     * @param int                                $key
122
     *
123
     * @return string
124
     */
125
    private function getEpisodeTitle($link_area, $key)
126
    {
127
        $title = $link_area->find('span.title', 0)->plaintext;
128
        $title = explode("\n", $title);
129
        $title = $key == 0 ? str_replace('Episode ', '', $title[$key]) : $title[$key];
130
131
        return trim($title);
132
    }
133
134
    /**
135
     * Get anime promotion video.
136
     *
137
     * @return array
138
     */
139
    private function getPromotion()
140
    {
141
        $promotion = [];
142
        $promotion_area = $this->_parser->find('.promotional-video', 0);
143
        if ($promotion_area) {
144
            foreach ($promotion_area->find('.video-list-outer') as $v) {
145
                $temp = [];
146
147
                $link_area = $v->find('a', 0);
148
                $temp['title'] = $this->getPromotionTitle($link_area);
149
                $temp['link'] = $this->getPromotionLink($link_area);
150
151
                $promotion[] = $temp;
152
            }
153
        }
154
155
        return $promotion;
156
    }
157
158
    /**
159
     * Get promotional video title.
160
     *
161
     * @param \simplehtmldom_1_5\simple_html_dom $link_area
162
     *
163
     * @return string
164
     */
165
    private function getPromotionTitle($link_area)
166
    {
167
        return $link_area->find('span.title', 0)->plaintext;
168
    }
169
170
    /**
171
     * Get promotional video link.
172
     *
173
     * @param \simplehtmldom_1_5\simple_html_dom $link_area
174
     *
175
     * @return string
176
     */
177
    private function getPromotionLink($link_area)
178
    {
179
        return Helper::videoUrlCleaner($link_area->href);
180
    }
181
182
    /**
183
     * Get anime videos.
184
     *
185
     * @return array
186
     */
187
    private function getAllInfo()
188
    {
189
        return $data = [
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
190
            'episode'   => $this->getEpisode(),
191
            'promotion' => $this->getPromotion(),
192
        ];
193
    }
194
}
195