Skip to content

Commit

Permalink
According to the docs the site ID can be of type int, string or empty,
Browse files Browse the repository at this point in the history
…closes #45
  • Loading branch information
thelfensdrfer committed Aug 1, 2019
1 parent 45c4113 commit 8b50583
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/Matomo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
class Matomo
{
const ERROR_INVALID = 10;
const ERROR_EMPTY = 11;

const PERIOD_DAY = 'day';
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -189,20 +188,20 @@ public function setToken(string $token): Matomo
/**
* Get current site ID
*
* @return int
* @return mixed
*/
public function getSiteId(): int
public function getSiteId()
{
return $this->_siteId;
}

/**
* 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;

Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/MatomoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 8b50583

Please sign in to comment.