Passed
Push — main ( 1c1b74...973229 )
by Osvaldo
05:20
created

EjecutarConsultaConDatos   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 30
ccs 13
cts 13
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A query() 0 21 3
1
<?php
2
namespace src\pdodatabase\ejecutar;
3
4
use Exception;
5
use PDOException;
6
use PDOStatement;
7
use src\pdodatabase\conexion\ConexionBaseDeDatos;
8
9
class EjecutarConsultaConDatos
10
{
11
    private $_conexion;
12
13 11
    public function __construct(ConexionBaseDeDatos $conexionBaseDeDatos)
14
    {
15 11
        $this->_conexion = $conexionBaseDeDatos->conectar();
16 11
    }
17
18 4
    public function query(object $sentencia): PDOStatement
19
    {
20 4
        $query = $this->_conexion->prepare($sentencia->sql());
21
22 4
        $x=1;
23 4
        foreach ($sentencia->datos() as $value)
24
        {
25 4
            $query->bindValue($x,$value);
26 4
            $x++;	
27
        }
28
        
29
        try
30
        {
31 4
            $query->execute();
32
        }
33 1
        catch(PDOException $e)
34
        {
35 1
            throw new Exception("Error en la consulta");
36
        }
37
38 3
        return $query;
39
    }
40
}