FunctionTrait::findFunctionNameIndex()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright MediaCT. All rights reserved.
5
 * https://www.mediact.nl
6
 */
7
8
namespace Mediact\CodingStandard;
9
10
use PHP_CodeSniffer\Files\File;
11
12
trait FunctionTrait
13
{
14
    /**
15
     * Get a function name.
16
     *
17
     * @param File $file
18
     * @param int  $functionIndex
19
     *
20
     * @return bool|string
21
     */
22
    protected function getFunctionName(File $file, $functionIndex)
23
    {
24
        $index = $this->findFunctionNameIndex($file, $functionIndex);
25
        return $index
26
            ? $file->getTokens()[$index]['content']
27
            : false;
28
    }
29
30
    /**
31
     * Find the function name index.
32
     *
33
     * @param File $file
34
     * @param int  $functionIndex
35
     *
36
     * @return bool|int
37
     */
38
    protected function findFunctionNameIndex(File $file, $functionIndex)
39
    {
40
        return $file->findNext([T_STRING], $functionIndex);
41
    }
42
43
    /**
44
     * Find the start of a function body.
45
     *
46
     * @param File $file
47
     * @param int  $functionIndex
48
     *
49
     * @return bool|int
50
     */
51
    protected function findFunctionBodyStartIndex(File $file, $functionIndex)
52
    {
53
        return $file->findNext([T_SEMICOLON, T_OPEN_CURLY_BRACKET], $functionIndex);
54
    }
55
}
56