|
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 | | - $stability = 'stable'; |
26 | | - } |
| 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 | + } |
27 | 55 |
|
28 | | - if (strtolower($stability) == 'rc') { |
29 | | - $stability = 'RC'; |
30 | | - } elseif (in_array(strtolower($stability), array('pl', 'patch', 'p'))) { |
31 | | - $stability = 'patch'; |
32 | | - } elseif (in_array(strtolower($stability), array('beta', 'b'))) { |
33 | | - $stability = 'beta'; |
34 | | - } elseif (in_array(strtolower($stability), array('a'))) { |
35 | | - $stability = 'alpha'; |
36 | | - } |
| 56 | + public function __toString() |
| 57 | + { |
| 58 | + return $this->stability . $this->number; |
| 59 | + } |
37 | 60 |
|
38 | | - $this->stability = $stability; |
39 | | - $this->number = $number; |
40 | | - } |
| 61 | + public function isStable() |
| 62 | + { |
| 63 | + return $this->stability == 'stable'; |
| 64 | + } |
41 | 65 |
|
42 | | - public function __toString() |
43 | | - { |
44 | | - return $this->stability . $this->number; |
45 | | - } |
| 66 | + /** |
| 67 | + * @return string |
| 68 | + */ |
| 69 | + public function getStability() |
| 70 | + { |
| 71 | + return $this->stability; |
| 72 | + } |
46 | 73 |
|
47 | | - public function isStable() |
48 | | - { |
49 | | - return $this->stability == 'stable'; |
50 | | - } |
| 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 | + } |
51 | 94 |
|
52 | | - /** |
53 | | - * @return string |
54 | | - */ |
55 | | - public function getStability() |
56 | | - { |
57 | | - return $this->stability; |
58 | | - } |
59 | | - |
60 | | - public function compare(Stability $stability) |
61 | | - { |
62 | | - if($this->toInt($this->stability) > $this->toInt($stability->stability)) { |
63 | | - return 1; |
64 | | - } |
65 | | - if($this->toInt($this->stability) < $this->toInt($stability->stability)) { |
66 | | - return -1; |
67 | | - } |
68 | | - if($this->number > $stability->number) { |
69 | | - return 1; |
70 | | - } |
71 | | - if($this->number < $stability->number) { |
72 | | - return -1; |
73 | | - } |
74 | | - return 0; |
75 | | - } |
76 | | - |
77 | | - private function toInt($stability) |
78 | | - { |
79 | | - switch($stability) { |
80 | | - case 'alpha': return 1; |
81 | | - case 'beta': return 2; |
82 | | - case 'RC': return 3; |
83 | | - case 'stable': return 4; |
84 | | - case 'patch': return 5; |
85 | | - default: throw new InvalidArgumentException('Invalid stability: ' . $stability); |
86 | | - } |
87 | | - } |
| 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 | + } |
88 | 115 | } |
0 commit comments