Elf64LinearScanSymbolResolver::resolve()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 2
b 0
f 0
nc 3
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler 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 PhpProfiler\Lib\Elf\SymbolResolver;
15
16
use PhpProfiler\Lib\Elf\Structure\Elf64\Elf64StringTable;
17
use PhpProfiler\Lib\Elf\Structure\Elf64\Elf64SymbolTable;
18
use PhpProfiler\Lib\Elf\Structure\Elf64\Elf64SymbolTableEntry;
19
20
final class Elf64LinearScanSymbolResolver implements Elf64AllSymbolResolver
21
{
22
    public function __construct(
23
        private Elf64SymbolTable $symbol_table,
24
        private Elf64StringTable $string_table,
25
    ) {
26
    }
27
28
    public function resolve(string $symbol_name): Elf64SymbolTableEntry
29
    {
30
        $all_symbols = $this->symbol_table->findAll();
31
        foreach ($all_symbols as $entry) {
32
            $name = $this->string_table->lookup($entry->st_name);
33
            if ($symbol_name === $name) {
34
                return $entry;
35
            }
36
        }
37
        return $all_symbols[Elf64SymbolTable::STN_UNDEF];
38
    }
39
}
40