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

StringHelper::find()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 27
ccs 0
cts 17
cp 0
rs 8.8571
cc 3
eloc 16
nc 4
nop 4
crap 12
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
}