@@ -46,15 +46,15 @@ class UserAgentParser
4646
4747 /**
4848 * Version
49- * @var int|string|null
49+ * @var float| int|string|null
5050 */
5151 private $ version ;
5252
5353 /**
5454 * UserAgentParser constructor
5555 *
5656 * @param string $product
57- * @param int|string|null $version
57+ * @param float| int|string|null $version
5858 */
5959 public function __construct ($ product , $ version = null )
6060 {
@@ -94,7 +94,7 @@ private function validateProduct()
9494 $ this ->blacklistCheck ($ this ->product );
9595 $ this ->originProduct = $ this ->product ;
9696 if ($ this ->originProduct !== ($ this ->product = preg_replace (self ::PREG_PATTERN , '' , $ this ->product ))) {
97- trigger_error ("Product name contains invalid characters. Truncated to ` $ this ->product `. " , E_USER_WARNING );
97+ trigger_error ("Product name contains invalid characters. Truncated to ` $ this ->product `. " , E_USER_NOTICE );
9898 }
9999 if (empty ($ this ->product )) {
100100 throw new ProductException ('Product string cannot be empty. ' );
@@ -105,7 +105,7 @@ private function validateProduct()
105105 /**
106106 * Check for blacklisted strings or characters
107107 *
108- * @param int|string|null $input
108+ * @param float| int|string|null $input
109109 * @return bool
110110 * @throws FormatException
111111 */
@@ -137,7 +137,7 @@ private function validateVersion()
137137 if (
138138 !empty ($ this ->version ) &&
139139 (
140- preg_match ( ' /[^0-9.]/ ' , $ this ->version ) ||
140+ str_replace ( ' + ' , '' , filter_var ( $ this ->version , FILTER_SANITIZE_NUMBER_FLOAT , FILTER_FLAG_ALLOW_FRACTION ) ) ||
141141 version_compare ($ this ->version , '0.0.1 ' , '>= ' ) === false
142142 )
143143 ) {
@@ -154,7 +154,9 @@ private function validateVersion()
154154 */
155155 public function getUserAgent ()
156156 {
157- return trim ($ this ->getProduct () . '/ ' . $ this ->getVersion (), '/ ' );
157+ $ product = $ this ->getProduct ();
158+ $ version = $ this ->getVersion ();
159+ return $ version === null ? $ product : $ product . '/ ' . $ version ;
158160 }
159161
160162 /**
@@ -170,7 +172,7 @@ public function getProduct()
170172 /**
171173 * Get version
172174 *
173- * @return string|null
175+ * @return float|int| string|null
174176 */
175177 public function getVersion ()
176178 {
@@ -215,7 +217,7 @@ public function getUserAgents()
215217 /**
216218 * Get versions
217219 *
218- * @return int[]|string[]
220+ * @return float[]| int[]|string[]
219221 */
220222 public function getVersions ()
221223 {
0 commit comments