Passed
Push — master ( c572a9...7c9482 )
by Rougin
01:48
created

Result   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 67
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A manager() 0 3 1
A execute() 0 14 2
A mapping() 0 5 1
A __construct() 0 3 1
1
<?php
2
3
namespace Rougin\Windstorm\Doctrine;
4
5
use Doctrine\ORM\EntityManager;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Doctrine\ORM\NativeQuery;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\NativeQuery was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Doctrine\ORM\Query\ResultSetMapping;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Query\ResultSetMapping was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Rougin\Windstorm\ResultInterface;
9
10
/**
11
 * Result
12
 *
13
 * @package Windstorm
14
 * @author  Rougin Gutib <[email protected]>
15
 */
16
class Result implements ResultInterface
17
{
18
    /**
19
     * @var \Doctrine\ORM\EntityManager
20
     */
21
    protected $manager;
22
23
    /**
24
     * @var \Doctrine\ORM\Query\ResultSetMapping
25
     */
26
    protected $mapping;
27
28
    /**
29
     * Initializes the entity manager instance.
30
     *
31
     * @param \Doctrine\ORM\EntityManager $manager
32
     */
33
    public function __construct(EntityManager $manager)
34
    {
35
        $this->manager = $manager;
36
    }
37
38
    /**
39
     * Returns the entity manager instance.
40
     *
41
     * @return \Doctrine\ORM\EntityManager
42
     */
43
    public function manager()
44
    {
45
        return $this->manager;
46
    }
47
48
    /**
49
     * Executes an SQL statement with its bindings and types.
50
     *
51
     * @param  string $sql
52
     * @param  array  $bindings
53
     * @param  array  $types
54
     * @return mixed
55
     */
56
    public function execute($sql, array $parameters, array $types)
57
    {
58
        $connection = $this->manager->getConnection();
59
60
        if (strpos($sql, 'SELECT') === false)
61
        {
62
            return $connection->executeUpdate($sql, $parameters, $types);
63
        }
64
65
        $query = new NativeQuery($this->manager);
66
67
        $query->setSql($sql)->setResultSetMapping($this->mapping);
68
69
        return (array) $query->getResult();
70
    }
71
72
    /**
73
     * Sets the result set mapping instance.
74
     *
75
     * @param  \Doctrine\ORM\Query\ResultSetMapping $mapping
76
     * @return self
77
     */
78
    public function mapping(ResultSetMapping $mapping)
79
    {
80
        $this->mapping = $mapping;
81
82
        return $this;
83
    }
84
}
85