Passed
Pull Request — master (#567)
by Théo
02:03
created

SymbolsRegistry::getRecordedFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the humbug/php-scoper package.
7
 *
8
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
9
 *                    Pádraic Brady <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Humbug\PhpScoper\Symbol;
16
17
use Countable;
18
use Humbug\PhpScoper\Whitelist;
19
use PhpParser\Node\Name\FullyQualified;
20
use function array_values;
21
use function count;
22
23
final class SymbolsRegistry implements Countable
24
{
25
    /**
26
     * @var array<string, array{string, string}>
27
     */
28
    private array $recordedFunctions = [];
29
30
    /**
31
     * @var array<string, array{string, string}>
32
     */
33
    private array $recordedClasses = [];
34
35
    public static function fromWhitelist(Whitelist $whitelist): self
36
    {
37
        $registry = new self();
38
39
        foreach ($whitelist->getRecordedWhitelistedFunctions() as [$original, $alias]) {
40
            $registry->recordFunction(
41
                new FullyQualified($original),
42
                new FullyQualified($alias),
43
            );
44
        }
45
46
        foreach ($whitelist->getRecordedWhitelistedClasses() as [$original, $alias]) {
47
            $registry->recordClass(
48
                new FullyQualified($original),
49
                new FullyQualified($alias),
50
            );
51
        }
52
53
        return $registry;
54
    }
55
    
56
    public function recordFunction(FullyQualified $original, FullyQualified $alias): void
57
    {
58
        $this->recordedFunctions[(string) $original] = [(string) $original, (string) $alias];
59
    }
60
61
    /**
62
     * @return list<array{string, string}>
0 ignored issues
show
Bug introduced by
The type Humbug\PhpScoper\Symbol\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
63
     */
64
    public function getRecordedFunctions(): array
65
    {
66
        return array_values($this->recordedFunctions);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_values($this->recordedFunctions) returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Symbol\list.
Loading history...
67
    }
68
69
    public function recordClass(FullyQualified $original, FullyQualified $alias): void
70
    {
71
        $this->recordedClasses[(string) $original] = [(string) $original, (string) $alias];
72
    }
73
74
    /**
75
     * @return list<array{string, string}>
76
     */
77
    public function getRecordedClasses(): array
78
    {
79
        return array_values($this->recordedClasses);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_values($this->recordedClasses) returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Symbol\list.
Loading history...
80
    }
81
82
    public function count(): int
83
    {
84
        return count($this->recordedFunctions) + count($this->recordedClasses);
85
    }
86
}
87