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

PhpInterface::fromFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

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