Passed
Push — master ( 1ba30a...8ac47c )
by Luis
01:05 queued 12s
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 10
cts 10
cp 1
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 7 1
A fromConfiguration() 0 7 2
A __construct() 0 2 1
1
<?php declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Parser;
7
8
use PhUml\Code\Codebase;
9
use PhUml\Parser\Code\PhpCodeParser;
10
use PhUml\Parser\Code\RelationshipsResolvers;
11
12
/**
13
 * It takes the files found by the `CodeFinder` and turns them into a `Codebase`
14
 *
15
 * A `Codebase` is a collection of `Definition`s (classes, interfaces and traits)
16
 *
17
 * It will call the `ExternalDefinitionsResolver` to add generic `Definition`s for classes,
18
 * interfaces and traits that do not belong directly to the current codebase
19
 *
20
 * These external definitions are either built-in or from third party libraries
21
 */
22
final class CodeParser
23
{
24 31
    public static function fromConfiguration(CodeParserConfiguration $configuration): CodeParser
25
    {
26 31
        $resolvers = $configuration->extractAssociations()
27 9
            ? RelationshipsResolvers::withAssociations()
28 22
            : RelationshipsResolvers::withoutAssociations();
29
30 31
        return new CodeParser(PhpCodeParser::fromConfiguration($configuration), $resolvers);
31
    }
32
33 31
    private function __construct(private readonly PhpCodeParser $parser, private readonly RelationshipsResolvers $resolvers)
34
    {
35
    }
36
37
    /**
38
     * The parsing process is as follows
39
     *
40
     * 1. Parse the code and populate the `Codebase` with definitions
41
     * 2. Add external definitions (built-in/third party), if needed
42
     */
43 25
    public function parse(SourceCode $sourceCode): Codebase
44
    {
45 25
        $codebase = $this->parser->parse($sourceCode);
46
47 25
        $this->resolvers->addExternalDefinitionsTo($codebase);
48
49 25
        return $codebase;
50
    }
51
}
52