PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.24
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.24
1.10.24 1.10.23 1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 All 168 releases
woocommerce-pos / vendor_prefixed / sentry / sentry / src / Serializer / RepresentationSerializer.php

RepresentationSerializer.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.24, at vendor_prefixed/sentry/sentry/src/Serializer/RepresentationSerializer.php

68 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WCPOS\Vendor\Sentry\Serializer;
5
6 /**
7 * Serializes a value into a representation that should reasonably suggest
8 * both the type and value, and be serializable into JSON.
9 */
10 class RepresentationSerializer extends AbstractSerializer implements RepresentationSerializerInterface
11 {
12 /**
13 * {@inheritdoc}
14 */
15 public function representationSerialize($value)
16 {
17 $value = $this->serializeRecursively($value);
18 if (\is_numeric($value)) {
19 return (string) $value;
20 }
21 if (\is_bool($value)) {
22 return $value ? 'true' : 'false';
23 }
24 return $value;
25 }
26 /**
27 * This method is overridden to return even basic types as strings.
28 *
29 * @param mixed $value The value that needs to be serialized
30 *
31 * @return string
32 */
33 protected function serializeValue($value)
34 {
35 if ($value === null) {
36 return 'null';
37 }
38 if ($value === \false) {
39 return 'false';
40 }
41 if ($value === \true) {
42 return 'true';
43 }
44 if (\is_float($value)) {
45 if (\is_nan($value)) {
46 return 'NAN';
47 }
48 if ($this->isCastableToInt($value) && (int) $value == $value) {
49 return $value . '.0';
50 }
51 }
52 if (\is_numeric($value)) {
53 return (string) $value;
54 }
55 return (string) parent::serializeValue($value);
56 }
57 /**
58 * Casting a non-finite float, or one that falls outside of the integer
59 * range, raises a warning as of PHP 8.5.
60 *
61 * @param float $value The value to check
62 */
63 private function isCastableToInt(float $value) : bool
64 {
65 return $value >= (float) \PHP_INT_MIN && $value < (float) \PHP_INT_MAX;
66 }
67 }
68