Passed
Push — master ( 203740...2c4c0a )
by Kacper
04:22
created

StringHelper::positionToLine()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
crap 2
1
<?php
2
/**
3
 * Highlighter
4
 *
5
 * Copyright (C) 2015, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Highlighter\Utils;
17
18
class StringHelper
19
{
20 1
    public static function positionToLine($source, $pos)
21
    {
22 1
        $source = substr($source, 0, $pos);
23 1
        $last = strripos($source, PHP_EOL);
24 1
        if ($last !== false) {
25 1
            $last += strlen(PHP_EOL);
26 1
        }
27
28
        return [
29 1
            'line' => substr_count($source, PHP_EOL) + 1,
30 1
            'pos'  => $pos - $last + 1,
31 1
        ];
32
    }
33
34 2
    public static function pop($string, $delimiter = '.') {
35 2
        $array = explode($delimiter, $string);
36 2
        array_pop($array);
37 2
        return implode($delimiter, $array);
38
    }
39
}