Passed
Pull Request — 0.9.x (#272)
by Nikita
11:35
created

FunctionEntry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addSample() 0 9 2
1
<?php
2
3
/**
4
 * This file is part of the reliforp/reli-prof package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Reli\Converter\Callgrind;
15
16
final class FunctionEntry
17
{
18
    /** @var array<int, int> Line number to number of samples map. */
19
    public array $lineno_samples = [];
20
21
    /** @var array<string, CallEntry> Callee name and caller lineno to call entry map. */
22
    public array $calls = [];
23
24
    public function __construct(
25
        public string $function_name,
26
        public string $file_name,
27
    ) {
28
    }
29
30
    public function addSample(int $lineno, ?FunctionEntry $callee): void
31
    {
32
        if ($callee === null) {
33
            $this->lineno_samples[$lineno] ??= 0;
34
            ++$this->lineno_samples[$lineno];
35
        } else {
36
            $key = $callee->function_name . '@' . $lineno;
37
            $this->calls[$key] ??= new CallEntry($callee, $lineno);
38
            ++$this->calls[$key]->samples;
39
        }
40
    }
41
}
42