Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare auditor-bundle 6 release #425

Merged
merged 16 commits into from
Sep 6, 2024
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tests/coverage/
.DS_Store
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
.phpunit.cache/
composer.lock
*.sqlite
.preload.php
53 changes: 53 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

return (new Config())
->setParallelConfig(ParallelConfigFactory::detect()) // @TODO 4.0 no need to call this manually :poop:
->setRiskyAllowed(true)
->setRules([
'@PHP82Migration' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@DoctrineAnnotation' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@PHPUnit100Migration:risky' => true,
// 'date_time_immutable' => true,
'general_phpdoc_annotation_remove' => [
'annotations' => [
'expectedDeprecation',
'expectedException',
'expectedExceptionMessage',
'expectedExceptionMessageRegExp',
],
],
'ordered_interfaces' => true,
'ordered_traits' => true,
'phpdoc_to_param_type' => true,
'phpdoc_to_property_type' => true,
'phpdoc_to_return_type' => true,
'regular_callable_call' => true,
'simplified_if_return' => true,
'get_class_to_class_keyword' => true,
'mb_str_functions' => true,
'modernize_strpos' => true,
'no_useless_concat_operator' => false, // TODO switch back on when the `src/Console/Application.php` no longer needs the concat
'numeric_literal_separator' => true,
'string_implicit_backslashes' => true, // https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7786
'php_unit_test_case_static_method_calls' => false,
'php_unit_test_class_requires_covers' => false,
])
->setFinder(
(new Finder())
->ignoreDotFiles(false)
->ignoreVCSIgnored(true)
->in(__DIR__.'/src')
->notPath('DependencyInjection/Configuration.php')
->in(__DIR__.'/tests')
->exclude('App/var')
)
;
53 changes: 0 additions & 53 deletions .php-cs-fixer.php

This file was deleted.

22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"ext-json": "*",
"damienharper/auditor": "dev-master",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.13 || ^3.1",
"doctrine/orm": "^2.13|^3.2",
"symfony/asset": "^5.4|^6.0|^7.0",
"symfony/doctrine-bridge": "^5.4|^6.0|^7.0",
"symfony/event-dispatcher": "^5.4|^6.0|^7.0",
Expand All @@ -45,9 +45,9 @@
},
"require-dev": {
"gedmo/doctrine-extensions": "^2.4|^3.0",
"matthiasnoback/symfony-dependency-injection-test": "^3.1|^4.0|^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^6.0",
"nyholm/symfony-bundle-test": "^2.0|^3.0",
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^11.0",
"symfony/browser-kit": "^5.4|^6.0|^7.0",
"symfony/css-selector": "^5.4|^6.0|^7.0",
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
Expand All @@ -56,15 +56,15 @@
"doctrine/data-fixtures": "^1.4"
},
"scripts": {
"test": "php -d pcov.enabled=1 ./vendor/bin/phpunit --colors=always",
"csfixer": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --using-cache=no --verbose --ansi",
"cs-check": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --using-cache=no --verbose --ansi --dry-run",
"phpstan": "tools/phpstan/vendor/bin/phpstan --ansi analyse src",
"setup44": "SYMFONY_REQUIRE='^4.4' composer update --prefer-stable",
"setup54": "SYMFONY_REQUIRE='^5.4' composer update --prefer-stable",
"rector": "tools/rector/vendor/bin/rector process src",
"test": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always",
"cs-fix": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --using-cache=no --verbose --ansi",
"cs-check": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --using-cache=no --verbose --ansi --dry-run",
"phpstan": "tools/phpstan/vendor/bin/phpstan --memory-limit=1G --ansi analyse src",
"rector": "tools/rector/vendor/bin/rector",
"rector-check": "tools/rector/vendor/bin/rector --dry-run",
"update-tools": "composer update --working-dir=tools/php-cs-fixer ; composer update --working-dir=tools/phpstan ; composer update --working-dir=tools/rector"
"update-tools": "composer update --working-dir=tools/php-cs-fixer ; composer update --working-dir=tools/phpstan ; composer update --working-dir=tools/rector",
"setup54": "SYMFONY_REQUIRE='^5.4' composer update --prefer-stable && rm -rf tests/App/var/cache/*",
"setup64": "SYMFONY_REQUIRE='^6.4' composer update --prefer-stable && rm -rf tests/App/var/cache/*"
},
"config": {
"sort-packages": true,
Expand Down
13 changes: 9 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
includes:
- tools/phpstan/vendor/phpstan/phpstan-doctrine/extension.neon
- tools/phpstan/vendor/phpstan/phpstan-doctrine/rules.neon

parameters:
level: max
inferPrivatePropertyTypeFromConstructor: true

type_coverage:
return_type: 100
param_type: 100
property_type: 100
constant: 0

paths:
- src

Expand All @@ -14,3 +17,5 @@ parameters:

ignoreErrors:
- identifier: missingType.iterableValue
- message: '~Class Symfony\\Component\\Security\\Core\\Authentication\\Token\\AnonymousToken not found.~'
reportUnmatched: false
30 changes: 30 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" bootstrap="tests/bootstrap.php"
executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache"
requireCoverageMetadata="false" beStrictAboutCoverageMetadata="true">
<coverage includeUncoveredFiles="true">
<report>
<html outputDirectory="tests/coverage"/>
</report>
</coverage>
<logging/>
<php>
<ini name="error_reporting" value="-1"/>
<server name="KERNEL_CLASS" value="DH\AuditorBundle\Tests\App\Kernel"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<!-- <server name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>-->
<env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="test"/>
</php>
<testsuites>
<testsuite name="Auditor Bundle test suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
33 changes: 0 additions & 33 deletions phpunit.xml.dist

This file was deleted.

80 changes: 28 additions & 52 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,39 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Rector\Class_\MakeCommandLazyRector;
use Rector\Symfony\Set\SymfonySetList;
use Rector\Transform\Rector\Attribute\AttributeKeyToClassConstFetchRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayParamDocTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([__DIR__.'/src', __DIR__.'/tests']);

// Do not try to change simple property init and assign to constructor promotion
// to make code easier to read (no more class with properties declared both
// at the start of the class and in the constructor)
$rectorConfig->skip([
ClassPropertyAssignToConstructorPromotionRector::class,
RemoveUnusedPrivatePropertyRector::class,
AttributeKeyToClassConstFetchRector::class,
MakeCommandLazyRector::class,
AddArrayReturnDocTypeRector::class,
AddArrayParamDocTypeRector::class,
return RectorConfig::configure()
->withPaths([__DIR__.'/src', __DIR__.'/tests'])
->withSkip([
__DIR__.'/tests/App/var/*',
]);

// PHP rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::CODING_STYLE,
SetList::TYPE_DECLARATION,
]);

// Symfony rules
$rectorConfig->sets([
])
->withPhpSets(php82: true)
->withPreparedSets(
deadCode: true,
codeQuality: true,
codingStyle: true,
typeDeclarations: true,
privatization: true,
instanceOf: true,
earlyReturn: true,
phpunitCodeQuality: true,
doctrineCodeQuality: true,
symfonyCodeQuality: true,
phpunit: true,
)
->withSets([
SymfonySetList::SYMFONY_54,
SymfonySetList::SYMFONY_CODE_QUALITY,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
]);

// Doctrine rules
$rectorConfig->sets([
PHPUnitSetList::PHPUNIT_110,
DoctrineSetList::DOCTRINE_CODE_QUALITY,
DoctrineSetList::DOCTRINE_DBAL_30,
DoctrineSetList::DOCTRINE_ORM_29,
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
]);

// PHPUnit rules
$rectorConfig->sets([
PHPUnitSetList::PHPUNIT_91,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::PHPUNIT_YIELD_DATA_PROVIDER,
]);
};
DoctrineSetList::DOCTRINE_DBAL_40,
])
->withAttributesSets(
symfony: true,
doctrine: true,
phpunit: true,
)
;
14 changes: 5 additions & 9 deletions src/Controller/ViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
*/
final class ViewerController
{
private Environment $environment;

public function __construct(Environment $environment)
{
$this->environment = $environment;
}
public function __construct(private readonly Environment $environment) {}

#[Route(path: '/audit', name: 'dh_auditor_list_audits', methods: ['GET'])]
public function listAuditsAction(Reader $reader): Response
Expand All @@ -44,7 +39,7 @@ public function listAuditsAction(Reader $reader): Response
$audited,
array_filter(
$schemaManager->getAuditableTableNames($auditingService->getEntityManager()),
static function ($entity) use ($reader, $scope) {
static function (string $entity) use ($reader, $scope) {
$roleChecker = $reader->getProvider()->getAuditor()->getConfiguration()->getRoleChecker();

return null === $roleChecker ? true : $roleChecker($entity, $scope);
Expand Down Expand Up @@ -76,7 +71,8 @@ public function showEntityHistoryAction(Request $request, Reader $reader, string
{
\assert(\is_string($request->query->get('page', '1')) || \is_int($request->query->get('page', '1')));
$page = (int) $request->query->get('page', '1');
$page = $page < 1 ? 1 : $page;
$page = max(1, $page);

$entity = UrlHelper::paramToNamespace($entity);

if (!$reader->getProvider()->isAuditable($entity)) {
Expand All @@ -89,7 +85,7 @@ public function showEntityHistoryAction(Request $request, Reader $reader, string
'page' => $page,
'page_size' => Reader::PAGE_SIZE,
]), $page, Reader::PAGE_SIZE);
} catch (AccessDeniedException $e) {
} catch (AccessDeniedException) {
throw new SymfonyAccessDeniedException('Access Denied.');
}

Expand Down
Loading
Loading