PluginProbe
Packeta / 1.2.2
Packeta v1.2.2
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Core / Helper.php

Helper.php in Packeta 1.2.2, at src/Packetery/Core/Helper.php

69 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Helper
4 *
5 * @package Packetery
6 */
7
8 declare( strict_types=1 );
9
10
11 namespace Packetery\Core;
12
13 /**
14 * Class Helper
15 *
16 * @package Packetery
17 */
18 class Helper {
19 public const TRACKING_URL = 'https://tracking.packeta.com/?id=%s';
20 public const MYSQL_DATETIME_FORMAT = 'Y-m-d H:i:s';
21
22 /**
23 * Simplifies weight.
24 *
25 * @param float|null $weight Weight.
26 *
27 * @return float|null
28 */
29 public static function simplifyWeight( ?float $weight ): ?float {
30 return self::simplifyFloat( $weight, 3 );
31 }
32
33 /**
34 * Simplifies float value to have max decimal places.
35 *
36 * @param float|null $value Value.
37 * @param int $maxDecimalPlaces Max decimal places.
38 *
39 * @return float|null
40 */
41 public static function simplifyFloat( ?float $value, int $maxDecimalPlaces ): ?float {
42 if ( null === $value ) {
43 return null;
44 }
45
46 return (float) number_format( $value, $maxDecimalPlaces, '.', '' );
47 }
48
49 /**
50 * Returns tracking URL.
51 *
52 * @param string $packet_id Packet ID.
53 *
54 * @return string
55 */
56 public function get_tracking_url( string $packet_id ): string {
57 return sprintf( self::TRACKING_URL, rawurlencode( $packet_id ) );
58 }
59
60 /**
61 * Creates UTC DateTime.
62 *
63 * @return \DateTimeImmutable
64 */
65 public static function now(): \DateTimeImmutable {
66 return new \DateTimeImmutable( 'now', new \DateTimeZone( 'UTC' ) );
67 }
68 }
69