Number   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A zeroFill() 0 17 3
1
<?php
2
namespace MrPrompt\ShipmentCommon\Util;
3
4
/**
5
 * Class Number
6
 * @package Centercob\Common\Util
7
 *
8
 * @author Walter Discher Cechinel <[email protected]>
9
 */
10
abstract class Number
11
{
12
    const FILL_LEFT  = 0;
13
    const FILL_RIGHT = 1;
14
15
    /**
16
     * @param $value
17
     * @param $length
18
     * @param int $fillSide
19
     * @return string
20
     * @throws \InvalidArgumentException
21
     */
22 6
    public static function zeroFill($value = '', $length = 0, $fillSide = self::FILL_LEFT)
23
    {
24 6
        $valueLength = strlen($value);
25
26 6
        if ($valueLength == $length) {
27 1
            return $value;
28
        }
29
30 5
        if ($valueLength > $length) {
31 1
            throw new \InvalidArgumentException(sprintf(
32 1
                'The given value (%s) is invalid',
33 1
                $value
34
            ));
35
        }
36
37 4
        return str_pad($value, $length, 0, $fillSide);
38
    }
39
}
40