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

CharacterPeoplePictureModel   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 90
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A getAllInfo() 0 12 4
A __call() 0 5 2
A __construct() 0 12 2
A getId() 0 3 1
1
<?php
2
3
namespace MalScraper\Model\Additional;
4
5
use MalScraper\Helper\Helper;
6
use MalScraper\Model\MainModel;
7
8
/**
9
 * CharacterPeoplePictureModel class.
10
 */
11
class CharacterPeoplePictureModel extends MainModel
12
{
13
    /**
14
     * Type of the picture (either character or people)
15
     *
16
     * @var string
17
     */
18
    private $_type;
19
20
    /**
21
     * Id of the people.
22
     *
23
     * @var string|int
24
     */
25
	private $_id;
26
27
    /**
28
     * Default constructor.
29
     *
30
     * @param string|int $id
31
     * @param string $parserArea
32
     *
33
     * @return void
34
     */
35
	public function __construct($type, $id, $parserArea = '#content table tr td')
36
    {
37
    	$this->_type = $type;
38
        $this->_id = $id;
39
        if ($this->_type == 'people') {
40
            $this->_url = $this->_myAnimeListUrl.'/people/'.$id;
41
        } else {
42
            $this->_url = $this->_myAnimeListUrl.'/character/'.$id;
43
        }
44
        $this->_parserArea = $parserArea;
45
46
        parent::errorCheck($this);
47
    }
48
49
    /**
50
     * Default call.
51
     *
52
     * @param string $method
53
     * @param array  $arguments
54
     *
55
     * @return array|string|int
56
     */
57
    public function __call($method, $arguments)
58
    {
59
        if ($this->_error)
60
            return $this->_error;
61
        return call_user_func_array([$this, $method], $arguments);
62
    }
63
64
    /**
65
     * Get type.
66
     *
67
     * @return string
68
     */
69
    private function getType()
70
    {
71
        return null;
72
    }
73
74
    /**
75
     * Get people id.
76
     *
77
     * @return string
78
     */
79
    private function getId()
80
    {
81
    	return $this->_id;
82
    }
83
84
    /**
85
     * Get people additional pictures.
86
     *
87
     * @return array
88
     */
89
    private function getAllInfo()
90
    {
91
        $data = [];
92
        $picture_table = $this->_parser->find('table', 0);
93
        if ($picture_table) {
94
            foreach ($picture_table->find('img') as $each_picture) {
95
                if ($each_picture) {
96
                    $data[] = $each_picture->src;
97
                }
98
            }
99
        }
100
        return $data;
101
    }
102
}