Completed
Push — master ( 5be53c...92f243 )
by Thomas
03:28
created

PhpClass::fromReflection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace gossi\codegen\model;
3
4
use gossi\codegen\model\parts\AbstractPart;
5
use gossi\codegen\model\parts\ConstantsPart;
6
use gossi\codegen\model\parts\FinalPart;
7
use gossi\codegen\model\parts\InterfacesPart;
8
use gossi\codegen\model\parts\PropertiesPart;
9
use gossi\codegen\model\parts\TraitsPart;
10
use gossi\codegen\parser\FileParser;
11
use gossi\codegen\parser\visitor\ClassParserVisitor;
12
use gossi\codegen\parser\visitor\ConstantParserVisitor;
13
use gossi\codegen\parser\visitor\MethodParserVisitor;
14
use gossi\codegen\parser\visitor\PropertyParserVisitor;
15
16
/**
17
 * Represents a PHP class.
18
 *
19
 * @author Thomas Gossmann
20
 */
21
class PhpClass extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface, ConstantsInterface, PropertiesInterface {
22
23
	use AbstractPart;
24
	use ConstantsPart;
25
	use FinalPart;
26
	use InterfacesPart;
27
	use PropertiesPart;
28
	use TraitsPart;
29
30
	/** @var string */
31
	private $parentClassName;
32
33
	/**
34
	 * Creates a PHP class from file
35
	 *
36
	 * @param string $filename
37
	 * @return PhpClass
38
	 */
39 10
	public static function fromFile($filename) {
40 10
		$class = new PhpClass();
41 10
		$parser = new FileParser($filename);
42 10
		$parser->addVisitor(new ClassParserVisitor($class));
43 10
		$parser->addVisitor(new MethodParserVisitor($class));
44 10
		$parser->addVisitor(new ConstantParserVisitor($class));
45 10
		$parser->addVisitor(new PropertyParserVisitor($class));
46 10
		$parser->parse();
47
		
48 10
		return $class;
49 1
	}
50
51
	/**
52
	 * Creates a new PHP class
53
	 *
54
	 * @param string $name the qualified name
55
	 */
56 44
	public function __construct($name = null) {
57 44
		parent::__construct($name);
58 44
		$this->initProperties();
59 44
		$this->initConstants();
60 44
		$this->initInterfaces();
61 44
	}
62
63
	/**
64
	 * Returns the parent class name
65
	 *
66
	 * @return string
67
	 */
68 14
	public function getParentClassName() {
69 14
		return $this->parentClassName;
70
	}
71
72
	/**
73
	 * Sets the parent class name
74
	 *
75
	 * @param string|null $name the new parent
76
	 * @return $this
77
	 */
78 4
	public function setParentClassName($name) {
79 4
		$this->parentClassName = $name;
80
81 4
		return $this;
82
	}
83
84 5
	public function generateDocblock() {
85 5
		parent::generateDocblock();
86
87 5
		foreach ($this->constants as $constant) {
88 2
			$constant->generateDocblock();
89 5
		}
90
91 5
		foreach ($this->properties as $prop) {
92 3
			$prop->generateDocblock();
93 5
		}
94 5
	}
95
96
}
97