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

PhpTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 8
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\PropertiesPart;
13
use gossi\codegen\model\parts\TraitsPart;
14
use gossi\codegen\parser\FileParser;
15
use gossi\codegen\parser\visitor\ConstantParserVisitor;
16
use gossi\codegen\parser\visitor\MethodParserVisitor;
17
use gossi\codegen\parser\visitor\PropertyParserVisitor;
18
use gossi\codegen\parser\visitor\TraitParserVisitor;
19
use phootwork\file\exception\FileNotFoundException;
20
21
/**
22
 * Represents a PHP trait.
23
 *
24
 * @author Thomas Gossmann
25
 */
26
class PhpTrait extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface, PropertiesInterface {
27
	use PropertiesPart;
28
	use TraitsPart;
29
30 1
	/**
31 1
	 * Creates a PHP trait from a file
32 1
	 *
33 1
	 * @param string $filename
34 1
	 *
35 1
	 * @throws FileNotFoundException
36 1
	 *
37 1
	 * @return PhpTrait
38
	 *
39 1
	 */
40
	public static function fromFile(string $filename): self {
41
		$trait = new self();
42
		$parser = new FileParser($filename);
43
		$parser->addVisitor(new TraitParserVisitor($trait));
44
		$parser->addVisitor(new MethodParserVisitor($trait));
45
		$parser->addVisitor(new ConstantParserVisitor($trait));
46
		$parser->addVisitor(new PropertyParserVisitor($trait));
47 7
		$parser->parse();
48 7
49 7
		return $trait;
50 7
	}
51
52
	/**
53
	 * Creates a new PHP trait
54
	 *
55 3
	 * @param string $name qualified name
56 3
	 */
57
	public function __construct(string $name = '') {
58 3
		parent::__construct($name);
59 2
		$this->initProperties();
60
		$this->initTraits();
61 3
	}
62
63
	/**
64
	 * @inheritDoc
65
	 */
66
	public function generateDocblock(): void {
67
		parent::generateDocblock();
68
		$this->properties->each(fn (string $key, PhpProperty $prop) => $prop->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...
69
	}
70
}
71