Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ jobs:
uses: matomo-org/plugin-ci-workflows/.github/workflows/plugin-ci.yml@main
with:
plugin-name: DeviceDetectorCache
# PHPStan has never run here and there is no phpstan.neon to run it with;
# adding one is a decision of its own.
skip-phpstan: true
2 changes: 1 addition & 1 deletion CachedEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CachedEntry extends DeviceDetector
private static $CACHE_DIR = '';
private static $customCache = null;

public function __construct(string $userAgent, $clientHints, array $values)
public function __construct(string $userAgent, array $clientHints, array $values)
{
$clientHints = $clientHints ? ClientHints::factory($clientHints) : null;
parent::__construct($userAgent, $clientHints);
Expand Down
2 changes: 1 addition & 1 deletion Commands/WarmDeviceDetectorCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected function doExecute(): int
if ($i <= 10) {
$this->log('Found user agent ' . $agent . ' count: ' . $val);
}
CachedEntry::writeToCache($agent, []);
CachedEntry::writeToCache($agent);
// sleep 2ms to let CPU do something else
// this will make things about 10m slower for 200K entries but at least sudden CPU increase for instance
// can be prevented when there are only few CPUs available
Expand Down
4 changes: 2 additions & 2 deletions Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ public function getAccessLogRegex()
}

/**
* @return string
* @return int
*/
public function getRegexMatchEntry()
{
return (int)$this->getConfigValue(self::KEY_ACCESS_LOG_REGEX_MATCH_ENTRY, self::DEFAULT_ACCESS_LOG_REGEX_MATCH_ENTRY);
}

/**
* @return string
* @return int
*/
public function getNumEntriesToCache()
{
Expand Down
19 changes: 19 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
level: 5
phpVersion: 80100
tmpDir: /tmp/phpstan/DeviceDetectorCache/main
paths:
- .
excludePaths:
- tests/*
# The shared workflow leaves this helper checkout in the workspace, and `paths: .`
# would otherwise analyse it as if it were plugin code.
- github-action-tests/*
bootstrapFiles:
- ../../bootstrap-phpstan.php
universalObjectCratesClasses:
- Piwik\Config
- Piwik\View
- Piwik\ViewDataTable\Config
scanDirectories:
- ../../
26 changes: 13 additions & 13 deletions tests/Integration/CachedEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ public function testGetNumCacheFiles_noneCached()

public function testGetNumCacheFiles()
{
CachedEntry::writeToCache('foo', []);
CachedEntry::writeToCache('foo');
$this->assertEquals(1, CachedEntry::getNumEntriesInCacheDir());
CachedEntry::writeToCache('bar', []);
CachedEntry::writeToCache('bar');
$this->assertEquals(2, CachedEntry::getNumEntriesInCacheDir());
CachedEntry::writeToCache('baz', []);
CachedEntry::writeToCache('baz');
$this->assertEquals(3, CachedEntry::getNumEntriesInCacheDir());
}

Expand All @@ -180,7 +180,7 @@ public function testGetCached_noEntry()

public function test_writeToCache_GetCached()
{
CachedEntry::writeToCache('foo', []);
CachedEntry::writeToCache('foo');
$cacheEntry = CachedEntry::getCached('foo', []);
$this->assertEquals(
[
Expand Down Expand Up @@ -212,7 +212,7 @@ public function test_getCacheDir()

public function test_deleteLeastAccessedFiles_nothingToDelete()
{
$filePath = CachedEntry::writeToCache('file', []);
$filePath = CachedEntry::writeToCache('file');
$this->assertFileExists($filePath);

CachedEntry::deleteLeastAccessedFiles(-1);
Expand All @@ -223,13 +223,13 @@ public function test_deleteLeastAccessedFiles_nothingToDelete()

public function test_deleteLeastAccessedFiles_deletesOnlyOldest()
{
$filePath1 = CachedEntry::writeToCache('file', []);
$filePath1 = CachedEntry::writeToCache('file');
sleep(1); // otherwise without sleep the sorting won't work properly
$filePath2 = CachedEntry::writeToCache('bar', []);
$filePath2 = CachedEntry::writeToCache('bar');
sleep(1);
$filePath3 = CachedEntry::writeToCache('baz', []);
$filePath3 = CachedEntry::writeToCache('baz');
sleep(1);
$filePath4 = CachedEntry::writeToCache('foo', []);
$filePath4 = CachedEntry::writeToCache('foo');
sleep(1);

CachedEntry::deleteLeastAccessedFiles(2);
Expand All @@ -242,13 +242,13 @@ public function test_deleteLeastAccessedFiles_deletesOnlyOldest()

public function test_deleteLeastAccessedFiles_deletesOnlyOldest2()
{
$filePath1 = CachedEntry::writeToCache('file', []);
$filePath1 = CachedEntry::writeToCache('file');
sleep(1);
$filePath2 = CachedEntry::writeToCache('bar', []);
$filePath2 = CachedEntry::writeToCache('bar');
sleep(1);
$filePath3 = CachedEntry::writeToCache('baz', []);
$filePath3 = CachedEntry::writeToCache('baz');
sleep(1);
$filePath4 = CachedEntry::writeToCache('foo', []);
$filePath4 = CachedEntry::writeToCache('foo');
sleep(1);

touch($filePath1);
Expand Down
Loading