Completed
Pull Request — master (#108)
by
unknown
02:32
created

ReadMangaToday::getTitleData()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 18
nc 4
nop 2
dl 0
loc 27
ccs 0
cts 18
cp 0
crap 12
rs 8.8571
c 0
b 0
f 0
1
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed');
2
3
class ReadMangaToday extends Base_Site_Model {
4
	public $titleFormat   = '/^[a-zA-Z0-9_-]+$/';
5
	public $chapterFormat = '/^[0-9\.]+$/';
6
7
	public function getFullTitleURL(string $title_url) : string {
8
		return "http://www.readmanga.today/{$title_url}";
9
	}
10
11
	public function getChapterData(string $title_url, string $chapter) : array {
12
		//http://www.readmanga.today/saiki-kusuo-no-psi-nan/128
13
		return [
14
			'url'    => $this->getFullTitleURL($title_url).'/'.$chapter,
15
			'number' => "c{$chapter}"
16
		];
17
	}
18
19
	public function getTitleData(string $title_url, bool $firstGet = FALSE) : ?array {
20
		$titleData = [];
21
22
		$fullURL = $this->getFullTitleURL($title_url);
23
24
		$content = $this->get_content($fullURL);
25
26
		$data = $this->parseTitleDataDOM(
27
			$content,
0 ignored issues
show
Security Bug introduced by
It seems like $content defined by $this->get_content($fullURL) on line 24 can also be of type false; however, Base_Site_Model::parseTitleDataDOM() does only seem to accept array, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
28
			$title_url,
29
			"//body/div[@class='content']/div/div/div/div/div/div/div/div/h1",
30
			"//ul[contains(@class, 'chp_lst')]/li[1]/a[1]",
31
			"span[@class='dte']",
32
			"",
33
			"404 Page Not Found"
34
		);
35
		if($data) {
36
			$titleData['title'] = trim($data['nodes_title']->textContent);
37
38
			$titleData['latest_chapter'] = preg_replace('/^.*\/([0-9\.]+)$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
39
40
			$dateString = $data['nodes_latest']->nodeValue;
41
			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime(preg_replace('/ (-|\[A\]).*$/', '', $dateString)));
42
		}
43
44
		return (!empty($titleData) ? $titleData : NULL);
45
	}
46
}
47