diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1074ce56..fdb9b3bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CachedEntry.php b/CachedEntry.php index 5291e71a..e3ae19d2 100644 --- a/CachedEntry.php +++ b/CachedEntry.php @@ -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); diff --git a/Commands/WarmDeviceDetectorCache.php b/Commands/WarmDeviceDetectorCache.php index 336d9c49..681589f7 100644 --- a/Commands/WarmDeviceDetectorCache.php +++ b/Commands/WarmDeviceDetectorCache.php @@ -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 diff --git a/Configuration.php b/Configuration.php index c95cb1a5..be117dec 100644 --- a/Configuration.php +++ b/Configuration.php @@ -78,7 +78,7 @@ public function getAccessLogRegex() } /** - * @return string + * @return int */ public function getRegexMatchEntry() { @@ -86,7 +86,7 @@ public function getRegexMatchEntry() } /** - * @return string + * @return int */ public function getNumEntriesToCache() { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..6058b356 --- /dev/null +++ b/phpstan.neon @@ -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: + - ../../ diff --git a/tests/Integration/CachedEntryTest.php b/tests/Integration/CachedEntryTest.php index c2e29043..32393a2d 100644 --- a/tests/Integration/CachedEntryTest.php +++ b/tests/Integration/CachedEntryTest.php @@ -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()); } @@ -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( [ @@ -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); @@ -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); @@ -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);