Tracker_Stats_Model::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
1
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed');
2
3
class Tracker_Stats_Model extends Tracker_Base_Model {
4 96
	public function __construct() {
5 96
		parent::__construct();
6 96
	}
7
8
	public function get() : array {
9
		if(!($stats = $this->cache->get('site_stats'))) {
10
			$stats = array();
11
12
			//CHECK: Is it possible to merge some of these queries?
13
			$queryUsers = $this->db
14
				->select([
0 ignored issues
show
Documentation introduced by
array('COUNT(*) AS total... END) AS active_users') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
15
					'COUNT(*) AS total_users',
16
					'SUM(CASE WHEN api_key IS NOT NULL THEN 1 ELSE 0 END) AS validated_users',
17
					'SUM(CASE WHEN (api_key IS NOT NULL AND from_unixtime(last_login) > DATE_SUB(NOW(), INTERVAL 7 DAY)) THEN 1 ELSE 0 END) AS active_users'
18
				], FALSE)
19
				->from('auth_users')
20
				->get();
21
			$stats = array_merge($stats, $queryUsers->result_array()[0]);
22
23
			$queryCounts = $this->db
24
				->select([
0 ignored issues
show
Documentation introduced by
array('tracker_titles.ti..., 'tracker_sites.site') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25
					'tracker_titles.title',
26
					'COUNT(tracker_chapters.title_id) AS count',
27
					'tracker_sites.site'
28
				], FALSE)
29
				->from('tracker_chapters')
30
				->join('tracker_titles', 'tracker_titles.id = tracker_chapters.title_id', 'left')
31
				->join('tracker_sites','tracker_titles.site_id = tracker_sites.id', 'left')
32
				->where('tracker_sites.status', 'enabled')
33
				->group_by('tracker_chapters.title_id')
34
				->having('count > 1')
35
				->order_by('count DESC')
36
				->get();
37
			$stats['titles_tracked_more'] = count($queryCounts->result_array());
38
			$stats['top_title_name']  = $queryCounts->result_array()[0]['title'] ?? 'N/A';
39
			$stats['top_title_site']  = $queryCounts->result_array()[0]['site'] ?? 'N/A';
40
			$stats['top_title_count'] = $queryCounts->result_array()[0]['count'] ?? 'N/A';
41
42
			$queryTitles = $this->db
43
				->select([
0 ignored issues
show
Documentation introduced by
array('COUNT(DISTINCT tr...ND) AS updated_titles') is of type array<integer,string,{"0..."string","3":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
					'COUNT(DISTINCT tracker_titles.id) AS total_titles',
45
					'COUNT(DISTINCT tracker_titles.site_id) AS total_sites',
46
					'SUM(CASE WHEN from_unixtime(auth_users.last_login) > DATE_SUB(NOW(), INTERVAL 120 HOUR) IS NOT NULL THEN 0 ELSE 1 END) AS inactive_titles',
47
					'SUM(CASE WHEN (tracker_titles.last_updated > DATE_SUB(NOW(), INTERVAL 24 HOUR)) THEN 1 ELSE 0 END) AS updated_titles'
48
				], FALSE)
49
				->from('tracker_titles')
50
				->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left')
51
				->join('tracker_chapters', 'tracker_titles.id = tracker_chapters.title_id', 'left')
52
				->join('auth_users', 'tracker_chapters.user_id = auth_users.id', 'left')
53
				->where('tracker_sites.status', 'enabled')
54
				->get();
55
			$stats = array_merge($stats, $queryTitles->result_array()[0]);
56
57
			$querySites = $this->db
58
				->select([
0 ignored issues
show
Documentation introduced by
array('tracker_sites.site', 'COUNT(*) AS count') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
					'tracker_sites.site',
60
					'COUNT(*) AS count'
61
				], FALSE)
62
				->from('tracker_titles')
63
				->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left')
64
				->where('tracker_sites.status', 'enabled')
65
				->group_by('tracker_titles.site_id')
66
				->order_by('count DESC')
67
				->limit(3)
68
				->get();
69
			$querySitesResult = $querySites->result_array();
70
			$stats['rank1_site']       = $querySitesResult[0]['site'];
71
			$stats['rank1_site_count'] = $querySitesResult[0]['count'];
72
			$stats['rank2_site']       = $querySitesResult[1]['site'];
73
			$stats['rank2_site_count'] = $querySitesResult[1]['count'];
74
			$stats['rank3_site']       = $querySitesResult[2]['site'];
75
			$stats['rank3_site_count'] = $querySitesResult[2]['count'];
76
77
			$queryTitlesU = $this->db
78
				->select([
0 ignored issues
show
Documentation introduced by
array('COUNT(*) AS title_updated_count') is of type array<integer,string,{"0":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
					'COUNT(*) AS title_updated_count'
80
				], FALSE)
81
				->from('tracker_titles_history')
82
				->get();
83
			$stats = array_merge($stats, $queryTitlesU->result_array()[0]);
84
85
			$queryUsersU = $this->db
86
				->select([
0 ignored issues
show
Documentation introduced by
array('COUNT(*) AS user_updated_count') is of type array<integer,string,{"0":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
87
					'COUNT(*) AS user_updated_count'
88
				], FALSE)
89
				->from('tracker_user_history')
90
				->get();
91
			$stats = array_merge($stats, $queryUsersU->result_array()[0]);
92
93
			$stats['live_time'] = timespan(/*2016-09-10T03:17:19*/ 1473477439, time(), 2);
94
95
			$this->cache->save('site_stats', $stats, 3600); //Cache for an hour
96
		}
97
98
		return $stats;
99
	}
100
}
101