Completed
Push — master ( d075bd...c77af7 )
by Thomas
03:19
created

PhpTrait::fromReflection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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