diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d23e48b..bf97c11 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,5 +15,8 @@ jobs: - name: Test CGL run: ./vendor/bin/phpcs + - name: Execute PHPStan Code Quality + run: ./vendor/bin/phpstan analyse + - name: Execute PHPUnit Tests run: ./vendor/bin/phpunit diff --git a/Classes/Dashboard/Widgets/PageViewsBar.php b/Classes/Dashboard/Widgets/PageViewsBar.php index 5ee4af4..dd8831c 100644 --- a/Classes/Dashboard/Widgets/PageViewsBar.php +++ b/Classes/Dashboard/Widgets/PageViewsBar.php @@ -110,10 +110,15 @@ class PageViewsBar extends AbstractBarChartWidget $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d'; for ($daysBefore = $days; $daysBefore >= 0; $daysBefore--) { - $labels[] = date($format, strtotime('-' . $daysBefore . ' day')); + $timeForLabel = strtotime('-' . $daysBefore . ' day'); $startPeriod = strtotime('-' . $daysBefore . ' day 0:00:00'); $endPeriod = strtotime('-' . $daysBefore . ' day 23:59:59'); + if ($timeForLabel === false || $startPeriod === false || $endPeriod === false) { + continue; + } + + $labels[] = date($format, $timeForLabel); $data[] = $this->getPageViewsInPeriod($startPeriod, $endPeriod); } diff --git a/Classes/Dashboard/Widgets/SettingsFactory.php b/Classes/Dashboard/Widgets/SettingsFactory.php index 0892d80..37cb84d 100644 --- a/Classes/Dashboard/Widgets/SettingsFactory.php +++ b/Classes/Dashboard/Widgets/SettingsFactory.php @@ -25,6 +25,9 @@ use TYPO3\CMS\Core\Utility\ArrayUtility; class SettingsFactory { + /** + * @var array + */ private $defaults = [ 'pageViewsBar' => [ 'periodInDays' => 31, diff --git a/Classes/Domain/Repository/Pageview.php b/Classes/Domain/Repository/Pageview.php index 069d2ff..97af4cc 100644 --- a/Classes/Domain/Repository/Pageview.php +++ b/Classes/Domain/Repository/Pageview.php @@ -36,7 +36,7 @@ class Pageview $this->connection = $connection; } - public function add(Model $pageview) + public function add(Model $pageview): void { $this->connection->insert( 'tx_tracking_pageview', diff --git a/Tests/Unit/Domain/Model/PageviewTest.php b/Tests/Unit/Domain/Model/PageviewTest.php index 87f5b1c..c590f23 100644 --- a/Tests/Unit/Domain/Model/PageviewTest.php +++ b/Tests/Unit/Domain/Model/PageviewTest.php @@ -1,6 +1,6 @@ @@ -33,7 +33,7 @@ class PageviewTest extends TestCase /** * @test */ - public function canBeCreated() + public function canBeCreated(): void { $language = $this->prophesize(SiteLanguage::class); @@ -52,7 +52,7 @@ class PageviewTest extends TestCase /** * @test */ - public function returnsPageUid() + public function returnsPageUid(): void { $language = $this->prophesize(SiteLanguage::class); @@ -71,7 +71,7 @@ class PageviewTest extends TestCase /** * @test */ - public function returnsLanguage() + public function returnsLanguage(): void { $language = $this->prophesize(SiteLanguage::class); @@ -90,7 +90,7 @@ class PageviewTest extends TestCase /** * @test */ - public function returnsCrdate() + public function returnsCrdate(): void { $language = $this->prophesize(SiteLanguage::class); $crdate = new \DateTimeImmutable(); @@ -110,7 +110,7 @@ class PageviewTest extends TestCase /** * @test */ - public function returnsPageType() + public function returnsPageType(): void { $language = $this->prophesize(SiteLanguage::class); @@ -129,7 +129,7 @@ class PageviewTest extends TestCase /** * @test */ - public function returnsUrl() + public function returnsUrl(): void { $language = $this->prophesize(SiteLanguage::class); @@ -148,7 +148,7 @@ class PageviewTest extends TestCase /** * @test */ - public function returnsUserAgent() + public function returnsUserAgent(): void { $language = $this->prophesize(SiteLanguage::class); diff --git a/Tests/Unit/Domain/Pageview/FactoryTest.php b/Tests/Unit/Domain/Pageview/FactoryTest.php index 0c97d35..521144c 100644 --- a/Tests/Unit/Domain/Pageview/FactoryTest.php +++ b/Tests/Unit/Domain/Pageview/FactoryTest.php @@ -1,6 +1,6 @@ @@ -36,7 +36,7 @@ class FactoryTest extends TestCase /** * @test */ - public function returnsPageview() + public function returnsPageview(): void { $routing = $this->prophesize(PageArguments::class); $routing->getPageId()->willReturn(10); @@ -57,7 +57,7 @@ class FactoryTest extends TestCase /** * @test */ - public function returnedPageviewContainsUserAgent() + public function returnedPageviewContainsUserAgent(): void { $routing = $this->prophesize(PageArguments::class); $routing->getPageId()->willReturn(10); @@ -83,7 +83,7 @@ class FactoryTest extends TestCase /** * @test */ - public function returnedPageviewContainsUri() + public function returnedPageviewContainsUri(): void { $routing = $this->prophesize(PageArguments::class); $routing->getPageId()->willReturn(10); @@ -107,7 +107,7 @@ class FactoryTest extends TestCase /** * @test */ - public function returnedPageviewContainsPageType() + public function returnedPageviewContainsPageType(): void { $routing = $this->prophesize(PageArguments::class); $routing->getPageId()->willReturn(10); @@ -131,7 +131,7 @@ class FactoryTest extends TestCase /** * @test */ - public function returnedPageviewContainsDateTime() + public function returnedPageviewContainsDateTime(): void { $routing = $this->prophesize(PageArguments::class); $routing->getPageId()->willReturn(10); @@ -152,7 +152,7 @@ class FactoryTest extends TestCase /** * @test */ - public function returnedPageviewContainsLanguage() + public function returnedPageviewContainsLanguage(): void { $routing = $this->prophesize(PageArguments::class); $routing->getPageId()->willReturn(10); @@ -173,7 +173,7 @@ class FactoryTest extends TestCase /** * @test */ - public function returnedPageviewContainsPageId() + public function returnedPageviewContainsPageId(): void { $routing = $this->prophesize(PageArguments::class); $routing->getPageId()->willReturn(10); diff --git a/Tests/Unit/Domain/Repository/PageviewTest.php b/Tests/Unit/Domain/Repository/PageviewTest.php index bd07858..05e6923 100644 --- a/Tests/Unit/Domain/Repository/PageviewTest.php +++ b/Tests/Unit/Domain/Repository/PageviewTest.php @@ -1,6 +1,6 @@ @@ -35,7 +35,7 @@ class PageviewTest extends TestCase /** * @test */ - public function modelCanBeAdded() + public function modelCanBeAdded(): void { $connection = $this->prophesize(Connection::class); diff --git a/Tests/Unit/Middleware/PageviewTest.php b/Tests/Unit/Middleware/PageviewTest.php index 5f88677..32fb633 100644 --- a/Tests/Unit/Middleware/PageviewTest.php +++ b/Tests/Unit/Middleware/PageviewTest.php @@ -1,6 +1,6 @@ @@ -41,7 +41,7 @@ class PageviewTest extends TestCase /** * @test */ - public function doesNotAddBlacklistedRequest() + public function doesNotAddBlacklistedRequest(): void { $repository = $this->prophesize(Repository::class); $context = $this->prophesize(Context::class); @@ -63,7 +63,7 @@ class PageviewTest extends TestCase /** * @test */ - public function addsPageviewToRepository() + public function addsPageviewToRepository(): void { $repository = $this->prophesize(Repository::class); $context = $this->prophesize(Context::class); diff --git a/composer.json b/composer.json index cd60acf..1a93f84 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ }, "require": { "doctrine/dbal": "^2.10", + "ext-mbstring": "*", "php": "^7.3.0", "psr/http-message": "^1.0", "psr/http-server-handler": "^1.0", @@ -56,6 +57,9 @@ "require-dev": { "squizlabs/php_codesniffer": "^3.5", "phpunit/phpunit": "^9.0", - "typo3/cms-dashboard": "^10.3.0" + "typo3/cms-dashboard": "^10.3.0", + "phpstan/phpstan": "^0.12.18", + "phpstan/extension-installer": "^1.0", + "jangregor/phpstan-prophecy": "^0.6.2" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..51c13e7 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,10 @@ +parameters: + level: max + paths: + - Classes + - Tests + checkGenericClassInNonGenericObjectType: false + checkMissingIterableValueType: false + ignoreErrors: + - '#Cannot call method fetchAll\(\) on Doctrine\\DBAL\\Driver\\Statement\|int\.#' + - '#Cannot call method fetchColumn\(\) on Doctrine\\DBAL\\Driver\\Statement\|int\.#'