PhpTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 8
dl 0
loc 44
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromFile() 0 11 1
A __construct() 0 4 1
A generateDocblock() 0 7 2
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