http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 7 LOC: 116 Statements: 13
Legend: executednot executeddead code
Source file Statements Methods Total coverage
Sort.php 100.0% 100.0% 100.0%
 
1
<?php
2
/**
3
 * Xyster Framework
4
 *
5
 * This source file is subject to the new BSD license that is bundled
6
 * with this package in the file LICENSE.txt.
7
 * It is also available through the world-wide-web at this URL:
8
 * http://www.opensource.org/licenses/bsd-license.php
9
 *
10
 * @category  Xyster
11
 * @package   Xyster_Data
12
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
13
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
14
 * @version   $Id$
15
 */
16
namespace Xyster\Data\Symbol;
17
/**
18
 * A struct that holds a field and a direction
19
 *
20
 * @category  Xyster
21
 * @package   Xyster_Data
22
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
23
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
24
 */
25
class Sort implements ISymbol
26
{
27
    /**
28
     * The direction of the sort
29
     *
30
     * @var bool
31
     */
32
    private $_ascending;
33
34
    /**
35
     * @var Field
36
     */
37
    private $_field;
38
39
    /**
40
     * Creates a new Sort
41
     *
42
     * @param Field|string $field
43
     * @param bool $ascending
44
     */
45
    private function __construct( $field, $ascending )
46
    {
47 23
        $this->_ascending = $ascending !== false;
48 23
        if (! $field instanceof Field) {
49 17
            $field = Field::named($field);
50 17
        }
51 23
        $this->_field = $field;
52
    }
53
54
    /**
55
     * Gets the field
56
     *
57
     * @return Xyster_Data_Field
58
     */
59
    public function getField()
60
    {
61 10
        return $this->_field;
62
    }
63
64
    /**
65
     * Gets the sort direction
66
     *
67
     * @return string
68
     */
69
    public function getDirection()
70
    {
71 6
        return $this->_ascending ? 'ASC' : 'DESC';
72
    }
73
74
    /**
75
     * Gets whether the sort is ascending
76
     *
77
     * @return bool
78
     */
79
    public function isAscending()
80
    {
81 6
        return $this->_ascending;
82
    }
83
84
    /**
85
     * Returns the string syntax for this Sort
86
     *
87
     * @magic
88
     * @return string
89
     */
90
    public function __toString()
91
    {
92 2
        return $this->_field->getName() . ' ' . $this->getDirection();
93
    }
94
95
    /**
96
     * Create a new ascending sort for the column specified
97
     *
98
     * @param string $field
99
     * @return Xyster_Data_Sort
100
     */
101
    static public function asc( $field )
102
    {
103 20
        return new self($field, true);
104
    }
105
106
    /**
107
     * Create a new descending Sort for the column specified
108
     *
109
     * @param string $field
110
     * @return Xyster_Data_Sort
111
     */
112
    static public function desc( $field )
113
    {
114 14
        return new self($field, false);
115
    }
116 1
}


Report generated at 2010-10-18T17:19:49-04:00