From bf8b9c3d89d9367bbf1471f724d1e2c9bf334ffe Mon Sep 17 00:00:00 2001 From: Damien Harper Date: Thu, 24 Oct 2024 12:11:09 +0200 Subject: [PATCH] Better JSON support (#450) * Updated PHPUnit config * Adjusted `auditor` requirement * Better viewer for changes inside JSON columns * Tweak `phpdoc_to_comment` rule (PHP-CS-Fixer ) --------- Co-authored-by: Fabian Kropfhamer <54098356+fkropfhamer@users.noreply.github.com> --- .php-cs-fixer.dist.php | 3 ++ composer.json | 2 +- phpunit.xml | 50 +++++++++---------- src/Resources/views/Audit/entry.html.twig | 44 ++++++---------- .../views/Audit/entry_diff.html.twig | 30 +++++++++++ 5 files changed, 74 insertions(+), 55 deletions(-) create mode 100644 src/Resources/views/Audit/entry_diff.html.twig diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index c10118c7..44cf3b79 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -30,6 +30,9 @@ 'phpdoc_to_param_type' => true, 'phpdoc_to_property_type' => true, 'phpdoc_to_return_type' => true, + 'phpdoc_to_comment' => [ + 'ignored_tags' => ['todo', 'var'] + ], 'regular_callable_call' => true, 'simplified_if_return' => true, 'get_class_to_class_keyword' => true, diff --git a/composer.json b/composer.json index c1ec8e6f..5dc2367c 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require": { "php": ">=8.2", "ext-intl": "*", - "damienharper/auditor": "^2.3|^3.0", + "damienharper/auditor": "^3.2", "doctrine/doctrine-bundle": "^2.0", "symfony/asset": "^5.4|^6.4|^7.0", "symfony/doctrine-bridge": "^5.4|^6.4|^7.0", diff --git a/phpunit.xml b/phpunit.xml index 66093063..77f2eb45 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - - - - - tests - - - - - src - - + + + + + + + + + + + + + + + + + tests + + + + + src + + diff --git a/src/Resources/views/Audit/entry.html.twig b/src/Resources/views/Audit/entry.html.twig index fac39ca9..43d234c9 100644 --- a/src/Resources/views/Audit/entry.html.twig +++ b/src/Resources/views/Audit/entry.html.twig @@ -1,5 +1,18 @@ {% import '@DHAuditor/Audit/helpers/helper.html.twig' as helper %} +{% macro displayDiffs(field, changeset) %} +{# {{ dump(field, changeset) }}#} + {% if changeset.old is defined or changeset.new is defined %} + {# NON JSON field changeset #} + {{ include('@DHAuditor/Audit/entry_diff.html.twig', {'key': field, 'values': changeset}) }} + {% else %} + {# JSON field changeset #} + {% for json_field, json_changeset in changeset %} + {{ _self.displayDiffs(field~'.'~json_field, json_changeset) }} + {% endfor %} + {% endif %} +{% endmacro %} +
{% if not is_last %} @@ -46,34 +59,8 @@ {% set diffs = entry.getDiffs() %} - {% for key, values in diffs %} - - - {{ key }} - - - {% if values.old is defined %} - {% if values.old is null %} - null - {% else %} - {{ helper.dump(values.old) }} - {% endif %} - {% endif %} - - - {% if values.new is defined %} - {% if values.new is null %} - null - {% else %} - {% if values.old is null %} - {{ helper.dump(values.new) }} - {% else %} - {{ helper.dump(values.new) }} - {% endif %} - {% endif %} - {% endif %} - - + {% for field, changeset in diffs %} + {{ _self.displayDiffs(field, changeset) }} {% endfor %} @@ -97,4 +84,3 @@
- diff --git a/src/Resources/views/Audit/entry_diff.html.twig b/src/Resources/views/Audit/entry_diff.html.twig new file mode 100644 index 00000000..d9f85a70 --- /dev/null +++ b/src/Resources/views/Audit/entry_diff.html.twig @@ -0,0 +1,30 @@ +{% import '@DHAuditor/Audit/helpers/helper.html.twig' as helper %} + + + +{#{{ dump('entry_diff', key, values) }}#} + {{ key }} + + + {% if values.old is defined %} + {% if values.old is null %} + null + {% else %} + {{ helper.dump(values.old) }} + {% endif %} + {% endif %} + + + {% if values.new is defined %} + {% if values.new is null %} + null + {% else %} + {% if values.old is not defined or values.old is null %} + {{ helper.dump(values.new) }} + {% else %} + {{ helper.dump(values.new) }} + {% endif %} + {% endif %} + {% endif %} + +