mirror of
https://github.com/DanielSiepmann/tracking.git
synced 2024-11-24 22:36:08 +01:00
Add PHPStan to ensure code quality and prevent bugs
This commit is contained in:
parent
e06cc3c5c5
commit
669d75ce86
10 changed files with 49 additions and 24 deletions
3
.github/workflows/ci.yaml
vendored
3
.github/workflows/ci.yaml
vendored
|
@ -15,5 +15,8 @@ jobs:
|
||||||
- name: Test CGL
|
- name: Test CGL
|
||||||
run: ./vendor/bin/phpcs
|
run: ./vendor/bin/phpcs
|
||||||
|
|
||||||
|
- name: Execute PHPStan Code Quality
|
||||||
|
run: ./vendor/bin/phpstan analyse
|
||||||
|
|
||||||
- name: Execute PHPUnit Tests
|
- name: Execute PHPUnit Tests
|
||||||
run: ./vendor/bin/phpunit
|
run: ./vendor/bin/phpunit
|
||||||
|
|
|
@ -110,10 +110,15 @@ class PageViewsBar extends AbstractBarChartWidget
|
||||||
$format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d';
|
$format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d';
|
||||||
|
|
||||||
for ($daysBefore = $days; $daysBefore >= 0; $daysBefore--) {
|
for ($daysBefore = $days; $daysBefore >= 0; $daysBefore--) {
|
||||||
$labels[] = date($format, strtotime('-' . $daysBefore . ' day'));
|
$timeForLabel = strtotime('-' . $daysBefore . ' day');
|
||||||
$startPeriod = strtotime('-' . $daysBefore . ' day 0:00:00');
|
$startPeriod = strtotime('-' . $daysBefore . ' day 0:00:00');
|
||||||
$endPeriod = strtotime('-' . $daysBefore . ' day 23:59:59');
|
$endPeriod = strtotime('-' . $daysBefore . ' day 23:59:59');
|
||||||
|
|
||||||
|
if ($timeForLabel === false || $startPeriod === false || $endPeriod === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$labels[] = date($format, $timeForLabel);
|
||||||
$data[] = $this->getPageViewsInPeriod($startPeriod, $endPeriod);
|
$data[] = $this->getPageViewsInPeriod($startPeriod, $endPeriod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@ use TYPO3\CMS\Core\Utility\ArrayUtility;
|
||||||
|
|
||||||
class SettingsFactory
|
class SettingsFactory
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
private $defaults = [
|
private $defaults = [
|
||||||
'pageViewsBar' => [
|
'pageViewsBar' => [
|
||||||
'periodInDays' => 31,
|
'periodInDays' => 31,
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Pageview
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add(Model $pageview)
|
public function add(Model $pageview): void
|
||||||
{
|
{
|
||||||
$this->connection->insert(
|
$this->connection->insert(
|
||||||
'tx_tracking_pageview',
|
'tx_tracking_pageview',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DanielSiepmann\Tracking\Unit\Domain\Model;
|
namespace DanielSiepmann\Tracking\Tests\Unit\Domain\Model;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
@ -33,7 +33,7 @@ class PageviewTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function canBeCreated()
|
public function canBeCreated(): void
|
||||||
{
|
{
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
$language = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class PageviewTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnsPageUid()
|
public function returnsPageUid(): void
|
||||||
{
|
{
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
$language = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class PageviewTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnsLanguage()
|
public function returnsLanguage(): void
|
||||||
{
|
{
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
$language = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class PageviewTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnsCrdate()
|
public function returnsCrdate(): void
|
||||||
{
|
{
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
$language = $this->prophesize(SiteLanguage::class);
|
||||||
$crdate = new \DateTimeImmutable();
|
$crdate = new \DateTimeImmutable();
|
||||||
|
@ -110,7 +110,7 @@ class PageviewTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnsPageType()
|
public function returnsPageType(): void
|
||||||
{
|
{
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
$language = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ class PageviewTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnsUrl()
|
public function returnsUrl(): void
|
||||||
{
|
{
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
$language = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ class PageviewTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnsUserAgent()
|
public function returnsUserAgent(): void
|
||||||
{
|
{
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
$language = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DanielSiepmann\Tracking\Unit\Domain\Pageview;
|
namespace DanielSiepmann\Tracking\Tests\Unit\Domain\Pageview;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
@ -36,7 +36,7 @@ class FactoryTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnsPageview()
|
public function returnsPageview(): void
|
||||||
{
|
{
|
||||||
$routing = $this->prophesize(PageArguments::class);
|
$routing = $this->prophesize(PageArguments::class);
|
||||||
$routing->getPageId()->willReturn(10);
|
$routing->getPageId()->willReturn(10);
|
||||||
|
@ -57,7 +57,7 @@ class FactoryTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnedPageviewContainsUserAgent()
|
public function returnedPageviewContainsUserAgent(): void
|
||||||
{
|
{
|
||||||
$routing = $this->prophesize(PageArguments::class);
|
$routing = $this->prophesize(PageArguments::class);
|
||||||
$routing->getPageId()->willReturn(10);
|
$routing->getPageId()->willReturn(10);
|
||||||
|
@ -83,7 +83,7 @@ class FactoryTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnedPageviewContainsUri()
|
public function returnedPageviewContainsUri(): void
|
||||||
{
|
{
|
||||||
$routing = $this->prophesize(PageArguments::class);
|
$routing = $this->prophesize(PageArguments::class);
|
||||||
$routing->getPageId()->willReturn(10);
|
$routing->getPageId()->willReturn(10);
|
||||||
|
@ -107,7 +107,7 @@ class FactoryTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnedPageviewContainsPageType()
|
public function returnedPageviewContainsPageType(): void
|
||||||
{
|
{
|
||||||
$routing = $this->prophesize(PageArguments::class);
|
$routing = $this->prophesize(PageArguments::class);
|
||||||
$routing->getPageId()->willReturn(10);
|
$routing->getPageId()->willReturn(10);
|
||||||
|
@ -131,7 +131,7 @@ class FactoryTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnedPageviewContainsDateTime()
|
public function returnedPageviewContainsDateTime(): void
|
||||||
{
|
{
|
||||||
$routing = $this->prophesize(PageArguments::class);
|
$routing = $this->prophesize(PageArguments::class);
|
||||||
$routing->getPageId()->willReturn(10);
|
$routing->getPageId()->willReturn(10);
|
||||||
|
@ -152,7 +152,7 @@ class FactoryTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnedPageviewContainsLanguage()
|
public function returnedPageviewContainsLanguage(): void
|
||||||
{
|
{
|
||||||
$routing = $this->prophesize(PageArguments::class);
|
$routing = $this->prophesize(PageArguments::class);
|
||||||
$routing->getPageId()->willReturn(10);
|
$routing->getPageId()->willReturn(10);
|
||||||
|
@ -173,7 +173,7 @@ class FactoryTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnedPageviewContainsPageId()
|
public function returnedPageviewContainsPageId(): void
|
||||||
{
|
{
|
||||||
$routing = $this->prophesize(PageArguments::class);
|
$routing = $this->prophesize(PageArguments::class);
|
||||||
$routing->getPageId()->willReturn(10);
|
$routing->getPageId()->willReturn(10);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DanielSiepmann\Tracking\Unit\Domain\Repository;
|
namespace DanielSiepmann\Tracking\Tests\Unit\Domain\Repository;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
@ -35,7 +35,7 @@ class PageviewTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function modelCanBeAdded()
|
public function modelCanBeAdded(): void
|
||||||
{
|
{
|
||||||
$connection = $this->prophesize(Connection::class);
|
$connection = $this->prophesize(Connection::class);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DanielSiepmann\Tracking\Unit\Middleware;
|
namespace DanielSiepmann\Tracking\Tests\Unit\Middleware;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
@ -41,7 +41,7 @@ class PageviewTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function doesNotAddBlacklistedRequest()
|
public function doesNotAddBlacklistedRequest(): void
|
||||||
{
|
{
|
||||||
$repository = $this->prophesize(Repository::class);
|
$repository = $this->prophesize(Repository::class);
|
||||||
$context = $this->prophesize(Context::class);
|
$context = $this->prophesize(Context::class);
|
||||||
|
@ -63,7 +63,7 @@ class PageviewTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function addsPageviewToRepository()
|
public function addsPageviewToRepository(): void
|
||||||
{
|
{
|
||||||
$repository = $this->prophesize(Repository::class);
|
$repository = $this->prophesize(Repository::class);
|
||||||
$context = $this->prophesize(Context::class);
|
$context = $this->prophesize(Context::class);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"doctrine/dbal": "^2.10",
|
"doctrine/dbal": "^2.10",
|
||||||
|
"ext-mbstring": "*",
|
||||||
"php": "^7.3.0",
|
"php": "^7.3.0",
|
||||||
"psr/http-message": "^1.0",
|
"psr/http-message": "^1.0",
|
||||||
"psr/http-server-handler": "^1.0",
|
"psr/http-server-handler": "^1.0",
|
||||||
|
@ -56,6 +57,9 @@
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"squizlabs/php_codesniffer": "^3.5",
|
"squizlabs/php_codesniffer": "^3.5",
|
||||||
"phpunit/phpunit": "^9.0",
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
phpstan.neon
Normal file
10
phpstan.neon
Normal file
|
@ -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\.#'
|
Loading…
Reference in a new issue