Useful::mb_str_pad()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
namespace kalanis\kw_clipr\Clipr;
4
5
6
use kalanis\kw_input\Interfaces\IEntry;
7
use kalanis\kw_input\Parsers\Cli;
8
9
10
/**
11
 * Class Useful
12
 * @package kalanis\kw_clipr\Clipr
13
 */
14
class Useful
15
{
16
    /**
17
     * mb_str_pad
18
     *
19
     * @param string $input
20
     * @param int $pad_length
21
     * @param string $pad_string
22
     * @param int $pad_type
23
     * @return string
24
     * @author Kari "Haprog" Sderholm https://gist.github.com/nebiros/226350
25
     */
26 10
    public static function mb_str_pad(string $input, int $pad_length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT): string
27
    {
28 10
        $diff = strlen( $input ) - mb_strlen( $input );
29 10
        return str_pad( $input, $pad_length + $diff, $pad_string, $pad_type );
30
    }
31
32
    /**
33
     * get nth param from input array
34
     * @param iterable<IEntry> $inputs
35
     * @param int $position
36
     * @return string|null
37
     */
38 6
    public static function getNthParam(iterable $inputs, int $position = 1): ?string
39
    {
40 6
        $nthKey = Cli::UNSORTED_PARAM . $position;
41 6
        foreach ($inputs as $input) {
42
            /** @var IEntry $input */
43 6
            if ($input->getKey() == $nthKey) {
44 2
                return $input->getValue();
45
            }
46
        }
47 5
        return null;
48
    }
49
50 14
    public static function sanitizeClass(string $input): string
51
    {
52 14
        $input = strtr($input, [':' => '\\', '/' => '\\']);
53 14
        return ('\\' == $input[0]) ? mb_substr($input, 1) : $input ;
54
    }
55
56 5
    public static function getTaskCall(object $class): string
57
    {
58 5
        return strtr(get_class($class), '\\', '/');
59
    }
60
}
61