Completed
Pull Request — master (#68)
by Cristiano
05:36
created

PhpInterface   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 44
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the php-code-generator package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @license Apache-2.0
8
 */
9
10
namespace gossi\codegen\model;
11
12
use gossi\codegen\model\parts\ConstantsPart;
13
use gossi\codegen\model\parts\InterfacesPart;
14
use gossi\codegen\parser\FileParser;
15
use gossi\codegen\parser\visitor\ConstantParserVisitor;
16
use gossi\codegen\parser\visitor\InterfaceParserVisitor;
17
use gossi\codegen\parser\visitor\MethodParserVisitor;
18
use phootwork\file\exception\FileNotFoundException;
19
20
/**
21
 * Represents a PHP interface.
22
 *
23
 * @author Thomas Gossmann
24
 */
25
class PhpInterface extends AbstractPhpStruct implements GenerateableInterface, ConstantsInterface {
26
	use ConstantsPart;
27
	use InterfacesPart;
28
29 2
	/**
30 2
	 * Creates a PHP interface from file
31 2
	 *
32 2
	 * @param string $filename
33 2
	 *
34 2
	 * @throws FileNotFoundException
35 2
	 *
36
	 * @return PhpInterface
37 2
	 *
38
	 */
39
	public static function fromFile(string $filename): self {
40
		$interface = new self();
41
		$parser = new FileParser($filename);
42
		$parser->addVisitor(new InterfaceParserVisitor($interface));
43
		$parser->addVisitor(new MethodParserVisitor($interface));
44
		$parser->addVisitor(new ConstantParserVisitor($interface));
45 8
		$parser->parse();
46 8
47 8
		return $interface;
48 8
	}
49 8
50
	/**
51
	 * Create a new PHP interface
52
	 *
53
	 * @param string $name qualified name
54 3
	 */
55 3
	public function __construct(string $name = '') {
56
		parent::__construct($name);
57 3
		$this->initConstants();
58 1
		$this->initInterfaces();
59
	}
60 3
61
	/**
62
	 * @inheritDoc
63
	 */
64
	public function generateDocblock(): void {
65
		parent::generateDocblock();
66
		$this->constants->each(fn (string $key, PhpConstant $constant) => $constant->generateDocblock());
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_VARIABLE, expecting ',' or ')'
Loading history...
67
	}
68
}
69