Completed
Push — master ( 3b8e4a...cb7c37 )
by Arjay
03:02
created

OracleProcessor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 18.52 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 3 Features 0
Metric Value
wmc 7
c 3
b 3
f 0
lcom 0
cbo 3
dl 15
loc 81
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A processInsertGetId() 5 16 2
A prepareStatement() 0 6 1
B saveLob() 10 29 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Yajra\Oci8\Query\Processors;
4
5
use Illuminate\Database\Query\Builder;
6
use Illuminate\Database\Query\Processors\Processor;
7
use PDO;
8
9
class OracleProcessor extends Processor
10
{
11
    /**
12
     * Process an "insert get ID" query.
13
     *
14
     * @param  Builder $query
15
     * @param  string $sql
16
     * @param  array $values
17
     * @param  string $sequence
18
     * @return int
19
     */
20
    public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
21
    {
22
        $id        = 0;
23
        $parameter = 0;
24
        $statement = $this->prepareStatement($query, $sql);
25
26 View Code Duplication
        for ($i = 0; $i < count($values); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
            ${'param' . $i} = $values[$i];
28
            $statement->bindParam($parameter, ${'param' . $i});
29
            $parameter++;
30
        }
31
        $statement->bindParam($parameter, $id, PDO::PARAM_INT, 10);
32
        $statement->execute();
33
34
        return (int) $id;
35
    }
36
37
    /**
38
     * Get prepared statement.
39
     *
40
     * @param Builder $query
41
     * @param string $sql
42
     * @return \PDOStatement | \Yajra\Pdo\Oci8
43
     */
44
    private function prepareStatement(Builder $query, $sql)
45
    {
46
        $pdo = $query->getConnection()->getPdo();
47
48
        return $pdo->prepare($sql);
49
    }
50
51
    /**
52
     * save Query with Blob returning primary key value
53
     *
54
     * @param  Builder $query
55
     * @param  string $sql
56
     * @param  array $values
57
     * @param  array $binaries
58
     * @return int
59
     */
60
    public function saveLob(Builder $query, $sql, array $values, array $binaries)
61
    {
62
        $id        = 0;
63
        $parameter = 0;
64
        $statement = $this->prepareStatement($query, $sql);
65
66
        // bind values.
67 View Code Duplication
        for ($i = 0; $i < count($values); $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
68
            ${'param' . $i} = $values[$i];
69
            $statement->bindParam($parameter, ${'param' . $i});
70
            $parameter++;
71
        }
72
73
        // bind blob fields.
74 View Code Duplication
        for ($i = 0; $i < count($binaries); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
            ${'binary' . $i} = $binaries[$i];
76
            $statement->bindParam($parameter, ${'binary' . $i}, PDO::PARAM_LOB, -1);
77
            $parameter++;
78
        }
79
80
        // bind output param for the returning clause.
81
        $statement->bindParam($parameter, $id, PDO::PARAM_INT, 10);
82
83
        if (! $statement->execute()) {
84
            return false;
85
        }
86
87
        return (int) $id;
88
    }
89
}
90