Issues (22)

src/helpers/App.php (2 issues)

1
<?php
2
3
4
namespace Alkoumi\LaravelArabicTafqeet\Helpers;
5
6
7
trait App
8
{
9
10
    public function runBeforeComma()
11
    {
12
        $number = null;
13
        for ($i=0; $i < count($this->before_comma_array); $i++){
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
14
            $num = $this->before_comma_array[$i];
15
            $number = $number.$num;
16
        };
17
            $f = new \NumberFormatter("ar", \NumberFormatter::SPELLOUT);
18
            return $f->format($number);
0 ignored issues
show
It seems like $number can also be of type string; however, parameter $value of NumberFormatter::format() does only seem to accept double|integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

18
            return $f->format(/** @scrutinizer ignore-type */ $number);
Loading history...
19
    }
20
21
22
    public function runAfterComma()
23
    {
24
        $class =  $this->detectClass($this->after_comma_len);
25
        $methodName = 'Class' . $class;
26
        if(method_exists($this,$methodName))
27
        {
28
            return $this->$methodName($this->after_comma_array,$this->after_comma_len);
29
        }
30
        return 'عفوا هذا الرقم خارج نطاقنا حاليا حاول لاحقاً';
31
    }
32
33
34
    public function detectClass($len)
35
    {
36
        if($len == 1)
37
             return "A";
38
39
40
        if($len == 2)
41
            return "B";
42
43
44
        if($len == 3)
45
            return "C";
46
47
48
        if($len == 4)
49
            return "D";
50
51
52
        if($len == 5)
53
            return "E";
54
55
        if($len == 6)
56
            return "F";
57
58
        if($len == 7)
59
            return "G";
60
61
        if($len == 8)
62
            return "H";
63
64
        if($len == 9)
65
            return "I";
66
67
    }
68
}
69