Passed
Push — master ( a4f7f2...d3cc39 )
by Melech
04:09
created

OrderBy::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Orm\Data;
15
16
use Stringable;
17
use Valkyrja\Orm\Enum\SortOrder;
18
19
/**
20
 * Class OrderBy.
21
 *
22
 * @author Melech Mizrachi
23
 */
24
readonly class OrderBy implements Stringable
25
{
26
    /**
27
     * @param non-empty-string $field The field to order by
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
28
     */
29
    public function __construct(
30
        public string $field,
31
        public SortOrder $order = SortOrder::ASC,
32
    ) {
33
    }
34
35
    /**
36
     * Get the join clause as a string.
37
     *
38
     * @return non-empty-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
39
     */
40
    public function __toString(): string
41
    {
42
        return $this->field
43
            . ' '
44
            . $this->order->value;
45
    }
46
}
47