Passed
Push — master ( d2ad69...686350 )
by Kacper
02:44
created

StringHelper::findAll()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
crap 6
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
}