@@ -9,15 +9,15 @@ class PreRelease
99
1010 /**
1111 * PreRelease constructor.
12- * @param array $preReleaseParts The prerelease parts.
12+ * @param array $preReleaseParts The pre-release parts.
1313 */
1414 private function __construct ($ preReleaseParts )
1515 {
1616 $ this ->preReleaseParts = $ preReleaseParts ;
1717 }
1818
1919 /**
20- * @return PreRelease The incremented prerelease
20+ * @return PreRelease The incremented pre-release.
2121 */
2222 public function increment ()
2323 {
@@ -39,13 +39,16 @@ public function increment()
3939 }
4040
4141 /**
42- * @return string The string representation of the prerelease .
42+ * @return string The string representation of the pre-release .
4343 */
4444 public function __toString ()
4545 {
4646 return implode ('. ' , $ this ->preReleaseParts );
4747 }
4848
49+ /**
50+ * @return PreRelease The copied pre-release.
51+ */
4952 private function copy ()
5053 {
5154 return new PreRelease ($ this ->preReleaseParts );
@@ -57,20 +60,16 @@ private function copy()
5760 private function validate ()
5861 {
5962 foreach ($ this ->preReleaseParts as $ part ) {
60- if ($ this ->hasOnlyNumbers ($ part )) {
61- if (strlen ($ part ) > 1 && $ part [0 ] == "0 " ) {
62- throw new VersionFormatException (sprintf (
63- "The prerelease part '%s' is numeric but contains a leading zero. " ,
64- $ part
65- ));
66- } else {
67- continue ;
68- }
63+ if ($ this ->hasOnlyNumbers ($ part ) && strlen ($ part ) > 1 && $ part [0 ] == "0 " ) {
64+ throw new VersionFormatException (sprintf (
65+ "The pre-release part '%s' is numeric but contains a leading zero. " ,
66+ $ part
67+ ));
6968 }
7069
7170 if (!$ this ->hasOnlyAlphanumericsAndHyphen ($ part )) {
7271 throw new VersionFormatException (sprintf (
73- "The prerelease part '%s' contains invalid character. " ,
72+ "The pre-release part '%s' contains invalid character. " ,
7473 $ part
7574 ));
7675 }
@@ -79,36 +78,36 @@ private function validate()
7978
8079 /**
8180 * @param string $part part to check.
82- * @return bool True when the part is containing only numbers.
81+ * @return bool True when the part has only numbers.
8382 */
8483 private function hasOnlyNumbers ($ part )
8584 {
86- return ! preg_match ("/[^ 0-9]/ " , $ part );
85+ return preg_match ("/^[ 0-9]+$ / " , $ part );
8786 }
8887
8988 /**
9089 * @param string $part The part to check.
91- * @return bool True when the part is only containing alphanumerics.
90+ * @return bool True when the part has only alphanumerics.
9291 */
9392 private function hasOnlyAlphanumericsAndHyphen ($ part )
9493 {
95- return ! preg_match ("/[^ 0-9A-Za-z-]/ " , $ part );
94+ return preg_match ("/^[ 0-9A-Za-z-]+$ / " , $ part );
9695 }
9796
9897 /**
99- * Creates a new prerelease tag with initial default value (-0).
98+ * Creates a new pre-release tag with initial default value (-0).
10099 *
101- * @return PreRelease The default prerelease tag.
100+ * @return PreRelease The default pre-release tag.
102101 */
103102 public static function createDefault ()
104103 {
105104 return new PreRelease ([0 ]);
106105 }
107106
108107 /**
109- * @param string $preReleaseString The prerelease string.
110- * @return PreRelease The parsed prerelease part.
111- * @throws VersionFormatException When the given prerelease string is invalid.
108+ * @param string $preReleaseString The pre-release string.
109+ * @return PreRelease The parsed pre-release part.
110+ * @throws VersionFormatException When the given pre-release string is invalid.
112111 */
113112 public static function parse ($ preReleaseString )
114113 {
@@ -127,7 +126,7 @@ public static function parse($preReleaseString)
127126 * @param string|PreRelease $p1 The left side of the comparison.
128127 * @param string|PreRelease $p2 The right side of the comparison.
129128 * @return int -1 when $p1 < $p2, 0 when $p1 == $p2, 1 when $p1 > $p2.
130- * @throws VersionFormatException When the given prerelease values are invalid.
129+ * @throws VersionFormatException When the given pre-release values are invalid.
131130 */
132131 public static function compare ($ p1 , $ p2 )
133132 {
0 commit comments