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

Result   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 45
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A model() 0 3 1
A execute() 0 14 2
1
<?php
2
3
namespace Rougin\Windstorm\Eloquent;
4
5
use Illuminate\Database\Connection;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Connection 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 Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Model 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 Illuminate\Support\Collection;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Collection 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 \Illuminate\Database\Connection
20
     */
21
    protected $connection;
22
23
    /**
24
     * @var \Illuminate\Database\Eloquent\Model
25
     */
26
    protected $model;
27
28
    /**
29
     * Executes an SQL statement with its bindings and types.
30
     *
31
     * @param  string $sql
32
     * @param  array  $bindings
33
     * @param  array  $types
34
     * @return mixed
35
     */
36
    public function execute($sql, array $parameters, array $types)
37
    {
38
        $connection = $this->model->getConnection();
39
40
        $type = (string) strtolower(substr($sql, 0, 6));
41
42
        $result = $connection->$type($sql, $parameters);
43
44
        if (is_array($result) === false)
45
        {
46
            return $result;
47
        }
48
49
        return $this->model->hydrate($result);
50
    }
51
52
    /**
53
     * Sets the Eloquent model to be used.
54
     *
55
     * @param  \Illuminate\Database\Eloquent\Model $model
56
     * @return self
57
     */
58
    public function model(Model $model)
59
    {
60
        $this->model = $model;
61
    }
62
}
63