PhpUtilities   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 68
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isStringEnglish() 0 7 2
A parseNumber() 0 4 2
A getPercentageAmount() 0 4 1
A getAmountPercentage() 0 4 1
1
<?php
2
3
namespace Bhavingajjar\PhpUtilities;
4
5
class PhpUtilities
6
{
7
    /*
8
     * ================
9
     * String Functions
10
     * ================
11
     * */
12
    /**
13
     * isStringEnglish will check the input string is in english or not
14
     * @param $str
15
     * @return bool
16
     */
17
    public static function isStringEnglish($str): bool
18
    {
19
        if (strlen($str) !== strlen(utf8_decode($str)))
20
            return false;
21
        else
22
            return true;
23
    }
24
    /*
25
     * ================
26
     * String Functions
27
     * ================
28
     * */
29
30
    /*
31
     * ================
32
     * Number Functions
33
     * ================
34
     * */
35
    /**
36
     * parseNumber will get input as value as string or number and return float or integer number
37
     * @param $value
38
     * @return float|int
39
     */
40
    public static function parseNumber($value)
41
    {
42
        return ($value == (int)$value) ? (int)$value : (float)$value;
43
    }
44
45
    /**
46
     * getPercentageAmount will get input as amount & percentage as number and return percentage amount
47
     * @param $amount
48
     * @param $percentage
49
     * @return float|int
50
     */
51
    public static function getPercentageAmount($amount, $percentage)
52
    {
53
        return self::parseNumber((($percentage / 100) * $amount));
54
    }
55
56
    /**
57
     * getAmountPercentage will get input as amount & total as number and return amount percentage
58
     * @param $amount
59
     * @param $total
60
     * @return float|int
61
     */
62
    public static function getAmountPercentage($amount, $total)
63
    {
64
        return self::parseNumber((($amount * 100) / $total));
65
    }
66
67
    /*
68
     * ================
69
     * Number Functions
70
     * ================
71
     * */
72
}
73