Skip to content

Commit 18c1056

Browse files
committed
(doc): classes and methods annotations, and small tweaks
\Core\Analytics, \Core\Boost, \Core\Config
1 parent 54f1b61 commit 18c1056

19 files changed

Lines changed: 519 additions & 300 deletions

Core/Analytics/App.php

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
2-
/**
3-
* Minds Analytics: Global factory
4-
*/
52
namespace Minds\Core\Analytics;
63

74
use Minds\Core;
85
use Minds\Interfaces\AnalyticsMetric;
96

7+
/**
8+
* Global Factory for Analytics
9+
*/
1010
class App
1111
{
1212
private static $_;
@@ -18,6 +18,11 @@ public function __construct()
1818
{
1919
}
2020

21+
/**
22+
* Instanciates a new Metrics class
23+
* @param string|AnalyticsMetric $metric - Metric class name or instance
24+
* @return $this
25+
*/
2126
public function setMetric($metric)
2227
{
2328
if (is_string($metric)) {
@@ -35,6 +40,10 @@ public function setMetric($metric)
3540
return $this;
3641
}
3742

43+
/**
44+
* Sets metric key
45+
* @param string $key
46+
*/
3847
public function setKey($key)
3948
{
4049
$this->key = $key;
@@ -44,36 +53,45 @@ public function setKey($key)
4453
return $this;
4554
}
4655

56+
/**
57+
* Increments metric counter
58+
* @return mixed
59+
*/
4760
public function increment()
4861
{
4962
return $this->metric->increment();
5063
}
5164

52-
/**
53-
* Return a set of analytics for a timespan
54-
* @param int $span - eg. 3 (will return 3 units, eg 3 day, 3 months)
55-
* @param string $unit - eg. day, month, year
56-
* @param int $timestamp (optional) - sets the base to work off
57-
* @return array
58-
*/
59-
public function get($span = 3, $unit = "day", $timestamp = null)
60-
{
61-
return $this->metric->get($span, $unit, $timestamp);
62-
}
65+
/**
66+
* Return a set of analytics for a timespan
67+
* @param int $span - eg. 3 (will return 3 units, eg 3 day, 3 months)
68+
* @param string $unit - eg. day, month, year
69+
* @param int $timestamp (optional) - sets the base to work off
70+
* @return array
71+
*/
72+
public function get($span = 3, $unit = "day", $timestamp = null)
73+
{
74+
return $this->metric->get($span, $unit, $timestamp);
75+
}
6376

77+
/**
78+
* Returns the total for a metric counter
79+
* @return int
80+
*/
6481
public function total()
6582
{
6683
return $this->metric->total();
6784
}
6885

69-
/**
70-
* Factory builder
71-
*/
72-
public static function _()
73-
{
74-
if (!self::$_) {
75-
self::$_ = new App();
76-
}
77-
return self::$_;
78-
}
86+
/**
87+
* Factory singleton builder
88+
* @return static
89+
*/
90+
public static function _()
91+
{
92+
if (!self::$_) {
93+
self::$_ = new App();
94+
}
95+
return self::$_;
96+
}
7997
}

Core/Analytics/Iterators/SignupsIterator.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Minds\Core\Data;
77
use Minds\Core\Analytics\Timestamps;
88

9+
/**
10+
* Iterator that loops through all signups
11+
*/
912
class SignupsIterator implements \Iterator
1013
{
1114
private $cursor = -1;
@@ -23,12 +26,20 @@ public function __construct($db = null)
2326
$this->position = 0;
2427
}
2528

29+
/**
30+
* Sets the period to cycle through
31+
* @param string $period
32+
*/
2633
public function setPeriod($period = null)
2734
{
2835
$this->period = $period;
2936
$this->getUsers();
3037
}
3138

39+
/**
40+
* Fetch all the users who signed up
41+
* @return array
42+
*/
3243
protected function getUsers()
3344
{
3445
//$this->cursor = -1;
@@ -61,6 +72,10 @@ protected function getUsers()
6172
$this->offset = end($users)->guid;
6273
}
6374

75+
/**
76+
* Rewind the array cursor
77+
* @return null
78+
*/
6479
public function rewind()
6580
{
6681
if ($this->cursor >= 0) {
@@ -69,16 +84,28 @@ public function rewind()
6984
$this->next();
7085
}
7186

87+
/**
88+
* Get the current cursor's data
89+
* @return mixed
90+
*/
7291
public function current()
7392
{
7493
return $this->data[$this->cursor];
7594
}
7695

96+
/**
97+
* Get cursor's key
98+
* @return mixed
99+
*/
77100
public function key()
78101
{
79102
return $this->cursor;
80103
}
81104

105+
/**
106+
* Goes to the next cursor
107+
* @return null
108+
*/
82109
public function next()
83110
{
84111
$this->cursor++;
@@ -87,6 +114,10 @@ public function next()
87114
}
88115
}
89116

117+
/**
118+
* Checks if the cursor is valid
119+
* @return bool
120+
*/
90121
public function valid()
91122
{
92123
return $this->valid && isset($this->data[$this->cursor]);

Core/Analytics/Iterators/SignupsOffsetIterator.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
2-
/**
3-
* This iterator differs from SignupsIterator in that it goes through all signups after a set period
4-
*/
52
namespace Minds\Core\Analytics\Iterators;
63

74
use Minds\Core;
85
use Minds\Core\Entities;
96
use Minds\Core\Data;
107
use Minds\Core\Analytics\Timestamps;
118

9+
/**
10+
* Iterator that loops through all signups after a set period
11+
*/
1212
class SignupsOffsetIterator implements \Iterator
1313
{
1414
private $cursor = -1;
@@ -27,12 +27,20 @@ public function __construct($db = null)
2727
$this->position = 0;
2828
}
2929

30+
/**
31+
* Sets the period to cycle through
32+
* @param string $period
33+
*/
3034
public function setPeriod($period = null)
3135
{
3236
$this->period = $period;
3337
$this->getUsers();
3438
}
3539

40+
/**
41+
* Fetch all the users who signed up in a certain period
42+
* @return array
43+
*/
3644
protected function getUsers()
3745
{
3846
$timestamps = array_reverse(Timestamps::span($this->period+1, 'day'));
@@ -71,6 +79,10 @@ protected function getUsers()
7179
}
7280
}
7381

82+
/**
83+
* Rewind the array cursor
84+
* @return null
85+
*/
7486
public function rewind()
7587
{
7688
if ($this->cursor >= 0) {
@@ -79,16 +91,28 @@ public function rewind()
7991
$this->next();
8092
}
8193

94+
/**
95+
* Get the current cursor's data
96+
* @return mixed
97+
*/
8298
public function current()
8399
{
84100
return $this->data[$this->cursor];
85101
}
86102

103+
/**
104+
* Get cursor's key
105+
* @return mixed
106+
*/
87107
public function key()
88108
{
89109
return $this->cursor;
90110
}
91111

112+
/**
113+
* Goes to the next cursor
114+
* @return null
115+
*/
92116
public function next()
93117
{
94118
$this->cursor++;
@@ -97,6 +121,10 @@ public function next()
97121
}
98122
}
99123

124+
/**
125+
* Checks if the cursor is valid
126+
* @return bool
127+
*/
100128
public function valid()
101129
{
102130
return $this->valid && isset($this->data[$this->cursor]);

Core/Analytics/Metrics/Active.php

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
2-
/**
3-
* Active Metric
4-
*/
52
namespace Minds\Core\Analytics\Metrics;
63

74
use Minds\Helpers;
85
use Minds\Core;
96
use Minds\Core\Analytics\Timestamps;
107
use Minds\Interfaces\AnalyticsMetric;
118

9+
/**
10+
* Active Metric
11+
*/
1212
class Active implements AnalyticsMetric
1313
{
1414
private $db;
@@ -28,16 +28,28 @@ public function __construct($db = null)
2828
}
2929
}
3030

31+
/**
32+
* Sets the current namespace
33+
* @param string $namesapce
34+
*/
3135
public function setNamespace($namesapce)
3236
{
3337
//$this->namespace = $namespace . ":";
3438
}
3539

40+
/**
41+
* Sets the current key
42+
* @param string $key
43+
*/
3644
public function setKey($key)
3745
{
3846
$this->key = $key;
3947
}
4048

49+
/**
50+
* Increments metric counter
51+
* @return bool
52+
*/
4153
public function increment()
4254
{
4355
foreach (Timestamps::get(array('day', 'month')) as $p => $ts) {
@@ -46,27 +58,31 @@ public function increment()
4658
return true;
4759
}
4860

49-
/**
50-
* Return a set of analytics for a timespan
51-
* @param int $span - eg. 3 (will return 3 units, eg 3 day, 3 months)
52-
* @param string $unit - eg. day, month, year
53-
* @param int $timestamp (optional) - sets the base to work off
54-
* @return array
55-
*/
56-
public function get($span = 3, $unit = 'day', $timestamp = null)
57-
{
58-
$timestamps = Timestamps::span($span, $unit);
59-
$data = array();
60-
foreach ($timestamps as $ts) {
61-
$data[] = array(
62-
'timestamp' => $ts,
63-
'date' => date('d-m-Y', $ts),
64-
'total' => $this->db->countRow("{$this->namespace}active:$unit:$ts")
65-
);
66-
}
67-
return $data;
68-
}
61+
/**
62+
* Return a set of analytics for a timespan
63+
* @param int $span - eg. 3 (will return 3 units, eg 3 day, 3 months)
64+
* @param string $unit - eg. day, month, year
65+
* @param int $timestamp (optional) - sets the base to work off
66+
* @return array
67+
*/
68+
public function get($span = 3, $unit = 'day', $timestamp = null)
69+
{
70+
$timestamps = Timestamps::span($span, $unit);
71+
$data = array();
72+
foreach ($timestamps as $ts) {
73+
$data[] = array(
74+
'timestamp' => $ts,
75+
'date' => date('d-m-Y', $ts),
76+
'total' => $this->db->countRow("{$this->namespace}active:$unit:$ts")
77+
);
78+
}
79+
return $data;
80+
}
6981

82+
/**
83+
* Returns total metric counter
84+
* @return int
85+
*/
7086
public function total()
7187
{
7288
return 0;

0 commit comments

Comments
 (0)