@@ -19,24 +19,38 @@ class Stability
19
19
*/
20
20
private $ number ;
21
21
22
- public function __construct ($ stability = 'stable ' , $ number = null )
22
+ public function __construct ( $ stability = 'stable ' , $ number = null )
23
23
{
24
- if (strlen ($ stability ) == 0 ) {
24
+ if ( strlen ( $ stability ) == 0 )
25
+ {
25
26
$ stability = 'stable ' ;
26
27
}
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 ;
36
51
}
37
-
38
52
$ this ->stability = $ stability ;
39
- $ this ->number = $ number ;
53
+ $ this ->number = $ number ;
40
54
}
41
55
42
56
public function __toString ()
@@ -57,32 +71,45 @@ public function getStability()
57
71
return $ this ->stability ;
58
72
}
59
73
60
- public function compare (Stability $ stability )
74
+ public function compare ( Stability $ stability )
61
75
{
62
- if ($ this ->toInt ($ this ->stability ) > $ this ->toInt ($ stability ->stability )) {
76
+ if ( $ this ->toInt ( $ this ->stability ) > $ this ->toInt ( $ stability ->stability ) )
77
+ {
63
78
return 1 ;
64
79
}
65
- if ($ this ->toInt ($ this ->stability ) < $ this ->toInt ($ stability ->stability )) {
80
+ if ( $ this ->toInt ( $ this ->stability ) < $ this ->toInt ( $ stability ->stability ) )
81
+ {
66
82
return -1 ;
67
83
}
68
- if ($ this ->number > $ stability ->number ) {
84
+ if ( $ this ->number > $ stability ->number )
85
+ {
69
86
return 1 ;
70
87
}
71
- if ($ this ->number < $ stability ->number ) {
88
+ if ( $ this ->number < $ stability ->number )
89
+ {
72
90
return -1 ;
73
91
}
74
92
return 0 ;
75
93
}
76
94
77
- private function toInt ($ stability )
95
+ private function toInt ( $ stability )
78
96
{
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 );
86
113
}
87
114
}
88
115
}
0 commit comments