Passed
Push — develop ( 5c3296...f8ad08 )
by axel
02:33
created

InfoModel::getRecommendation()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 4
nop 0
dl 0
loc 18
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace MalScraper\Model\General;
4
5
use MalScraper\Helper\Helper;
6
use MalScraper\Model\MainModel;
7
8
/**
9
 * InfoModel class.
10
 */
11
class InfoModel extends MainModel
12
{
13
    /**
14
     * Type of info. Either anime or manga.
15
     *
16
     * @var string
17
     */
18
    private $_type;
19
20
    /**
21
     * Id of the anime or manga.
22
     *
23
     * @var string|int
24
     */
25
    private $_id;
26
27
    /**
28
     * Default constructor.
29
     *
30
     * @param string     $type
31
     * @param string|int $id
32
     * @param string     $parserArea
33
     *
34
     * @return void
35
     */
36
    public function __construct($type, $id, $parserArea = '#content')
37
    {
38
        $this->_type = $type;
39
        $this->_id = $id;
40
        $this->_url = $this->_myAnimeListUrl.'/'.$type.'/'.$id;
41
        $this->_parserArea = $parserArea;
42
43
        parent::errorCheck($this);
44
    }
45
46
    /**
47
     * Default call.
48
     *
49
     * @param string $method
50
     * @param array  $arguments
51
     *
52
     * @return array|string|int
53
     */
54
    public function __call($method, $arguments)
55
    {
56
        if ($this->_error) {
57
            return $this->_error;
58
        }
59
60
        return call_user_func_array([$this, $method], $arguments);
61
    }
62
63
    /**
64
     * Get anime/manga id.
65
     *
66
     * @return string
67
     */
68
    private function getId()
69
    {
70
        return $this->_id;
71
    }
72
73
    /**
74
     * Get anime/manga cover.
75
     *
76
     * @return string|bool
77
     */
78
    private function getCover()
79
    {
80
        $anime_cover = $this->_parser->find('img.ac', 0);
81
82
        return $anime_cover ? $anime_cover->src : '';
83
    }
84
85
    /**
86
     * Get anime/manga title.
87
     *
88
     * @return string|bool
89
     */
90
    private function getTitle()
91
    {
92
        $anime_cover = $this->_parser->find('img.ac', 0);
93
94
        return $anime_cover ? $anime_cover->alt : '';
95
    }
96
97
    /**
98
     * Get anime/manga alternative title.
99
     *
100
     * @return array
101
     */
102
    private function getTitle2()
103
    {
104
        $title2 = [];
105
106
        $anime_info = $this->_parser->find('.js-scrollfix-bottom', 0);
107
108
        $title2['english'] = $this->getTitle3($anime_info, 'English');
109
        $title2['synonym'] = $this->getTitle3($anime_info, 'Synonyms');
110
        $title2['japanese'] = $this->getTitle3($anime_info, 'Japanese');
111
112
        return $title2;
113
    }
114
115
    /**
116
     * Get anime/manga alternative title.
117
     *
118
     * @param \simplehtmldom_1_5\simple_html_dom $anime_info
119
     * @param string                             $type
120
     *
121
     * @return array
122
     */
123
    private function getTitle3($anime_info, $type)
124
    {
125
        preg_match('/('.$type.':<\/span>)([^<]*)/', $anime_info->innertext, $title);
126
127
        return trim($title ? $title[2] : '');
0 ignored issues
show
Bug Best Practice introduced by
The expression return trim($title ? $title[2] : '') returns the type string which is incompatible with the documented return type array.
Loading history...
128
    }
129
130
    /**
131
     * Get anime/manga promotional video.
132
     *
133
     * @return string
134
     */
135
    private function getVideo()
136
    {
137
        $video_area = $this->_parser->find('.video-promotion', 0);
138
        if ($video_area) {
139
            $video = $video_area->find('a', 0)->href;
140
141
            return Helper::videoUrlCleaner($video);
142
        }
143
144
        return '';
145
    }
146
147
    /**
148
     * Get anime/manga synopsis.
149
     *
150
     * @return string
151
     */
152
    private function getSynopsis()
153
    {
154
        $synopsis = $this->_parser->find('span[itemprop=description]', 0);
155
        if ($synopsis) {
156
            $synopsis = $synopsis->plaintext;
157
158
            return trim(preg_replace('/\n[^\S\n]*/', "\n", $synopsis));
159
        } else {
160
            return;
161
        }
162
    }
163
164
    /**
165
     * Get anime/manga score.
166
     *
167
     * @return string
168
     */
169
    private function getScore()
170
    {
171
        $score = $this->_parser->find('div[class="fl-l score"]', 0)->plaintext;
172
        $score = trim($score);
173
174
        return $score != 'N/A' ? $score : null;
175
    }
176
177
    /**
178
     * Get number of user who give score.
179
     *
180
     * @return string
181
     */
182
    private function getVoter()
183
    {
184
        $voter = $this->_parser->find('div[class="fl-l score"]', 0)->getAttribute('data-user');
185
186
        return trim(str_replace(['users', 'user', ','], '', $voter));
187
    }
188
189
    /**
190
     * Get anime/manga rank.
191
     *
192
     * @return string
193
     */
194
    private function getRank()
195
    {
196
        $rank = $this->_parser->find('span[class="numbers ranked"] strong', 0)->plaintext;
197
        $rank = $rank != 'N/A' ? $rank : '';
198
199
        return str_replace('#', '', $rank);
200
    }
201
202
    /**
203
     * Get anime/manga popularity.
204
     *
205
     * @return string
206
     */
207
    private function getPopularity()
208
    {
209
        $popularity = $this->_parser->find('span[class="numbers popularity"] strong', 0)->plaintext;
210
211
        return str_replace('#', '', $popularity);
212
    }
213
214
    /**
215
     * Get number of user who watch/read the anime/manga.
216
     *
217
     * @return string
218
     */
219
    private function getMembers()
220
    {
221
        $member = $this->_parser->find('span[class="numbers members"] strong', 0)->plaintext;
222
223
        return str_replace(',', '', $member);
224
    }
225
226
    /**
227
     * Get number of user who favorite the anime/manga.
228
     *
229
     * @return string
230
     */
231
    private function getFavorite()
232
    {
233
        $favorite = $this->_parser->find('div[data-id=info2]', 0)->next_sibling()->next_sibling()->next_sibling();
234
        $favorite_title = $favorite->find('span', 0)->plaintext;
235
        $favorite = $favorite->plaintext;
236
        $favorite = trim(str_replace($favorite_title, '', $favorite));
237
        $favorite = str_replace(',', '', $favorite);
238
239
        return preg_replace("/([\s])+/", ' ', $favorite);
240
    }
241
242
    /**
243
     * Get anime/manga detail info.
244
     *
245
     * @return array
246
     */
247
    private function getOtherInfo()
248
    {
249
        $info = [];
250
251
        $anime_info = $this->_parser->find('.js-scrollfix-bottom', 0);
252
        $other_info = (count($anime_info->find('h2')) > 2) ? $anime_info->find('h2', 1) : $anime_info->find('h2', 0);
0 ignored issues
show
Bug introduced by
It seems like $anime_info->find('h2') can also be of type simplehtmldom_1_5\simple_html_dom_node; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

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

252
        $other_info = (count(/** @scrutinizer ignore-type */ $anime_info->find('h2')) > 2) ? $anime_info->find('h2', 1) : $anime_info->find('h2', 0);
Loading history...
253
        $next_info = $other_info->next_sibling();
0 ignored issues
show
Bug introduced by
The method next_sibling() does not exist on null. ( Ignorable by Annotation )

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

253
        /** @scrutinizer ignore-call */ 
254
        $next_info = $other_info->next_sibling();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
254
        while (true) {
255
            $info_type = $next_info->find('span', 0)->plaintext;
256
257
            $clean_info_type = strtolower(str_replace(': ', '', $info_type));
258
            $clean_info_value = $this->getCleanInfo($info_type, $next_info);
259
            $clean_info_value = $this->getCleanerInfo1($clean_info_type, $clean_info_value);
260
            $clean_info_value = $this->getCleanerInfo2($next_info, $clean_info_type, $clean_info_value);
261
262
            $info[$clean_info_type] = $clean_info_value;
263
264
            $next_info = $next_info->next_sibling();
265
            if ($next_info->tag == 'h2' || $next_info->tag == 'br') {
266
                break;
267
            }
268
        }
269
270
        return $info;
271
    }
272
273
    /**
274
     * Get clean other info.
275
     *
276
     * @param string                             $info_type
277
     * @param \simplehtmldom_1_5\simple_html_dom $next_info
278
     *
279
     * @return string
280
     */
281
    private function getCleanInfo($info_type, $next_info)
282
    {
283
        $info_value = $next_info->plaintext;
284
        $clean_info_value = trim(str_replace($info_type, '', $info_value));
285
        $clean_info_value = preg_replace("/([\s])+/", ' ', $clean_info_value);
286
287
        return str_replace([', add some', '?', 'Not yet aired', 'Unknown'], '', $clean_info_value);
288
    }
289
290
    /**
291
     * Get cleaner other info.
292
     *
293
     * @param string $clean_info_type
294
     * @param string $clean_info_value
295
     *
296
     * @return string|array
297
     */
298
    private function getCleanerInfo1($clean_info_type, $clean_info_value)
299
    {
300
        if ($clean_info_type == 'published' || $clean_info_type == 'aired') {
301
            $start_air = $end_air = '';
302
            if ($clean_info_value != 'Not available') {
303
                $parsed_airing = explode(' to ', $clean_info_value);
304
                $start_air = ($parsed_airing[0] != '?') ? $parsed_airing[0] : '';
305
                if (count($parsed_airing) > 1) {
306
                    $end_air = ($parsed_airing[1] != '?') ? $parsed_airing[1] : '';
307
                }
308
            }
309
310
            $clean_info_value = [];
311
            $clean_info_value['start'] = $start_air;
312
            $clean_info_value['end'] = $end_air;
313
        }
314
315
        return $clean_info_value;
316
    }
317
318
    /**
319
     * Get cleaner other info.
320
     *
321
     * @param \simplehtmldom_1_5\simple_html_dom $next_info
322
     * @param string                             $clean_info_type
323
     * @param string|array                       $clean_info_value
324
     *
325
     * @return string|array
326
     */
327
    private function getCleanerInfo2($next_info, $clean_info_type, $clean_info_value)
328
    {
329
        if ($clean_info_type == 'producers'
330
            || $clean_info_type == 'licensors'
331
            || $clean_info_type == 'studios'
332
            || $clean_info_type == 'genres'
333
            || $clean_info_type == 'authors'
334
        ) {
335
            $info_temp = [];
336
            $info_temp_index = 0;
337
            if ($clean_info_value != 'None found') {
338
                foreach ($next_info->find('a') as $each_info) {
339
                    $temp_id = explode('/', $each_info->href);
340
                    $info_temp[$info_temp_index]['id'] = $clean_info_type == 'authors' ? $temp_id[2] : $temp_id[3];
341
                    $info_temp[$info_temp_index]['name'] = $each_info->plaintext;
342
                    $info_temp_index++;
343
                }
344
            }
345
346
            return $info_temp;
347
        }
348
349
        return $clean_info_value;
350
    }
351
352
    /**
353
     * Get anime/manga relation.
354
     *
355
     * @return array
356
     */
357
    private function getRelated()
358
    {
359
        $related = [];
360
        $related_area = $this->_parser->find('.anime_detail_related_anime', 0);
361
        if ($related_area) {
362
            foreach ($related_area->find('tr') as $rel) {
363
                $rel_type = $rel->find('td', 0)->plaintext;
364
                $rel_type = trim(strtolower(str_replace(':', '', $rel_type)));
365
366
                $each_rel = [];
367
                $each_rel_index = 0;
368
                $rel_anime = $rel->find('td', 1);
369
                foreach ($rel_anime->find('a') as $r) {
370
                    $each_rel[$each_rel_index] = $this->getRelatedDetail($r);
371
                    $each_rel_index++;
372
                }
373
374
                $related[$rel_type] = $each_rel;
375
            }
376
        }
377
378
        return $related;
379
    }
380
381
    /**
382
     * Get related detail.
383
     *
384
     * @param \simplehtmldom_1_5\simple_html_dom $r
385
     *
386
     * @return array
387
     */
388
    private function getRelatedDetail($r)
389
    {
390
        $related = [];
391
        $rel_anime_link = $r->href;
392
        $separated_anime_link = explode('/', $rel_anime_link);
393
394
        $related['id'] = $separated_anime_link[2];
395
        $related['title'] = $r->plaintext;
396
        $related['type'] = $separated_anime_link[1];
397
398
        return $related;
399
    }
400
401
    /**
402
     * Get anime/manga character and its va.
403
     *
404
     * @return array
405
     */
406
    private function getCharacter()
407
    {
408
        $character = [];
409
        $char_index = 0;
410
        $character_area = $this->_parser->find('div[class^=detail-characters-list]', 0);
411
        if ($character_area) {
412
            $character_list = [
413
                $character_area->find('div[class*=fl-l]', 0),
414
                $character_area->find('div[class*=fl-r]', 0),
415
            ];
416
            foreach ($character_list as $character_side) {
417
                if ($character_side) {
418
                    foreach ($character_side->find('table[width=100%]') as $each_char) {
419
                        $char = $each_char->find('tr td', 1);
420
                        $va = $each_char->find('table td', 0);
421
422
                        $character[$char_index]['id'] = $this->getStaffId($char);
423
                        $character[$char_index]['name'] = $this->getStaffName($char);
424
                        $character[$char_index]['role'] = $this->getStaffRole($char);
425
                        $character[$char_index]['image'] = $this->getStaffImage($each_char);
426
427
                        $character[$char_index]['va_id'] = $character[$char_index]['va_name'] = '';
428
                        $character[$char_index]['va_role'] = $character[$char_index]['va_image'] = '';
429
430
                        if ($va) {
431
                            $character[$char_index]['va_id'] = $this->getStaffId($va);
432
                            $character[$char_index]['va_name'] = $this->getStaffName($va, true);
433
                            $character[$char_index]['va_role'] = $this->getStaffRole($va);
434
                            $character[$char_index]['va_image'] = $this->getStaffImage($each_char, true);
435
                        }
436
437
                        $char_index++;
438
                    }
439
                }
440
            }
441
        }
442
443
        return $character;
444
    }
445
446
    /**
447
     * Get anime/manga staff involved.
448
     *
449
     * @return array
450
     */
451
    private function getStaff()
452
    {
453
        $staff = [];
454
        $staff_index = 0;
455
        $staff_area = $this->_parser->find('div[class^=detail-characters-list]', 1);
456
        if ($staff_area) {
457
            $staff_list = [
458
                $staff_area->find('div[class*=fl-l]', 0),
459
                $staff_area->find('div[class*=fl-r]', 0),
460
            ];
461
            foreach ($staff_list as $staff_side) {
462
                if ($staff_side) {
463
                    foreach ($staff_side->find('table[width=100%]') as $each_staff) {
464
                        $st = $each_staff->find('tr td', 1);
465
466
                        $staff[$staff_index]['id'] = $this->getStaffId($st);
467
                        $staff[$staff_index]['name'] = $this->getStaffName($st);
468
                        $staff[$staff_index]['role'] = $this->getStaffRole($st);
469
                        $staff[$staff_index]['image'] = $this->getStaffImage($each_staff);
470
471
                        $staff_index++;
472
                    }
473
                }
474
            }
475
        }
476
477
        return $staff;
478
    }
479
480
    /**
481
     * Get staff id.
482
     *
483
     * @param \simplehtmldom_1_5\simple_html_dom $st
484
     *
485
     * @return string
486
     */
487
    private function getStaffId($st)
488
    {
489
        $staff_id = $st->find('a', 0)->href;
490
        $staff_id = explode('/', $staff_id);
491
492
        return $staff_id[4];
493
    }
494
495
    /**
496
     * Get staff name.
497
     *
498
     * @param \simplehtmldom_1_5\simple_html_dom $st
499
     * @param bool                               $va (Optional)
500
     *
501
     * @return string
502
     */
503
    private function getStaffName($st, $va = false)
504
    {
505
        if ($va) {
506
            return $st->find('a', 0)->plaintext;
507
        }
508
509
        return trim(preg_replace('/\s+/', ' ', $st->find('a', 0)->plaintext));
510
    }
511
512
    /**
513
     * Get staff role.
514
     *
515
     * @param \simplehtmldom_1_5\simple_html_dom $st
516
     *
517
     * @return string
518
     */
519
    private function getStaffRole($st)
520
    {
521
        return trim($st->find('small', 0)->plaintext);
522
    }
523
524
    /**
525
     * Get staff image.
526
     *
527
     * @param \simplehtmldom_1_5\simple_html_dom $each_staff
528
     * @param bool                               $va         (Optional)
529
     *
530
     * @return string
531
     */
532
    private function getStaffImage($each_staff, $va = false)
533
    {
534
        if ($va) {
535
            $staff_image = $each_staff->find('table td', 1)->find('img', 0)->getAttribute('data-src');
536
        } else {
537
            $staff_image = $each_staff->find('tr td', 0)->find('img', 0)->getAttribute('data-src');
538
        }
539
540
        return Helper::imageUrlCleaner($staff_image);
541
    }
542
543
    /**
544
     * Get anime/manga opening and ending song.
545
     *
546
     * @return array
547
     */
548
    private function getSong()
549
    {
550
        $song = [];
551
        $song_area = $this->_parser->find('div[class*="theme-songs opnening"]', 0);
552
        if ($song_area) {
553
            foreach ($song_area->find('span.theme-song') as $each_song) {
554
                $each_song = trim(preg_replace('/#\d*:\s/', '', $each_song->plaintext));
555
                $song['opening'][] = $each_song;
556
            }
557
        }
558
559
        $song_area = $this->_parser->find('div[class*="theme-songs ending"]', 0);
560
        if ($song_area) {
561
            foreach ($song_area->find('span.theme-song') as $each_song) {
562
                $each_song = trim(preg_replace('/#\d*:\s/', '', $each_song->plaintext));
563
                $song['closing'][] = $each_song;
564
            }
565
        }
566
567
        return $song;
568
    }
569
570
    /**
571
     * Get anime/manga review.
572
     *
573
     * @return array
574
     */
575
    private function getReview()
576
    {
577
        $review = [];
578
        $review_area = $this->_parser->find('.js-scrollfix-bottom-rel', 0);
579
        $review_area = $review_area->find('table tr', 1);
580
        $review_area = $review_area->find('.borderDark');
581
        foreach ($review_area as $each_review) {
582
            $tmp = [];
583
584
            $top_area = $each_review->find('.spaceit', 0);
585
            $bottom_area = $top_area->next_sibling();
586
            $very_bottom_area = $bottom_area->next_sibling();
587
588
            $tmp['id'] = $this->getReviewId($very_bottom_area);
589
            $tmp['username'] = $this->getReviewUser($top_area);
590
            $tmp['image'] = $this->getReviewImage($top_area);
591
            $tmp['helpful'] = $this->getReviewHelpful($top_area);
592
            $tmp['date'] = $this->getReviewDate($top_area);
593
            if ($this->_type == 'anime') {
594
                $tmp['episode'] = $this->getReviewEpisode($top_area);
595
            } else {
596
                $tmp['chapter'] = $this->getReviewEpisode($top_area);
597
            }
598
            $tmp['score'] = $this->getReviewScore($bottom_area);
599
            $tmp['review'] = $this->getReviewText($bottom_area);
600
601
            $review[] = $tmp;
602
        }
603
604
        return $review;
605
    }
606
607
    /**
608
     * Get review user.
609
     *
610
     * @param \simplehtmldom_1_5\simple_html_dom $very_bottom_area
611
     *
612
     * @return string
613
     */
614
    private function getReviewId($very_bottom_area)
615
    {
616
        $id = $very_bottom_area->find('a', 0)->href;
617
        $id = explode('?id=', $id);
618
619
        return $id[1];
620
    }
621
622
    /**
623
     * Get review id.
624
     *
625
     * @param \simplehtmldom_1_5\simple_html_dom $top_area
626
     *
627
     * @return string
628
     */
629
    private function getReviewUser($top_area)
630
    {
631
        $user = $top_area->find('table', 0);
632
633
        return $user->find('td', 1)->find('a', 0)->plaintext;
634
    }
635
636
    /**
637
     * Get review image.
638
     *
639
     * @param \simplehtmldom_1_5\simple_html_dom $top_area
640
     *
641
     * @return string
642
     */
643
    private function getReviewImage($top_area)
644
    {
645
        $image = $top_area->find('table', 0);
646
        $image = $image->find('td', 0)->find('img', 0)->src;
647
648
        return Helper::imageUrlCleaner($image);
649
    }
650
651
    /**
652
     * Get review helful.
653
     *
654
     * @param \simplehtmldom_1_5\simple_html_dom $top_area
655
     *
656
     * @return string
657
     */
658
    private function getReviewHelpful($top_area)
659
    {
660
        $helpful = $top_area->find('table', 0);
661
        $helpful = $helpful->find('td', 1)->find('strong', 0)->plaintext;
662
663
        return trim($helpful);
664
    }
665
666
    /**
667
     * Get review date.
668
     *
669
     * @param \simplehtmldom_1_5\simple_html_dom $top_area
670
     *
671
     * @return array
672
     */
673
    private function getReviewDate($top_area)
674
    {
675
        $date = $top_area->find('div div', 0);
676
677
        return [
678
            'date' => $date->plaintext,
679
            'time' => $date->title,
680
        ];
681
    }
682
683
    /**
684
     * Get review episode seen.
685
     *
686
     * @param \simplehtmldom_1_5\simple_html_dom $top_area
687
     *
688
     * @return string
689
     */
690
    private function getReviewEpisode($top_area)
691
    {
692
        $episode = $top_area->find('div div', 1)->plaintext;
693
        $episode = str_replace(['episodes seen', 'chapters read'], '', $episode);
694
695
        return trim($episode);
696
    }
697
698
    /**
699
     * Get review score.
700
     *
701
     * @param \simplehtmldom_1_5\simple_html_dom $bottom_area
702
     *
703
     * @return array
704
     */
705
    private function getReviewScore($bottom_area)
706
    {
707
        $score = [];
708
        $score_area = $bottom_area->find('table', 0);
709
        if ($score_area) {
710
            foreach ($score_area->find('tr') as $each_score) {
711
                $score_type = strtolower($each_score->find('td', 0)->plaintext);
712
                $score_value = $each_score->find('td', 1)->plaintext;
713
                $score[$score_type] = $score_value;
714
            }
715
        }
716
717
        return $score;
718
    }
719
720
    /**
721
     * Get review text.
722
     *
723
     * @param \simplehtmldom_1_5\simple_html_dom $bottom_area
724
     *
725
     * @return string
726
     */
727
    private function getReviewText($bottom_area)
728
    {
729
        $useless_area_1 = $bottom_area->find('div', 0)->plaintext;
730
        $useless_area_2 = $bottom_area->find('div[id^=revhelp_output]', 0)->plaintext;
731
        $useless_area_3 = $bottom_area->find('a[id^=reviewToggle]', 0) ? $bottom_area->find('a[id^=reviewToggle]', 0)->plaintext : null;
732
        $text = str_replace([$useless_area_1, $useless_area_2, $useless_area_3], '', $bottom_area->plaintext);
733
        $text = str_replace('&lt;', '<', $text);
734
735
        return trim(preg_replace('/\h+/', ' ', $text));
736
    }
737
738
    /**
739
     * Get anime/manga recommendation.
740
     *
741
     * @return array
742
     */
743
    private function getRecommendation()
744
    {
745
        $recommendation = [];
746
        $recommendation_area = $this->_type == 'anime' ? $this->_parser->find('#anime_recommendation', 0) : $this->_parser->find('#manga_recommendation', 0);
747
        if ($recommendation_area) {
748
            foreach ($recommendation_area->find('li.btn-anime') as $each_recom) {
749
                $tmp = [];
750
751
                $tmp['id'] = $this->getRecomId($each_recom);
752
                $tmp['title'] = $this->getRecomTitle($each_recom);
753
                $tmp['image'] = $this->getRecomImage($each_recom);
754
                $tmp['user'] = $this->getRecomUser($each_recom);
755
756
                $recommendation[] = $tmp;
757
            }
758
        }
759
760
        return $recommendation;
761
    }
762
763
    /**
764
     * Get recommendation id.
765
     *
766
     * @param \simplehtmldom_1_5\simple_html_dom $each_recom
767
     *
768
     * @return string
769
     */
770
    private function getRecomId($each_recom)
771
    {
772
        $id = $each_recom->find('a', 0)->href;
773
        $id = explode('/', $id);
774
        $id = explode('-', $id[5]);
775
        if ($id[0] == $this->_id) {
776
            return $id[1];
777
        } else {
778
            return $id[0];
779
        }
780
    }
781
782
    /**
783
     * Get recommendation title.
784
     *
785
     * @param \simplehtmldom_1_5\simple_html_dom $each_recom
786
     *
787
     * @return string
788
     */
789
    private function getRecomTitle($each_recom)
790
    {
791
        return $each_recom->find('span', 0)->plaintext;
792
    }
793
794
    /**
795
     * Get recommendation image.
796
     *
797
     * @param \simplehtmldom_1_5\simple_html_dom $each_recom
798
     *
799
     * @return string
800
     */
801
    private function getRecomImage($each_recom)
802
    {
803
        $image = $each_recom->find('img', 0)->getAttribute('data-src');
804
805
        return Helper::imageUrlCleaner($image);
806
    }
807
808
    /**
809
     * Get recommendation user.
810
     *
811
     * @param \simplehtmldom_1_5\simple_html_dom $each_recom
812
     *
813
     * @return string
814
     */
815
    private function getRecomUser($each_recom)
816
    {
817
        $user = $each_recom->find('.users', 0)->plaintext;
818
        $user = str_replace(['Users', 'User'], '', $user);
819
820
        return trim($user);
821
    }
822
823
    /**
824
     * Get anime/manga all information.
825
     *
826
     * @return array
827
     */
828
    private function getAllInfo()
829
    {
830
        $data = [
831
            'id'        => $this->getId(),
832
            'cover'     => $this->getCover(),
833
            'title'     => $this->getTitle(),
834
            'title2'    => $this->getTitle2(),
835
            'video'     => $this->getVideo(),
836
            'synopsis'  => $this->getSynopsis(),
837
            'score'     => $this->getScore(),
838
            'voter'     => $this->getVoter(),
839
            'rank'      => $this->getRank(),
840
            'popularity'=> $this->getPopularity(),
841
            'members'   => $this->getMembers(),
842
            'favorite'  => $this->getFavorite(),
843
        ];
844
845
        $data = array_merge($data, $this->getOtherInfo());
846
847
        $data2 = [
848
            'related'        => $this->getRelated(),
849
            'character'      => $this->getCharacter(),
850
            'staff'          => $this->getStaff(),
851
            'song'           => $this->getSong(),
852
            'review'         => $this->getReview(),
853
            'recommendation' => $this->getRecommendation(),
854
        ];
855
856
        $data = array_merge($data, $data2);
857
858
        return $data;
859
    }
860
}
861