Passed
Push — master ( 1416ae...b5a8b1 )
by Luis
54s queued 13s
created

CodeParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 28
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 4
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Parser;
9
10
use PhUml\Code\Codebase;
11
use PhUml\Parser\Code\PhpCodeParser;
12
use PhUml\Parser\Code\RelationshipsResolvers;
13
14
/**
15
 * It takes the files found by the `CodeFinder` and turns them into a `Codebase`
16
 *
17
 * A `Codebase` is a collection of `Definition`s (classes, interfaces and traits)
18
 *
19
 * It will call the `ExternalDefinitionsResolver` to add generic `Definition`s for classes,
20
 * interfaces and traits that do not belong directly to the current codebase
21
 *
22
 * These external definitions are either built-in or from third party libraries
23
 */
24
final class CodeParser
25
{
26 31
    public static function fromConfiguration(CodeParserConfiguration $configuration): CodeParser
27
    {
28 31
        $resolvers = $configuration->extractAssociations()
29 9
            ? RelationshipsResolvers::withAssociations()
30 22
            : RelationshipsResolvers::withoutAssociations();
31
32 31
        return new CodeParser(PhpCodeParser::fromConfiguration($configuration), $resolvers);
33
    }
34
35 31
    private function __construct(private readonly PhpCodeParser $parser, private readonly RelationshipsResolvers $resolvers)
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 35 at column 50
Loading history...
36
    {
37
    }
38
39
    /**
40
     * The parsing process is as follows
41
     *
42
     * 1. Parse the code and populate the `Codebase` with definitions
43
     * 2. Add external definitions (built-in/third party), if needed
44
     */
45 25
    public function parse(SourceCode $sourceCode): Codebase
46
    {
47 25
        $codebase = $this->parser->parse($sourceCode);
48
49 25
        $this->resolvers->addExternalDefinitionsTo($codebase);
50
51 25
        return $codebase;
52
    }
53
}
54