Passed
Push — master ( d90b52...2a2bc7 )
by Damien
02:46
created

src/Controller/ViewerController.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace DH\AuditorBundle\Controller;
4
5
use DH\Auditor\Exception\AccessDeniedException;
6
use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Security;
7
use DH\Auditor\Provider\Doctrine\Persistence\Reader\Reader;
8
use DH\Auditor\Provider\Doctrine\Persistence\Schema\SchemaManager;
9
use DH\Auditor\Provider\Doctrine\Service\AuditingService;
10
use DH\AuditorBundle\Helper\UrlHelper;
11
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
use Symfony\Component\Routing\Annotation\Route;
15
16
class ViewerController extends AbstractController
17
{
18
    /**
19
     * @Route("/audit", name="dh_auditor_list_audits", methods={"GET"})
20
     */
21
    public function listAuditsAction(Reader $reader): Response
22
    {
23
        $schemaManager = new SchemaManager($reader->getProvider());
24
25
        /** @var AuditingService[] $auditingServices */
26
        $auditingServices = $reader->getProvider()->getAuditingServices();
27
        $audited = [];
28
        $scope = Security::VIEW_SCOPE;
29
        foreach ($auditingServices as $name => $auditingService) {
30
            $audited = array_merge(
31
                $audited,
32
                array_filter(
33
                    $schemaManager->getAuditableTableNames($auditingService->getEntityManager()),
34
                    function ($entity) use ($reader, $scope) {
35
                        $roleChecker = $reader->getProvider()->getAuditor()->getConfiguration()->getRoleChecker();
0 ignored issues
show
The method getRoleChecker() does not exist on DH\Auditor\Configuration. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
                        $roleChecker = $reader->getProvider()->getAuditor()->getConfiguration()->/** @scrutinizer ignore-call */ getRoleChecker();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
37
                        return null === $roleChecker ? true : $roleChecker($entity, $scope);
38
                    },
39
                    ARRAY_FILTER_USE_KEY
40
                )
41
            );
42
        }
43
44
        return $this->render('@DHAuditor/Audit/audits.html.twig', [
45
            'audited' => $audited,
46
            'reader' => $reader,
47
        ]);
48
    }
49
50
    /**
51
     * @Route("/audit/transaction/{hash}", name="dh_auditor_show_transaction", methods={"GET"})
52
     */
53
    public function showTransactionAction(Reader $reader, string $hash): Response
54
    {
55
        $audits = $reader->getAuditsByTransactionHash($hash);
56
57
        return $this->render('@DHAuditor/Audit/transaction.html.twig', [
58
            'hash' => $hash,
59
            'audits' => $audits,
60
        ]);
61
    }
62
63
    /**
64
     * @Route("/audit/{entity}/{id}", name="dh_auditor_show_entity_history", methods={"GET"})
65
     *
66
     * @param int|string $id
67
     */
68
    public function showEntityHistoryAction(Request $request, Reader $reader, string $entity, $id = null): Response
69
    {
70
        $page = (int) $request->query->get('page', '1');
71
        $entity = UrlHelper::paramToNamespace($entity);
72
73
        if (!$reader->getProvider()->isAuditable($entity)) {
74
            throw $this->createNotFoundException();
75
        }
76
77
        try {
78
            $pager = $reader->paginate($reader->createQuery($entity, [
79
                'object_id' => $id,
80
                'page' => $page,
81
                'page_size' => Reader::PAGE_SIZE,
82
            ]), $page, Reader::PAGE_SIZE);
83
        } catch (AccessDeniedException $e) {
84
            throw $this->createAccessDeniedException();
85
        }
86
87
        return $this->render('@DHAuditor/Audit/entity_history.html.twig', [
88
            'id' => $id,
89
            'entity' => $entity,
90
            'paginator' => $pager,
91
        ]);
92
    }
93
}
94