ArabicNumbers::transform()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 3
rs 10
1
<?php
2
3
namespace Maklad\ArabicNumbers\Http\Middleware;
4
5
use Illuminate\Foundation\Http\Middleware\TransformsRequest;
6
7
class ArabicNumbers extends TransformsRequest
8
{
9
    /**
10
     * The attributes that should not be trimmed.
11
     *
12
     * @var array
13
     */
14
    protected $except = [
15
        //
16
    ];
17
18
    /**
19
     * Transform the given value.
20
     *
21
     * @param  string $key
22
     * @param  mixed $value
23
     * @return mixed
24
     */
25 4
    protected function transform($key, $value)
26
    {
27 4
        if ((! is_string($value)) || in_array($key, $this->except, true)) {
28 2
            return $value;
29
        }
30
31 4
        $eastern = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
32 4
        $western = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
33 4
        return str_replace($eastern, $western, $value);
34 4
    }
35
}
36