Skip to content

Commit 8b50583

Browse files
author
Tim Helfensdörfer
committed
According to the docs the site ID can be of type int, string or empty, closes #45
1 parent 45c4113 commit 8b50583

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### 1.5.2 (2019/08/01)
4+
5+
* Fixed: The site ID can now be of mixed type again (e.g. 5, "9", "3,24,27", "all") or null
6+
37
### 1.5.1 (2019/07/22)
48

59
* Changed: Moved changelog to separate file

src/Matomo.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313
class Matomo
1414
{
15-
const ERROR_INVALID = 10;
1615
const ERROR_EMPTY = 11;
1716

1817
const PERIOD_DAY = 'day';
@@ -44,7 +43,7 @@ class Matomo
4443
private $_token = '';
4544

4645
/**
47-
* @var int The integer id of your website.
46+
* @var mixed The integer id of your website.
4847
*/
4948
private $_siteId = null;
5049

@@ -113,7 +112,7 @@ class Matomo
113112
function __construct(
114113
$site,
115114
$token,
116-
$siteId,
115+
$siteId = null,
117116
$format = self::FORMAT_JSON,
118117
$period = self::PERIOD_DAY,
119118
$date = self::DATE_YESTERDAY,
@@ -189,20 +188,20 @@ public function setToken(string $token): Matomo
189188
/**
190189
* Get current site ID
191190
*
192-
* @return int
191+
* @return mixed
193192
*/
194-
public function getSiteId(): int
193+
public function getSiteId()
195194
{
196195
return $this->_siteId;
197196
}
198197

199198
/**
200199
* Set current site ID
201200
*
202-
* @param int $id
201+
* @param mixed $id
203202
* @return $this
204203
*/
205-
public function setSiteId(int $id): Matomo
204+
public function setSiteId($id = null): Matomo
206205
{
207206
$this->_siteId = $id;
208207

@@ -3847,7 +3846,8 @@ public function getSitesFromGroup($group, array $optional = [])
38473846
}
38483847

38493848
/**
3850-
* Get all site groups
3849+
* Get all site groups.
3850+
* Requires superuser access.
38513851
*
38523852
* @param array $optional
38533853
* @return bool|object

tests/MatomoTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,20 @@ public function testCustomVariables()
231231

232232
$this->assertEquals(15, count($result));
233233
}
234+
235+
/**
236+
* Test if matamo can be used without the site ID parameter.
237+
*
238+
* @throws InvalidRequestException
239+
*/
240+
public function testEmptySiteId()
241+
{
242+
$matomo = new Matomo(self::TEST_SITE_URL, self::TEST_TOKEN);
243+
$this->assertNull($matomo->getSiteId());
244+
245+
$matomo->setSiteId(null);
246+
$this->assertNull($matomo->getSiteId());
247+
248+
$this->assertIsObject($matomo->getTimezonesList());
249+
}
234250
}

0 commit comments

Comments
 (0)