|
7 | 7 | class Stability |
8 | 8 | { |
9 | 9 |
|
10 | | - const REGEX = '[-|_|\.]{0,1}([R|r][C|c]|pl|a|alpha|[B|b][E|e][T|t][A|a]|b|B|patch|stable|p)\.{0,1}(\d*)'; |
| 10 | + const REGEX = '[-|_|\.]{0,1}([R|r][C|c]|pl|a|alpha|[B|b][E|e][T|t][A|a]|b|B|patch|stable|p)\.{0,1}(\d*)'; |
11 | 11 |
|
12 | | - /** |
13 | | - * @var string |
14 | | - */ |
15 | | - private $stability; |
| 12 | + /** |
| 13 | + * @var string |
| 14 | + */ |
| 15 | + private $stability; |
16 | 16 |
|
17 | | - /** |
18 | | - * @var int |
19 | | - */ |
20 | | - private $number; |
| 17 | + /** |
| 18 | + * @var int |
| 19 | + */ |
| 20 | + private $number; |
21 | 21 |
|
22 | | - public function __construct( $stability = 'stable', $number = null ) |
23 | | - { |
24 | | - if( strlen( $stability ) == 0 ) |
25 | | - { |
26 | | - $stability = 'stable'; |
27 | | - } |
28 | | - $stability = strtolower( $stability ); |
29 | | - switch( $stability ) |
30 | | - { |
31 | | - case 'rc': |
32 | | - $stability = 'RC'; |
33 | | - break; |
34 | | - case 'patch': |
35 | | - case 'pl': |
36 | | - case 'p': |
37 | | - $stability = 'patch'; |
38 | | - break; |
39 | | - case 'beta': |
40 | | - case 'b': |
41 | | - $stability = 'beta'; |
42 | | - break; |
43 | | - case 'alpha': |
44 | | - case 'a': |
45 | | - $stability = 'alpha'; |
46 | | - break; |
47 | | - case 'dev': |
48 | | - case 'd': |
49 | | - $stability = 'dev'; |
50 | | - break; |
51 | | - } |
52 | | - $this->stability = $stability; |
53 | | - $this->number = $number; |
54 | | - } |
| 22 | + public function __construct( $stability = 'stable', $number = null ) |
| 23 | + { |
| 24 | + if( strlen( $stability ) == 0 ) |
| 25 | + { |
| 26 | + $stability = 'stable'; |
| 27 | + } |
| 28 | + $stability = strtolower( $stability ); |
| 29 | + switch( $stability ) |
| 30 | + { |
| 31 | + case 'rc': |
| 32 | + $stability = 'RC'; |
| 33 | + break; |
| 34 | + case 'patch': |
| 35 | + case 'pl': |
| 36 | + case 'p': |
| 37 | + $stability = 'patch'; |
| 38 | + break; |
| 39 | + case 'beta': |
| 40 | + case 'b': |
| 41 | + $stability = 'beta'; |
| 42 | + break; |
| 43 | + case 'alpha': |
| 44 | + case 'a': |
| 45 | + $stability = 'alpha'; |
| 46 | + break; |
| 47 | + case 'dev': |
| 48 | + case 'd': |
| 49 | + $stability = 'dev'; |
| 50 | + break; |
| 51 | + } |
| 52 | + $this->stability = $stability; |
| 53 | + $this->number = $number; |
| 54 | + } |
55 | 55 |
|
56 | | - public function __toString() |
57 | | - { |
58 | | - return $this->stability . $this->number; |
59 | | - } |
| 56 | + public function __toString() |
| 57 | + { |
| 58 | + return $this->stability . $this->number; |
| 59 | + } |
60 | 60 |
|
61 | | - public function isStable() |
62 | | - { |
63 | | - return $this->stability == 'stable'; |
64 | | - } |
| 61 | + public function isStable() |
| 62 | + { |
| 63 | + return $this->stability == 'stable'; |
| 64 | + } |
65 | 65 |
|
66 | | - /** |
67 | | - * @return string |
68 | | - */ |
69 | | - public function getStability() |
70 | | - { |
71 | | - return $this->stability; |
72 | | - } |
| 66 | + /** |
| 67 | + * @return string |
| 68 | + */ |
| 69 | + public function getStability() |
| 70 | + { |
| 71 | + return $this->stability; |
| 72 | + } |
73 | 73 |
|
74 | | - public function compare( Stability $stability ) |
75 | | - { |
76 | | - if( $this->toInt( $this->stability ) > $this->toInt( $stability->stability ) ) |
77 | | - { |
78 | | - return 1; |
79 | | - } |
80 | | - if( $this->toInt( $this->stability ) < $this->toInt( $stability->stability ) ) |
81 | | - { |
82 | | - return -1; |
83 | | - } |
84 | | - if( $this->number > $stability->number ) |
85 | | - { |
86 | | - return 1; |
87 | | - } |
88 | | - if( $this->number < $stability->number ) |
89 | | - { |
90 | | - return -1; |
91 | | - } |
92 | | - return 0; |
93 | | - } |
| 74 | + public function compare( Stability $stability ) |
| 75 | + { |
| 76 | + if( $this->toInt( $this->stability ) > $this->toInt( $stability->stability ) ) |
| 77 | + { |
| 78 | + return 1; |
| 79 | + } |
| 80 | + if( $this->toInt( $this->stability ) < $this->toInt( $stability->stability ) ) |
| 81 | + { |
| 82 | + return -1; |
| 83 | + } |
| 84 | + if( $this->number > $stability->number ) |
| 85 | + { |
| 86 | + return 1; |
| 87 | + } |
| 88 | + if( $this->number < $stability->number ) |
| 89 | + { |
| 90 | + return -1; |
| 91 | + } |
| 92 | + return 0; |
| 93 | + } |
94 | 94 |
|
95 | | - private function toInt( $stability ) |
96 | | - { |
97 | | - switch( $stability ) |
98 | | - { |
99 | | - case 'dev': |
100 | | - return 1; |
101 | | - case 'alpha': |
102 | | - return 2; |
103 | | - case 'beta': |
104 | | - return 3; |
105 | | - case 'RC': |
106 | | - return 4; |
107 | | - case 'stable': |
108 | | - return 5; |
109 | | - case 'patch': |
110 | | - return 6; |
111 | | - default: |
112 | | - throw new InvalidArgumentException( 'Invalid stability: ' . $stability ); |
113 | | - } |
114 | | - } |
| 95 | + private function toInt( $stability ) |
| 96 | + { |
| 97 | + switch( $stability ) |
| 98 | + { |
| 99 | + case 'dev': |
| 100 | + return 1; |
| 101 | + case 'alpha': |
| 102 | + return 2; |
| 103 | + case 'beta': |
| 104 | + return 3; |
| 105 | + case 'RC': |
| 106 | + return 4; |
| 107 | + case 'stable': |
| 108 | + return 5; |
| 109 | + case 'patch': |
| 110 | + return 6; |
| 111 | + default: |
| 112 | + throw new InvalidArgumentException( 'Invalid stability: ' . $stability ); |
| 113 | + } |
| 114 | + } |
115 | 115 | } |
0 commit comments