Completed
Push — master ( 222f63...75778e )
by Angus
02:21
created

MerakiScans   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1
1
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed');
2
3
class MerakiScans 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://merakiscans.com/{$title_url}/";
9
	}
10
11
	public function getChapterData(string $title_url, string $chapter) : array {
12
		return [
13
			'url'    => $this->getFullTitleURL($title_url).$chapter.'/',
14
			'number' => "c{$chapter}"
15
		];
16
	}
17
18
	public function getTitleData(string $title_url, bool $firstGet = FALSE) : ?array {
19
		$titleData = [];
20
21
		$fullURL = $this->getFullTitleURL($title_url);
22
23
		$content = $this->get_content($fullURL);
24
25
		$data = $this->parseTitleDataDOM(
26
			$content,
27
			$title_url,
28
			"//h1",
29
			"//ul[contains(@class, 'mng_chp')]/li[1]/a[1]",
30
			"b[@class='dte']",
31
			"",
32
			"404 Page Not Found"
33
		);
34
		if($data) {
35
			$titleData['title'] = trim($data['nodes_title']->textContent);
36
37
			$titleData['latest_chapter'] = preg_replace('/^.*\/([0-9\.]+)\/$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
38
39
			$titleData['last_updated'] =  date("Y-m-d H:i:s", strtotime((string) substr($data['nodes_latest']->getAttribute('title'), 13)));
40
		}
41
42
		return (!empty($titleData) ? $titleData : NULL);
43
	}
44
}
45