Completed
Pull Request — 3.x (#1023)
by Wojciech
01:39
created

AuditBlock4Service   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 49
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A execute() 0 17 2
A buildEditForm() 0 3 1
A getName() 0 4 1
A configureSettings() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrineORMAdminBundle\Block;
15
16
use SimpleThings\EntityAudit\AuditReader;
17
use Sonata\AdminBundle\Form\FormMapper;
18
use Sonata\BlockBundle\Block\BlockContextInterface;
19
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
20
use Sonata\BlockBundle\Model\BlockInterface;
21
use Symfony\Component\HttpFoundation\Response;
22
use Symfony\Component\OptionsResolver\OptionsResolver;
23
use Twig\Environment;
24
25
/**
26
 * @author Thomas Rabaix <[email protected]>
27
 */
28
final class AuditBlock4Service extends AbstractBlockService
29
{
30
    /**
31
     * @var AuditReader
32
     */
33
    protected $auditReader;
34
35
    public function __construct(Environment $environment, AuditReader $auditReader)
36
    {
37
        parent::__construct($environment);
38
39
        $this->auditReader = $auditReader;
40
    }
41
42
    public function execute(BlockContextInterface $blockContext, Response $response = null): Response
43
    {
44
        $revisions = [];
45
46
        foreach ($this->auditReader->findRevisionHistory($blockContext->getSetting('limit'), 0) as $revision) {
47
            $revisions[] = [
48
                'revision' => $revision,
49
                'entities' => $this->auditReader->findEntitiesChangedAtRevision($revision->getRev()),
50
            ];
51
        }
52
53
        return $this->renderResponse($blockContext->getTemplate(), [
54
            'block' => $blockContext->getBlock(),
55
            'settings' => $blockContext->getSettings(),
56
            'revisions' => $revisions,
57
        ], $response);
58
    }
59
60
    public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
0 ignored issues
show
Unused Code introduced by
The parameter $formMapper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $block is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
    {
62
    }
63
64
    public function getName()
65
    {
66
        return 'Audit List';
67
    }
68
69
    public function configureSettings(OptionsResolver $resolver): void
70
    {
71
        $resolver->setDefaults([
72
            'limit' => 10,
73
            'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig',
74
        ]);
75
    }
76
}
77