Completed
Pull Request — master (#1)
by
unknown
02:51
created

CrateActivityLogStorage::findAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\ActivityLogBundle\Storage;
13
14
use Doctrine\Bundle\DoctrineBundle\Registry;
15
use Doctrine\DBAL\Driver\Connection;
16
use Sulu\Component\ActivityLog\Model\ActivityLog;
17
use Sulu\Component\ActivityLog\Model\ActivityLogInterface;
18
use Sulu\Component\ActivityLog\Storage\ActivityLogStorageInterface;
19
20
class CrateActivityLogStorage implements ActivityLogStorageInterface
21
{
22
    const ACTIVITY_LOG_TABLE_NAME = 'sulu_activity_logs';
23
24
    /** @var Registry $em */
25
    private $doctrine;
26
27
    /**
28
     * @param Registry $doctrine
29
     */
30
    public function __construct(Registry $doctrine)
31
    {
32
        $this->doctrine = $doctrine;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function create($type, $uuid = null)
39
    {
40
        return new ActivityLog($type, $uuid);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function find($uuid = null)
47
    {
48
        $stmt = 'SELECT * FROM ' . self::ACTIVITY_LOG_TABLE_NAME .
49
            ' WHERE uuid = \'' . $uuid . '\'';
50
51
        /** @var Connection $conn */
52
        $conn = $this->doctrine->getConnection('crate');
53
        $result = $conn->query($stmt)->fetchAll();
0 ignored issues
show
Unused Code introduced by
The call to Connection::query() has too many arguments starting with $stmt.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
54
55
        return $result;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function findAll($page = 1, $pageSize = null)
62
    {
63
        $stmt = 'SELECT * FROM ' . self::ACTIVITY_LOG_TABLE_NAME;
64
65
        /** @var Connection $conn */
66
        $conn = $this->doctrine->getConnection('crate');
67
        $result = $conn->query($stmt)->fetchAll();
0 ignored issues
show
Unused Code introduced by
The call to Connection::query() has too many arguments starting with $stmt.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
68
69
        return $result;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function findByParent(ActivityLogInterface $activityLog, $page = 1, $pageSize = null)
76
    {
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function persist(ActivityLogInterface $activityLog)
83
    {
84
        $stmt = 'INSERT INTO ' . self::ACTIVITY_LOG_TABLE_NAME .
85
            ' (uuid, msg) VALUES (\'' . $activityLog->getUuid() . '\', \'' . $activityLog->getMessage() . '\')';
86
87
88
        $conn = $this->doctrine->getConnection('crate');
89
        $conn->query($stmt);
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function flush()
96
    {
97
98
    }
99
}
100