Passed
Push — feature/super-model ( a850c4...c51526 )
by axel
03:11
created

AllProducerModel::getProducerName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MalScraper\Model\Lists;
4
5
use MalScraper\Helper\Helper;
6
use MalScraper\Model\MainModel;
7
8
/**
9
 * AllProducerModel class.
10
 */
11
class AllProducerModel extends MainModel
12
{
13
    /**
14
     * Either anime or manga.
15
     *
16
     * @var string
17
     */
18
	private $_type;
19
20
    /**
21
     * Default constructor.
22
     *
23
     * @param string $type
24
     * @param string $parserArea
25
     *
26
     * @return void
27
     */
28
	public function __construct($type, $parserArea = '.anime-manga-search')
29
    {
30
    	$this->_type = $type;
31
        if ($type == 'anime') {
32
            $this->_url = $this->_myAnimeListUrl.'/anime/producer';
33
        } else {
34
            $this->_url = $this->_myAnimeListUrl.'/manga/magazine';
35
        }
36
    	$this->_parserArea = $parserArea;
37
38
        parent::errorCheck($this);
39
    }
40
41
    /**
42
     * Default call.
43
     *
44
     * @param string $method
45
     * @param array  $arguments
46
     *
47
     * @return array|string|int
48
     */
49
    public function __call($method, $arguments)
50
    {
51
        if ($this->_error)
52
            return $this->_error;
53
        return call_user_func_array([$this, $method], $arguments);
54
    }
55
56
    /**
57
     * Get producer id
58
     *
59
     * @param \simplehtmldom_1_5\simple_html_dom $each_studio
60
     *
61
     * @return string
62
     */
63
    private function getProducerId($each_studio)
64
    {
65
        $link = $each_studio->href;
66
        $link = explode('/', $link);
67
        return $link[3];
68
    }
69
70
    /**
71
     * Get producer name
72
     *
73
     * @param \simplehtmldom_1_5\simple_html_dom $each_studio
74
     *
75
     * @return string
76
     */
77
    private function getProducerName($each_studio)
78
    {
79
        $name = $each_studio->plaintext;
80
        return trim(preg_replace('/\([0-9,]+\)/', '', $name));
81
    }
82
83
    /**
84
     * Get producer count
85
     *
86
     * @param \simplehtmldom_1_5\simple_html_dom $each_studio
87
     *
88
     * @return string
89
     */
90
    private function getProducerCount($each_studio)
91
    {
92
        $count = $each_studio->plaintext;
93
        preg_match('/\([0-9,]+\)/', $count, $count);
0 ignored issues
show
Bug introduced by
It seems like $count can also be of type string; however, parameter $matches of preg_match() does only seem to accept array|null, 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

93
        preg_match('/\([0-9,]+\)/', $count, /** @scrutinizer ignore-type */ $count);
Loading history...
94
        $count = substr($count[0], 1, strlen($count[0]) - 2);
95
        return str_replace(',', '', $count);
96
    }
97
98
    /**
99
     * Get list of all [producer].
100
     *
101
     * @return array
102
     */
103
    private function getAllInfo()
104
    {
105
        $data = [];
106
        foreach ($this->_parser->find('.genre-list a') as $each_studio) {
107
            $studio = [];
108
109
            $studio['id'] = $this->getProducerId($each_studio);
110
            $studio['name'] = $this->getProducerName($each_studio);
111
            $studio['count'] = $this->getProducerCount($each_studio);
112
113
            $data[] = $studio;
114
        }
115
        return $data;
116
    }
117
}