Skip to content

Commit

Permalink
Add QA checks through PHPStan and Psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Oct 24, 2021
1 parent 6493b44 commit 2babdf8
Show file tree
Hide file tree
Showing 16 changed files with 306 additions and 168 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# DO NOT EDIT THIS FILE!
#
# It's auto-generated by sonata-project/dev-kit package.

name: Quality assurance

on:
push:
branches:
- 1.x
- master
pull_request:

jobs:
phpstan:
name: PHPStan

runs-on: ubuntu-latest

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

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none
tools: composer:v2

- name: Install Composer dependencies (highest)
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "highest"
composer-options: "--prefer-dist --prefer-stable"

- name: PHPStan
run: vendor/bin/phpstan --memory-limit=1G analyse
psalm:
name: Psalm

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none
tools: composer:v2

- name: Install Composer dependencies (highest)
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "highest"
composer-options: "--prefer-dist --prefer-stable"

- name: Psalm
run: vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.0
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@
"doctrine/doctrine-bundle": "^1.4 || ^2.2",
"gedmo/doctrine-extensions": "^3.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.2.1",
"phpstan/phpstan": "^0.12.93",
"phpunit/phpunit": "^9.5",
"symfony/cache": "^4.4 || ^5.3 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.3 || ^6.0",
"symfony/framework-bundle": "^4.4 || ^5.3 || ^6.0",
"symfony/http-foundation": "^4.4 || ^5.3 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.3 || ^6.0",
"symfony/phpunit-bridge": "^5.3 || ^6.0",
"symfony/security-core": "^4.4 || ^5.3 || ^6.0"
"symfony/security-core": "^4.4 || ^5.3 || ^6.0",
"symfony/var-dumper": "^4.4 || ^5.2",
"vimeo/psalm": "^4.8"
},
"config": {
"sort-packages": true
Expand Down
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:scalarNode\\(\\)\\.$#"
count: 1
path: src/DependencyInjection/Configuration.php
13 changes: 13 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
includes:
- phpstan-baseline.neon

parameters:
level: 5
paths:
- src
- tests
treatPhpDocTypesAsCertain: false
checkGenericClassInNonGenericObjectType: true
checkMissingIterableValueType: true
checkMissingVarTagTypehint: true
checkMissingTypehints: true
3 changes: 3 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.13.1@afd8874a9e4562eac42a02de90e42e430c3a1db1">
</files>
6 changes: 6 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="6" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml">
<projectFiles>
<directory name="src"/>
</projectFiles>
</psalm>
8 changes: 5 additions & 3 deletions src/Action/ViewRevisionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace SimpleThings\EntityAudit\Action;

use SimpleThings\EntityAudit\AuditReader;
use SimpleThings\EntityAudit\Exception\InvalidRevisionException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Twig\Environment;
Expand All @@ -38,9 +39,10 @@ public function __construct(Environment $twig, AuditReader $auditReader)

public function __invoke(int $rev): Response
{
$revision = $this->auditReader->findRevision($rev);
if (!$revision) {
throw new NotFoundHttpException(sprintf('Revision %i not found', $rev));
try {
$revision = $this->auditReader->findRevision($rev);
} catch (InvalidRevisionException $ex) {
throw new NotFoundHttpException(sprintf('Revision %d not found', $rev), $ex);
}

$changedEntities = $this->auditReader->findEntitiesChangedAtRevision($rev);
Expand Down
16 changes: 15 additions & 1 deletion src/AuditConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,35 @@

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use SimpleThings\EntityAudit\Metadata\MetadataFactory;

class AuditConfiguration
{
/**
* @var string[]
*
* @phpstan-var class-string[]
*/
private $auditedEntityClasses = [];
/**
* @var string[]
*/
private $globalIgnoreColumns = [];
private $tablePrefix = '';
private $tableSuffix = '_audit';
private $revisionTableName = 'revisions';
private $revisionFieldName = 'rev';
private $revisionTypeFieldName = 'revtype';
private $revisionIdFieldType = Types::INTEGER;
/**
* @var callable|null
*/
private $usernameCallable;

/**
* @return AuditConfiguration
*
* @phpstan-param class-string[] $classes
*/
public static function forEntities(array $classes)
{
Expand Down Expand Up @@ -121,7 +135,7 @@ public function setGlobalIgnoreColumns(array $columns): void

public function createMetadataFactory()
{
return new Metadata\MetadataFactory($this->auditedEntityClasses);
return new MetadataFactory($this->auditedEntityClasses);
}

/**
Expand Down
Loading

0 comments on commit 2babdf8

Please sign in to comment.