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
54 changes: 54 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
on:
- push

name: Run PHPStan checks

jobs:
mutation:
name: PHPStan ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.2"
- "8.3"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: pcov
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
tools: composer:v2, cs2pr

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-

- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Setup project
run: |
mv config/autoload/local.php.dist config/autoload/local.php
mv config/autoload/mail.local.php.dist config/autoload/mail.local.php
mv config/autoload/local.test.php.dist config/autoload/local.test.php

- name: Run static analysis with PHPStan
run: vendor/bin/phpstan analyse
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ DotKernel web starter package suitable for admin applications.
[![Build Static](https://github.com/dotkernel/admin/actions/workflows/continuous-integration.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/admin/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/admin/graph/badge.svg?token=BQS43UWAM4)](https://codecov.io/gh/dotkernel/admin)
[![Qodana](https://github.com/dotkernel/admin/actions/workflows/qodana_code_quality.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/admin/actions/workflows/qodana_code_quality.yml)

[![SymfonyInsight](https://insight.symfony.com/projects/6a7ecfc1-a0ed-4901-96ac-d0ff61f7b55f/big.svg)](https://insight.symfony.com/projects/6a7ecfc1-a0ed-4901-96ac-d0ff61f7b55f)
[![PHPStan](https://github.com/dotkernel/admin/actions/workflows/static-analysis.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/admin/actions/workflows/static-analysis.yml)

## Installing DotKernel `admin`

Expand Down
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@
"mezzio/mezzio-tooling": "^2.9.0",
"phpunit/phpunit": "^10.5.9",
"roave/security-advisories": "dev-latest",
"vimeo/psalm": "^5.20.0",
"vincentlanglet/twig-cs-fixer": "^3.0"
"vincentlanglet/twig-cs-fixer": "^3.0",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-doctrine": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"symfony/var-dumper": "^7.1"
},
"autoload": {
"psr-4": {
Expand All @@ -90,13 +93,14 @@
"mezzio": "mezzio --ansi",
"check": [
"@cs-check",
"@test"
"@test",
"@static-analysis"
],
"clear-config-cache": "php bin/clear-config-cache.php",
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"serve": "php -S 0.0.0.0:8080 -t public/",
"static-analysis": "psalm --shepherd --stats",
"static-analysis": "phpstan analyse",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"twig-cs-check": "vendor/bin/twig-cs-fixer lint --config=config/twig-cs-fixer.php",
Expand Down
28 changes: 28 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
level: 5
paths:
- src
- test
treatPhpDocTypesAsCertain: false
ignoreErrors:
- '/Parameter #1 \$inputFilter of method .*::setInputFilter\(\) expects Laminas\\InputFilter\\InputFilterInterface<[^>]+>, [^ ]+ given\./'
- '/Parameter #1 \$expected of method PHPUnit\\Framework\\Assert::assertSame\(\) contains unresolvable type\./'
-
message: '#Call to method PHPUnit\\Framework\\Assert::assertInstanceOf\(\) with .* will always evaluate to true.#'
path: test
-
message: '#Call to an undefined method Laminas\\InputFilter\\InputFilterInterface::getInputs\(\)#'
path: test
-
message: '#Call to an undefined method Laminas\\InputFilter\\InputFilterInterface<Laminas\\Form\\FormInterface>::init\(\)#'
path: src
-
message: '#Call to an undefined method Laminas\\Authentication\\AuthenticationServiceInterface::getAdapter\(\)#'
path: src/Admin/src/Controller/AdminController.php
-
message: '#Call to an undefined method Laminas\\Authentication\\AuthenticationServiceInterface::getStorage\(\)#'
path: src/Admin/src/Controller/AdminController.php

24 changes: 0 additions & 24 deletions psalm-baseline.xml

This file was deleted.

17 changes: 0 additions & 17 deletions psalm.xml

This file was deleted.

4 changes: 3 additions & 1 deletion src/Admin/src/Form/AdminDeleteForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ public function getInputFilter(): InputFilterInterface
return $this->inputFilter;
}

public function setInputFilter(InputFilterInterface $inputFilter): void
public function setInputFilter(InputFilterInterface $inputFilter): FormInterface
{
$this->inputFilter = $inputFilter;
$this->inputFilter->init();

return $this;
}
}
4 changes: 3 additions & 1 deletion src/Admin/src/Form/AdminForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ public function getInputFilter(): InputFilterInterface
return $this->inputFilter;
}

public function setInputFilter(InputFilterInterface $inputFilter): void
public function setInputFilter(InputFilterInterface $inputFilter): FormInterface
{
$this->inputFilter = $inputFilter;
$this->inputFilter->init();

return $this;
}
}
6 changes: 1 addition & 5 deletions src/Admin/src/Form/LoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ class LoginForm extends Form
{
protected InputFilterInterface $inputFilter;

/**
* @param null $name
* @param array $options
*/
public function __construct($name = null, array $options = [])
public function __construct(?string $name = null, array $options = [])
{
parent::__construct($name, $options);

Expand Down
3 changes: 1 addition & 2 deletions src/Admin/src/Service/AdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Admin\App\Exception\IdentityException;
use Admin\App\Service\IpService;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NonUniqueResultException;
use Dot\DependencyInjection\Attribute\Inject;
use Dot\GeoIP\Service\LocationServiceInterface;
Expand All @@ -40,7 +39,7 @@ public function __construct(
) {
}

public function getAdminRepository(): AdminRepository|EntityRepository
public function getAdminRepository(): AdminRepository
{
return $this->adminRepository;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Admin/src/Service/AdminServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
use Admin\Admin\Entity\Admin;
use Admin\Admin\Entity\AdminLogin;
use Admin\Admin\Repository\AdminRepository;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\NonUniqueResultException;

interface AdminServiceInterface
{
public function getAdminRepository(): AdminRepository|EntityRepository;
public function getAdminRepository(): AdminRepository;

public function exists(string $identity = ''): bool;

Expand Down
2 changes: 1 addition & 1 deletion test/Common/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private function ensureTestMode(): void
);
}

if (! $this->getEntityManager()->getConnection()->getParams()['memory'] ?? false) {
if (! ($this->getEntityManager()->getConnection()->getParams()['memory'] ?? false)) {
throw new RuntimeException(
'You are running tests in a non in-memory database. Did you forget to create local.test.php?'
);
Expand Down
8 changes: 4 additions & 4 deletions test/Unit/Admin/Entity/AdminInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getArrayCopy(): array
return [];
}

public function getIdentity(): ?string
public function getIdentity(): string
{
return 'test';
}
Expand All @@ -29,7 +29,7 @@ public function setIdentity(string $identity): AdminInterface
return $this;
}

public function getFirstName(): ?string
public function getFirstName(): string
{
return 'test';
}
Expand All @@ -39,7 +39,7 @@ public function setFirstName(string $firstName): AdminInterface
return $this;
}

public function getLastName(): ?string
public function getLastName(): string
{
return 'test';
}
Expand All @@ -49,7 +49,7 @@ public function setLastName(string $lastName): AdminInterface
return $this;
}

public function getPassword(): ?string
public function getPassword(): string
{
return 'test';
}
Expand Down
2 changes: 0 additions & 2 deletions test/Unit/Admin/Form/AdminFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,5 @@ public function testFormWillSetDifferentInputFilter(): void

$newInputFilter = $form->getInputFilter();
$this->assertInstanceOf(EditAdminInputFilter::class, $newInputFilter);

$this->assertNotSame($oldInputFilter, $newInputFilter);
}
}
4 changes: 3 additions & 1 deletion test/Unit/App/Plugin/FormsPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ public function testWillRestoreState(): void
{
$hash = (new Csrf(['session' => new Container()]))->getHash();

$oldData = [
/** @var array<string, string> $oldData */
$oldData = [
'username' => 'old-username',
'password' => 'old-password',
'loginCsrf' => $hash,
];

$oldMessages = [];

$newData = [
Expand Down