Completed
Push — 5.0 ( 63a207...42960a )
by David
14s queued 13s
created

UncheckedOrderBy::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TheCodingMachine\TDBM;
5
6
/**
7
 * Use this object to inject any SQL string in an order by clause in $dao->find methods.
8
 *
9
 * By default, TDBM is conservative and prevents an ORDERBY clause to be anything other than a sort on columns.
10
 * This is done to prevent SQL injections.
11
 *
12
 * If you need to order on an expression, you can wrap your ORDERBY clause in this class.
13
 *
14
 * For instance:
15
 *
16
 * $this->find(null, null, new UncheckedOrderBy('RAND()'));
17
 *
18
 * Note: you understand that arguments passed inside the `UncheckedOrderBy` constructor are NOT protected and
19
 * can be used for an SQL injection based attack. Therefore, you understand that you MUST NOT put input from the user
20
 * in this constructor.
21
 */
22
class UncheckedOrderBy
23
{
24
    /**
25
     * @var string
26
     */
27
    private $orderBy;
28
29
    public function __construct(string $orderBy)
30
    {
31
        $this->orderBy = $orderBy;
32
    }
33
34
    public function getOrderBy() : string
35
    {
36
        return $this->orderBy;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function __toString()
43
    {
44
        return 'UncheckedOrderBy_'.$this->orderBy;
45
    }
46
}
47