From 8b50583254af0b0811d24689e25e978979a05cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Helfensd=C3=B6rfer?= Date: Thu, 1 Aug 2019 21:49:40 +0200 Subject: [PATCH] According to the docs the site ID can be of type int, string or empty, closes #45 --- CHANGELOG.md | 4 ++++ src/Matomo.php | 16 ++++++++-------- tests/MatomoTest.php | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65e7f72..1d4607b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 1.5.2 (2019/08/01) + +* Fixed: The site ID can now be of mixed type again (e.g. 5, "9", "3,24,27", "all") or null + ### 1.5.1 (2019/07/22) * Changed: Moved changelog to separate file diff --git a/src/Matomo.php b/src/Matomo.php index d509443..6b29328 100644 --- a/src/Matomo.php +++ b/src/Matomo.php @@ -12,7 +12,6 @@ */ class Matomo { - const ERROR_INVALID = 10; const ERROR_EMPTY = 11; const PERIOD_DAY = 'day'; @@ -44,7 +43,7 @@ class Matomo private $_token = ''; /** - * @var int The integer id of your website. + * @var mixed The integer id of your website. */ private $_siteId = null; @@ -113,7 +112,7 @@ class Matomo function __construct( $site, $token, - $siteId, + $siteId = null, $format = self::FORMAT_JSON, $period = self::PERIOD_DAY, $date = self::DATE_YESTERDAY, @@ -189,9 +188,9 @@ public function setToken(string $token): Matomo /** * Get current site ID * - * @return int + * @return mixed */ - public function getSiteId(): int + public function getSiteId() { return $this->_siteId; } @@ -199,10 +198,10 @@ public function getSiteId(): int /** * Set current site ID * - * @param int $id + * @param mixed $id * @return $this */ - public function setSiteId(int $id): Matomo + public function setSiteId($id = null): Matomo { $this->_siteId = $id; @@ -3847,7 +3846,8 @@ public function getSitesFromGroup($group, array $optional = []) } /** - * Get all site groups + * Get all site groups. + * Requires superuser access. * * @param array $optional * @return bool|object diff --git a/tests/MatomoTest.php b/tests/MatomoTest.php index ab638af..a56fb0a 100644 --- a/tests/MatomoTest.php +++ b/tests/MatomoTest.php @@ -231,4 +231,20 @@ public function testCustomVariables() $this->assertEquals(15, count($result)); } + + /** + * Test if matamo can be used without the site ID parameter. + * + * @throws InvalidRequestException + */ + public function testEmptySiteId() + { + $matomo = new Matomo(self::TEST_SITE_URL, self::TEST_TOKEN); + $this->assertNull($matomo->getSiteId()); + + $matomo->setSiteId(null); + $this->assertNull($matomo->getSiteId()); + + $this->assertIsObject($matomo->getTimezonesList()); + } }