@@ -7,6 +7,15 @@ class PreRelease
77 /** @var array */
88 private $ preReleaseParts ;
99
10+ /**
11+ * PreRelease constructor.
12+ * @param array $preReleaseParts The prerelease parts.
13+ */
14+ private function __construct ($ preReleaseParts )
15+ {
16+ $ this ->preReleaseParts = $ preReleaseParts ;
17+ }
18+
1019 /**
1120 * @return PreRelease The incremented prerelease
1221 */
@@ -39,9 +48,7 @@ public function __toString()
3948
4049 private function copy ()
4150 {
42- $ result = new PreRelease ();
43- $ result ->preReleaseParts = $ this ->preReleaseParts ;
44- return $ result ;
51+ return new PreRelease ($ this ->preReleaseParts );
4552 }
4653
4754 /**
@@ -52,20 +59,22 @@ private function validate()
5259 foreach ($ this ->preReleaseParts as $ part ) {
5360 if ($ this ->hasOnlyNumbers ($ part )) {
5461 if (strlen ($ part ) > 1 && $ part [0 ] == "0 " ) {
55- throw new VersionFormatException (sprintf ("The prerelease part '%s' is numeric but contains a leading zero. " , $ part ));
62+ throw new VersionFormatException (sprintf (
63+ "The prerelease part '%s' is numeric but contains a leading zero. " , $ part ));
5664 } else {
5765 continue ;
5866 }
5967 }
6068
6169 if (!$ this ->hasOnlyAlphanumericsAndHyphen ($ part )) {
62- throw new VersionFormatException (sprintf ("The prerelease part '%s' contains invalid character. " , $ part ));
70+ throw new VersionFormatException (sprintf (
71+ "The prerelease part '%s' contains invalid character. " , $ part ));
6372 }
6473 }
6574 }
6675
6776 /**
68- * @param $part string part to check.
77+ * @param string $part part to check.
6978 * @return bool True when the part is containing only numbers.
7079 */
7180 private function hasOnlyNumbers ($ part )
@@ -74,7 +83,7 @@ private function hasOnlyNumbers($part)
7483 }
7584
7685 /**
77- * @param $part string The part to check.
86+ * @param string $part The part to check.
7887 * @return bool True when the part is only containing alphanumerics.
7988 */
8089 private function hasOnlyAlphanumericsAndHyphen ($ part )
@@ -83,7 +92,17 @@ private function hasOnlyAlphanumericsAndHyphen($part)
8392 }
8493
8594 /**
86- * @param $preReleaseString string The prerelease string.
95+ * Creates a new prerelease tag with initial default value (-0).
96+ *
97+ * @return PreRelease The default prerelease tag.
98+ */
99+ public static function createDefault ()
100+ {
101+ return new PreRelease ([0 ]);
102+ }
103+
104+ /**
105+ * @param string $preReleaseString The prerelease string.
87106 * @return PreRelease The parsed prerelease part.
88107 * @throws VersionFormatException When the given prerelease string is invalid.
89108 */
@@ -94,17 +113,15 @@ public static function parse($preReleaseString)
94113 throw new VersionFormatException ("preReleaseString cannot be empty. " );
95114 }
96115
97- $ preRelease = new PreRelease ();
98-
99- $ preRelease ->preReleaseParts = explode ('. ' , $ preReleaseString );
116+ $ preRelease = new PreRelease (explode ('. ' , $ preReleaseString ));
100117 $ preRelease ->validate ();
101118
102119 return $ preRelease ;
103120 }
104121
105122 /**
106- * @param $p1 string|PreRelease The left side of the comparison.
107- * @param $p2 string|PreRelease The right side of the comparison.
123+ * @param string|PreRelease $p1 The left side of the comparison.
124+ * @param string|PreRelease $p2 The right side of the comparison.
108125 * @return int -1 when $p1 < $p2, 0 when $p1 == $p2, 1 when $p1 > $p2.
109126 * @throws VersionFormatException When the given prerelease values are invalid.
110127 */
@@ -134,8 +151,8 @@ public static function compare($p1, $p2)
134151 }
135152
136153 /**
137- * @param $a mixed The left side of the comparison.
138- * @param $b mixed The right side of the comparison.
154+ * @param mixed $a The left side of the comparison.
155+ * @param mixed $b The right side of the comparison.
139156 * @return int -1 when $a < $b, 0 when $a == $b, 1 when $v1 > $b.
140157 */
141158 private static function comparePart ($ a , $ b )
0 commit comments