Completed
Push — master ( dba3c8...01cd01 )
by Jean C.
07:48 queued 01:45
created

helpers.php ➔ pr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
if (!function_exists('to_cents')) {
4
    /**
5
     * convert a money amount (represented by a float or string (based on locale) ie.: R$ 5,00) to cents (represented by an int).
6
     *
7
     * @param float $amount
8
     *
9
     * @throws \UnexpectedValueException
10
     *
11
     * @return int
12
     */
13
    function to_cents(float $amount)
14
    {
15
        return Moip\Helper\Utils::toCents($amount);
16
    }
17
}
18
19
if (!function_exists('pr')) {
20
    /**
21
     * print_r() convenience function.
22
     *
23
     * In terminals this will act similar to using print_r() directly, when not run on cli
24
     * print_r() will also wrap <pre> tags around the output of given variable. Similar to debug().
25
     *
26
     * This function returns the same variable that was passed.
27
     *
28
     * @param mixed $var Variable to print out.
29
     *
30
     * @return mixed the same $var that was passed to this function
31
     *
32
     * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#pr
33
     * @see debug()
34
     */
35
    function pr($var)
36
    {
37
        $template = '<pre class="pr">%s</pre>';
38
        printf($template, trim(print_r($var, true)));
39
40
        return $var;
41
    }
42
}
43