PhpInterface::fromFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

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