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

PhpInterface   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 7
dl 0
loc 55
ccs 19
cts 19
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromFile() 0 10 1
A __construct() 0 5 1
A fromReflection() 0 3 1
A generateDocblock() 0 7 2
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 reflection
23
	 *
24
	 * @deprecated Use fromFile() instead
25
	 * @param \ReflectionClass $ref
26
	 * @return PhpInterface
27
	 */
28
	public static function fromReflection(\ReflectionClass $ref) {
29
		return static::fromFile($ref->getFileName());
30
	}
31
32
	/**
33
	 * Creates a PHP interface from file
34
	 *
35
	 * @param string $filename
36
	 * @return PhpInterface
37
	 */
38 3
	public static function fromFile($filename) {
39 3
		$interface = new PhpInterface();
40 3
		$parser = new FileParser($filename);
41 3
		$parser->addVisitor(new InterfaceParserVisitor($interface));
42 3
		$parser->addVisitor(new MethodParserVisitor($interface));
43 3
		$parser->addVisitor(new ConstantParserVisitor($interface));
44 3
		$parser->parse();
45
		
46 3
		return $interface;
47
	}
48
49
	/**
50
	 * Create a new PHP interface
51
	 *
52
	 * @param string $name qualified name
53
	 */
54 10
	public function __construct($name = null) {
55 10
		parent::__construct($name);
56 10
		$this->initConstants();
57 10
		$this->initInterfaces();
58 10
	}
59
60
	/**
61
	 * @inheritDoc
62
	 */
63 4
	public function generateDocblock() {
64 4
		parent::generateDocblock();
65
66 4
		foreach ($this->constants as $constant) {
67 1
			$constant->generateDocblock();
68 4
		}
69 4
	}
70
}
71