Passed
Push — main ( f2df15...8d7bb5 )
by Osvaldo
09:13
created

Orden::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
namespace src\pdodatabase\elementos;
3
4
use Exception;
5
6
class Orden
7
{
8
    private $_orden;
9
10
    public function __construct(string $Orden)
11
    {
12
        $this->_orden = $this->setOrden($Orden);
13
    }
14
15
    public function parametro(): string
16
    {
17
        return $this->_orden;
18
    }
19
20
    private function setOrden(string $orden): string
21
    {
22
        if(empty($orden))
23
        {
24
            throw new Exception("La sentencia ORDEN BY no puede estar vacia"); 
25
        }
26
27
        $this->alfaNumerico($orden);
28
29
        return ' ORDER BY '.$orden;
30
    }
31
32
    private function alfaNumerico($string)
33
    {
34
        if(!ctype_alnum($string))
35
        {
36
            throw new Exception("Caracter invalido en el campo de la sentencia ORDEN BY");
37
        }
38
    }
39
}