GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DataFormat   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 0
dl 0
loc 111
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A toSom() 0 4 1
A toCoins() 0 4 1
A timestamp() 0 8 2
A timestamp2seconds() 0 9 2
A timestamp2milliseconds() 0 9 2
A timestamp2datetime() 0 10 2
A datetime2timestamp() 0 8 2
A toDateTime() 0 3 1
A toDateTimeWithTimeZone() 0 3 1
1
<?php
2
namespace Goodoneuz\PayUz\Http\Classes;
3
4
class DataFormat{
5
    /**
6
     * Converts coins to som.
7
     * @param int|string $coins coins.
8
     * @return float coins converted to som.
9
     */
10
    public static function toSom($coins)
11
    {
12
        return 1 * $coins / 100;
13
    }
14
15
    /**
16
     * Converts som to coins.
17
     * @param float $amount
18
     * @return int
19
     */
20
    public static function toCoins($amount)
21
    {
22
        return round(1 * $amount * 100);
23
    }
24
25
    /**
26
     * Get current timestamp in seconds or milliseconds.
27
     * @param bool $milliseconds true - get timestamp in milliseconds, false - in seconds.
28
     * @return int current timestamp value
29
     */
30
    public static function timestamp($milliseconds = false)
31
    {
32
        if ($milliseconds) {
33
            return round(microtime(true) * 1000); // milliseconds
34
        }
35
36
        return time(); // seconds
37
    }
38
39
    /**
40
     * Converts timestamp value from milliseconds to seconds.
41
     * @param int $timestamp timestamp in milliseconds.
42
     * @return int timestamp in seconds.
43
     */
44
    public static function timestamp2seconds($timestamp)
45
    {
46
        // is it already as seconds
47
        if (strlen((string)$timestamp) == 10) {
48
            return $timestamp;
49
        }
50
51
        return floor(1 * $timestamp / 1000);
52
    }
53
54
    /**
55
     * Converts timestamp value from seconds to milliseconds.
56
     * @param int $timestamp timestamp in seconds.
57
     * @return int timestamp in milliseconds.
58
     */
59
    public static function timestamp2milliseconds($timestamp)
60
    {
61
        // is it already as milliseconds
62
        if (strlen((string)$timestamp) == 13) {
63
            return $timestamp;
64
        }
65
66
        return $timestamp * 1000;
67
    }
68
69
    /**
70
     * Converts timestamp to date time string.
71
     * @param int $timestamp timestamp value as seconds or milliseconds.
72
     * @return string string representation of the timestamp value in 'Y-m-d H:i:s' format.
73
     */
74
    public static function timestamp2datetime($timestamp)
75
    {
76
        // if as milliseconds, convert to seconds
77
        if (strlen((string)$timestamp) == 13) {
78
            $timestamp = self::timestamp2seconds($timestamp);
79
        }
80
81
        // convert to datetime string
82
        return date('Y-m-d H:i:s', strtotime($timestamp));
83
    }
84
85
    /**
86
     * Converts date time string to timestamp value.
87
     * @param string $datetime date time string.
88
     * @return int timestamp as seconds.
89
     */
90
    public static function datetime2timestamp($datetime)
91
    {
92
        if ($datetime) {
93
            return strtotime($datetime);
94
        }
95
96
        return $datetime;
97
    }
98
99
    /**
100
     * @param $time '2018-11-06T17:39:31+05:00'
101
     * @return false|string
102
     */
103
    public static function toDateTime($time){
104
        return date('Y-m-d H:i:s',strtotime($time));
105
    }
106
107
    /**
108
     * @param $time '2018-11-06 17:39:31'
109
     * @return string
110
     */
111
    public static function toDateTimeWithTimeZone($time){
112
        return date('Y-m-d\TH:i:s',strtotime($time)) . '+05:00';
113
    }
114
}