@@ -19,24 +19,38 @@ class Stability
1919 */
2020 private $ number ;
2121
22- public function __construct ($ stability = 'stable ' , $ number = null )
22+ public function __construct ( $ stability = 'stable ' , $ number = null )
2323 {
24- if (strlen ($ stability ) == 0 ) {
24+ if ( strlen ( $ stability ) == 0 )
25+ {
2526 $ stability = 'stable ' ;
2627 }
27-
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 ' ;
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 ;
3651 }
37-
3852 $ this ->stability = $ stability ;
39- $ this ->number = $ number ;
53+ $ this ->number = $ number ;
4054 }
4155
4256 public function __toString ()
@@ -57,32 +71,45 @@ public function getStability()
5771 return $ this ->stability ;
5872 }
5973
60- public function compare (Stability $ stability )
74+ public function compare ( Stability $ stability )
6175 {
62- if ($ this ->toInt ($ this ->stability ) > $ this ->toInt ($ stability ->stability )) {
76+ if ( $ this ->toInt ( $ this ->stability ) > $ this ->toInt ( $ stability ->stability ) )
77+ {
6378 return 1 ;
6479 }
65- if ($ this ->toInt ($ this ->stability ) < $ this ->toInt ($ stability ->stability )) {
80+ if ( $ this ->toInt ( $ this ->stability ) < $ this ->toInt ( $ stability ->stability ) )
81+ {
6682 return -1 ;
6783 }
68- if ($ this ->number > $ stability ->number ) {
84+ if ( $ this ->number > $ stability ->number )
85+ {
6986 return 1 ;
7087 }
71- if ($ this ->number < $ stability ->number ) {
88+ if ( $ this ->number < $ stability ->number )
89+ {
7290 return -1 ;
7391 }
7492 return 0 ;
7593 }
7694
77- private function toInt ($ stability )
95+ private function toInt ( $ stability )
7896 {
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 );
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 );
86113 }
87114 }
88115}
0 commit comments