|
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\Code\Builders; |
|
9
|
|
|
|
|
10
|
|
|
use PhpParser\Node\Stmt\Class_; |
|
11
|
|
|
use PhUml\Code\ClassDefinition; |
|
12
|
|
|
use PhUml\Code\Name as ClassDefinitionName; |
|
13
|
|
|
use PhUml\Parser\Code\Builders\Names\InterfaceNamesBuilder; |
|
14
|
|
|
use PhUml\Parser\Code\Builders\Names\TraitNamesBuilder; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* It builds a `ClassDefinition` |
|
18
|
|
|
* |
|
19
|
|
|
* @see MembersBuilder |
|
20
|
|
|
* @see InterfaceNamesBuilder |
|
21
|
|
|
* @see TraitNamesBuilder |
|
22
|
|
|
*/ |
|
23
|
|
|
final class ClassDefinitionBuilder |
|
24
|
|
|
{ |
|
25
|
|
|
use InterfaceNamesBuilder; |
|
26
|
|
|
use TraitNamesBuilder; |
|
27
|
|
|
|
|
28
|
41 |
|
public function __construct( |
|
29
|
|
|
private readonly MembersBuilder $membersBuilder, |
|
|
|
|
|
|
30
|
|
|
private readonly UseStatementsBuilder $useStatementsBuilder, |
|
31
|
|
|
private readonly AttributeAnalyzer $analyzer |
|
32
|
|
|
) { |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
30 |
|
public function build(Class_ $class): ClassDefinition |
|
36
|
|
|
{ |
|
37
|
30 |
|
$useStatements = $this->useStatementsBuilder->build($class); |
|
38
|
|
|
|
|
39
|
30 |
|
return new ClassDefinition( |
|
40
|
30 |
|
new ClassDefinitionName((string) $class->namespacedName), |
|
41
|
30 |
|
$this->membersBuilder->methods($class->getMethods(), $useStatements), |
|
42
|
30 |
|
$this->membersBuilder->constants($class->stmts), |
|
43
|
30 |
|
$class->extends !== null ? new ClassDefinitionName((string) $class->extends) : null, |
|
44
|
30 |
|
$this->membersBuilder->properties($class->stmts, $class->getMethod('__construct'), $useStatements), |
|
45
|
30 |
|
$this->buildInterfaces($class->implements), |
|
46
|
30 |
|
$this->buildTraits($class->stmts), |
|
47
|
30 |
|
$this->analyzer->isAttribute($class) |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|