Favourites::export()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 18
loc 18
ccs 0
cts 14
cp 0
crap 12
rs 9.6666
c 0
b 0
f 0
1
<?php defined('BASEPATH') or exit('No direct script access allowed');
2
3 View Code Duplication
class Favourites extends Auth_Controller {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4
	public function __construct() {
5
		parent::__construct();
6
	}
7
8
	public function index(int $page = 1) : void {
9
		if($page === 0) redirect('user/favourites/1');
10
11
		$this->header_data['title'] = "Favourites";
12
		$this->header_data['page']  = "favourites";
13
14
		$favouriteData = $this->Tracker->favourites->get($page);
15
		$this->body_data['favouriteData'] = $favouriteData['rows'];
16
		$this->body_data['currentPage'] = $page;
17
		$this->body_data['totalPages']  = $favouriteData['totalPages'];
18
19
		if($page > $this->body_data['totalPages'] && $page <= 1) redirect('user/favourites/1');
20
21
		$this->_render_page('User/Favourites');
22
	}
23
24
	public function export(string $type) : void {
25
		$favouriteData = $this->Tracker->favourites->getAll();
26
27
		switch($type) {
28
			case 'json':
29
				$this->_render_json($favouriteData, TRUE, 'tracker-history');
30
				break;
31
32
			case 'csv':
33
				$this->output->set_content_type('text/csv', 'utf-8');
34
				$this->_render_content($this->Tracker->portation->arrayToCSVRecursive($favouriteData, 'Date/Time,Title,Manga URL,Site,Chapter,Chapter Number, Chapter URL', ',', '"', FALSE, TRUE), 'csv',TRUE, 'tracker-favourite');
35
				break;
36
37
			default:
38
				//404
39
				break;
40
		}
41
	}
42
}
43