PhpTrait::fromFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 9
cts 9
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace gossi\codegen\model;
5
6
use gossi\codegen\model\parts\PropertiesPart;
7
use gossi\codegen\model\parts\TraitsPart;
8
use gossi\codegen\parser\FileParser;
9
use gossi\codegen\parser\visitor\ConstantParserVisitor;
10
use gossi\codegen\parser\visitor\MethodParserVisitor;
11
use gossi\codegen\parser\visitor\PropertyParserVisitor;
12
use gossi\codegen\parser\visitor\TraitParserVisitor;
13
14
/**
15
 * Represents a PHP trait.
16
 *
17
 * @author Thomas Gossmann
18
 */
19
class PhpTrait extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface, PropertiesInterface {
20
21
	use PropertiesPart;
22
	use TraitsPart;
23
24
	/**
25
	 * Creates a PHP trait from a file
26
	 *
27
	 * @param string $filename
28
	 * @return PhpTrait
29
	 */
30 1
	public static function fromFile(string $filename): self {
31 1
		$trait = new self();
32 1
		$parser = new FileParser($filename);
33 1
		$parser->addVisitor(new TraitParserVisitor($trait));
34 1
		$parser->addVisitor(new MethodParserVisitor($trait));
35 1
		$parser->addVisitor(new ConstantParserVisitor($trait));
36 1
		$parser->addVisitor(new PropertyParserVisitor($trait));
37 1
		$parser->parse();
38
39 1
		return $trait;
40
	}
41
42
	/**
43
	 * Creates a new PHP trait
44
	 *
45
	 * @param string $name qualified name
46
	 */
47 7
	public function __construct($name = null) {
48 7
		parent::__construct($name);
49 7
		$this->initProperties();
50 7
	}
51
52
	/**
53
	 * @inheritDoc
54
	 */
55 3
	public function generateDocblock(): void {
56 3
		parent::generateDocblock();
57
58 3
		foreach ($this->properties as $prop) {
59 2
			$prop->generateDocblock();
60
		}
61 3
	}
62
}
63