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

UserListModel   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 93
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllInfo() 0 27 5
A __construct() 0 9 1
A __call() 0 7 2
1
<?php
2
3
namespace MalScraper\Model\User;
4
5
use MalScraper\Helper\Helper;
6
use MalScraper\Model\MainModel;
7
8
/**
9
 * UserListModel class.
10
 */
11
class UserListModel extends MainModel
12
{
13
    /**
14
     * Username.
15
     *
16
     * @var string
17
     */
18
    private $_user;
19
20
    /**
21
     * Either anime or manga.
22
     *
23
     * @var string
24
     */
25
    private $_type;
26
27
    /**
28
     * Anime/manga status.
29
     *
30
     * @var string
31
     */
32
    private $_status;
33
34
    /**
35
     * Default constructor.
36
     *
37
     * @param string $user
38
     * @param string $type
39
     * @param string $status
40
     * @param string $parserArea
41
     *
42
     * @return void
43
     */
44
    public function __construct($user, $type, $status, $parserArea = '#content')
45
    {
46
        $this->_user = $user;
47
        $this->_type = $type;
48
        $this->_status = $status;
49
        $this->_url = $this->_myAnimeListUrl.'/'.$type.'list/'.$user.'?status='.$status;
50
        $this->_parserArea = $parserArea;
51
52
        parent::errorCheck($this);
53
    }
54
55
    /**
56
     * Default call.
57
     *
58
     * @param string $method
59
     * @param array  $arguments
60
     *
61
     * @return array|string|int
62
     */
63
    public function __call($method, $arguments)
64
    {
65
        if ($this->_error) {
66
            return $this->_error;
67
        }
68
69
        return call_user_func_array([$this, $method], $arguments);
70
    }
71
72
    /**
73
     * Get user list.
74
     *
75
     * @return string
76
     */
77
    private function getAllInfo()
78
    {
79
        $data = [];
80
        $offset = 0;
81
        while (true) {
82
            $url = $this->_myAnimeListUrl.'/'.$this->_type.'list/'.$this->_user.'/load.json?offset='.$offset.'&status='.$this->_status;
83
84
            $content = json_decode(file_get_contents($url), true);
85
86
            if ($content) {
87
                for ($i = 0; $i < count($content); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
88
                    if (!empty($content[$i]['anime_image_path'])) {
89
                        $content[$i]['anime_image_path'] = Helper::imageUrlCleaner($content[$i]['anime_image_path']);
90
                    } else {
91
                        $content[$i]['manga_image_path'] = Helper::imageUrlCleaner($content[$i]['manga_image_path']);
92
                    }
93
                }
94
95
                $data = array_merge($data, $content);
96
97
                $offset += 300;
98
            } else {
99
                break;
100
            }
101
        }
102
103
        return $data;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $data returns the type array which is incompatible with the documented return type string.
Loading history...
104
    }
105
}
106