Passed
Pull Request — 0.6.x (#221)
by
unknown
01:39
created

Elf64LazyParseSymbolResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 6 2
A loadResolver() 0 12 3
A __construct() 0 7 1
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\Lib\Elf\Process;
15
16
use Reli\Lib\Elf\Parser\ElfParserException;
17
use Reli\Lib\Elf\Structure\Elf64\Elf64SymbolTableEntry;
18
use Reli\Lib\Elf\SymbolResolver\Elf64SymbolResolver;
19
use Reli\Lib\Elf\SymbolResolver\SymbolResolverCreatorInterface;
20
use Reli\Lib\Process\MemoryMap\ProcessModuleMemoryMap;
21
use Reli\Lib\Process\MemoryReader\MemoryReaderInterface;
22
23
final class Elf64LazyParseSymbolResolver implements Elf64SymbolResolver
24
{
25
    private ?Elf64SymbolResolver $resolver_cache = null;
26
27
    public function __construct(
28
        private string $path,
29
        private MemoryReaderInterface $memory_reader,
30
        private int $pid,
31
        private ProcessModuleMemoryMap $module_memory_map,
32
        private SymbolResolverCreatorInterface $symbol_resolver_creator,
33
    ) {
34
    }
35
36
    private function loadResolver(): Elf64SymbolResolver
37
    {
38
        try {
39
            return $this->symbol_resolver_creator->createLinearScanResolverFromPath($this->path);
40
        } catch (ElfParserException $e) {
41
            try {
42
                return $this->symbol_resolver_creator->createDynamicResolverFromPath($this->path);
43
            } catch (ElfParserException $e) {
44
                return $this->symbol_resolver_creator->createDynamicResolverFromProcessMemory(
45
                    $this->memory_reader,
46
                    $this->pid,
47
                    $this->module_memory_map
48
                );
49
            }
50
        }
51
    }
52
53
    public function resolve(string $symbol_name): Elf64SymbolTableEntry
54
    {
55
        if (!isset($this->resolver_cache)) {
56
            $this->resolver_cache = $this->loadResolver();
57
        }
58
        return $this->resolver_cache->resolve($symbol_name);
0 ignored issues
show
Bug introduced by
The method resolve() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        return $this->resolver_cache->/** @scrutinizer ignore-call */ resolve($symbol_name);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
    }
60
}
61