App::detectClass()   B
last analyzed

Complexity

Conditions 10
Paths 10

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 10
eloc 18
c 3
b 1
f 0
nc 10
nop 1
dl 0
loc 32
rs 7.6666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
Bug introduced by
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