1 | <?php |
||
19 | final class LessThan implements ComparatorInterface |
||
20 | { |
||
21 | /** |
||
22 | * Return true if the left version is less than right version. |
||
23 | * |
||
24 | * @param VersionInterface $lVersion |
||
25 | * @param VersionInterface $rVersion |
||
26 | * |
||
27 | * @return boolean |
||
28 | */ |
||
29 | 21 | public function compare(VersionInterface $lVersion, VersionInterface $rVersion) |
|
30 | { |
||
31 | return ( |
||
32 | 21 | $this->compareVersionNumber($lVersion, $rVersion) |
|
33 | 18 | || $this->compareFullLabel($lVersion, $rVersion) |
|
34 | 21 | ); |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | 1 | public function __toString() |
|
44 | |||
45 | /** |
||
46 | * Returns true if left version number is less than right version number. |
||
47 | * |
||
48 | * @param VersionInterface $lVersion |
||
49 | * @param VersionInterface $rVersion |
||
50 | * |
||
51 | * @return bool |
||
52 | */ |
||
53 | 21 | private function compareVersionNumber(VersionInterface $lVersion, VersionInterface $rVersion) |
|
54 | { |
||
55 | return ( |
||
56 | 21 | $this->compareMajor($lVersion, $rVersion) |
|
57 | 20 | || $this->compareMinor($lVersion, $rVersion) |
|
58 | 20 | || $this->comparePatch($lVersion, $rVersion) |
|
59 | 21 | ); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Returns true if left label is less than right version label. |
||
64 | * |
||
65 | * @param VersionInterface $lVersion |
||
66 | * @param VersionInterface $rVersion |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | 18 | private function compareFullLabel(VersionInterface $lVersion, VersionInterface $rVersion) |
|
71 | { |
||
72 | return ( |
||
73 | 18 | $this->compareLabel($lVersion, $rVersion) |
|
74 | 14 | || $this->compareLabelVersion($lVersion, $rVersion) |
|
75 | 18 | ); |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Returns true if left major is less than right major version. |
||
80 | * |
||
81 | * @param VersionInterface $lVersion |
||
82 | * @param VersionInterface $rVersion |
||
83 | * |
||
84 | * @return bool |
||
85 | */ |
||
86 | 21 | private function compareMajor(VersionInterface $lVersion, VersionInterface $rVersion) |
|
90 | |||
91 | /** |
||
92 | * Returns true if left & right major values match & left minor is less than right major version. |
||
93 | * |
||
94 | * @param VersionInterface $lVersion |
||
95 | * @param VersionInterface $rVersion |
||
96 | * |
||
97 | * @return bool |
||
98 | */ |
||
99 | 20 | private function compareMinor(VersionInterface $lVersion, VersionInterface $rVersion) |
|
106 | |||
107 | /** |
||
108 | * Returns true if left & right major & minor values match & left patch is less than right patch version. |
||
109 | * |
||
110 | * @param VersionInterface $lVersion |
||
111 | * @param VersionInterface $rVersion |
||
112 | * |
||
113 | * @return bool |
||
114 | */ |
||
115 | 19 | private function comparePatch(VersionInterface $lVersion, VersionInterface $rVersion) |
|
123 | |||
124 | /** |
||
125 | * Returns true if left & right major, minor & patch values match & left label precedence is less than right label |
||
126 | * precedence. |
||
127 | * |
||
128 | * @param VersionInterface $lVersion |
||
129 | * @param VersionInterface $rVersion |
||
130 | * |
||
131 | * @return bool |
||
132 | */ |
||
133 | 18 | private function compareLabel(VersionInterface $lVersion, VersionInterface $rVersion) |
|
142 | |||
143 | /** |
||
144 | * Returns true if left & right major, minor, patch & label precedence values match & left label version is less |
||
145 | * than right patch version. |
||
146 | * |
||
147 | * @param VersionInterface $lVersion |
||
148 | * @param VersionInterface $rVersion |
||
149 | * |
||
150 | * @return bool |
||
151 | */ |
||
152 | 14 | private function compareLabelVersion(VersionInterface $lVersion, VersionInterface $rVersion) |
|
162 | } |
||
163 |