Strings::cutter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
namespace kalanis\RemoteRequest\Protocols\Fsp;
4
5
6
/**
7
 * Class Strings
8
 * @package kalanis\RemoteRequest\Protocols\Fsp
9
 * Process strings and integers in FSP
10
 */
11
class Strings
12
{
13 17
    public static function mb_chr(int $number): string
14
    {
15 17
        $part = intval(round($number / 256));
16 17
        return
17 17
            ((0 < $part) ? static::mb_chr($part) : '')
18 17
            . chr($number % 256);
19
    }
20
21 16
    public static function mb_ord(string $str): int
22
    {
23 16
        $len = strlen($str);
24 16
        $char = (1 < $len) ? substr($str, $len - 1) : $str;
25 16
        $next = (1 < $len) ? substr($str, 0, $len - 1) : '' ;
26 16
        return
27 16
            ( (!empty($next)) ? ( static::mb_ord($next) * 256 ) : 0 )
28 16
            + ord($char) ;
29
    }
30
31 17
    public static function filler(int $input, int $length): string
32
    {
33 17
        return str_pad(
34 17
            substr(static::mb_chr($input), 0, $length),
35 17
            $length,
36 17
            chr(0),
37 17
            STR_PAD_LEFT);
38
    }
39
40 16
    public static function cutter(string $data, int $start, int $length): int
41
    {
42 16
        return static::mb_ord(substr($data, $start, $length));
43
    }
44
}
45