PhpFunction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
declare(strict_types=1);
18
19
namespace gossi\codegen\model;
20
21
use gossi\codegen\model\parts\BodyPart;
22
use gossi\codegen\model\parts\DocblockPart;
23
use gossi\codegen\model\parts\LongDescriptionPart;
24
use gossi\codegen\model\parts\ParametersPart;
25
use gossi\codegen\model\parts\QualifiedNamePart;
26
use gossi\codegen\model\parts\ReferenceReturnPart;
27
use gossi\codegen\model\parts\TypeDocblockGeneratorPart;
28
use gossi\codegen\model\parts\TypePart;
29
use gossi\docblock\Docblock;
30
use gossi\docblock\tags\ReturnTag;
31
32
/**
33
 * Represents a PHP function.
34
 *
35
 * @author Johannes M. Schmitt <[email protected]>
36
 * @author Thomas Gossmann
37
 * @deprecated Not a structural model. Please refer to https://github.com/gossi/php-code-generator/issues/35 and join the discussion if you really need this
38
 */
39
class PhpFunction extends AbstractModel implements GenerateableInterface, NamespaceInterface, DocblockInterface, RoutineInterface {
40
41
	use BodyPart;
42
	use DocblockPart;
43
	use LongDescriptionPart;
44
	use ParametersPart;
45
	use QualifiedNamePart;
46
	use ReferenceReturnPart;
47
	use TypeDocblockGeneratorPart;
48
	use TypePart;
49
50
// 	/**
51
// 	 * Creates a PHP function from reflection
52
// 	 *
53
// 	 * @deprecated will be removed in version 0.5
54
// 	 * @param \ReflectionFunction $ref
55
// 	 * @return PhpFunction
56
// 	 */
57
// 	public static function fromReflection(\ReflectionFunction $ref) {
58
// 		$function = self::create($ref->name)
59
// 			->setReferenceReturned($ref->returnsReference())
60
// 			->setBody(ReflectionUtils::getFunctionBody($ref));
61
62
// 		$docblock = new Docblock($ref);
63
// 		$function->setDocblock($docblock);
64
// 		$function->setDescription($docblock->getShortDescription());
65
// 		$function->setLongDescription($docblock->getLongDescription());
66
67
// 		foreach ($ref->getParameters() as $refParam) {
68
// 			assert($refParam instanceof \ReflectionParameter); // hmm - assert here?
69
70
// 			$param = PhpParameter::fromReflection($refParam);
71
// 			$function->addParameter($param);
72
// 		}
73
74
// 		return $function;
75
// 	}
76
77
	/**
78
	 * Creates a new PHP function
79
	 *
80
	 * @param string $name qualified name
81
	 * @return static
82
	 */
83 6
	public static function create($name = null) {
84 6
		return new static($name);
0 ignored issues
show
Deprecated Code introduced by
The class gossi\codegen\model\PhpFunction has been deprecated with message: Not a structural model. Please refer to https://github.com/gossi/php-code-generator/issues/35 and join the discussion if you really need this

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
85
	}
86
87
	/**
88
	 * Creates a new PHP function
89
	 *
90
	 * @param string $name qualified name
91
	 */
92 9
	public function __construct($name = null) {
93 9
		$this->setQualifiedName($name);
94 9
		$this->docblock = new Docblock();
95 9
		$this->initParameters();
96 9
	}
97
98
	/**
99
	 * @inheritDoc
100
	 */
101 3
	public function generateDocblock(): void {
102 3
		$docblock = $this->getDocblock();
103 3
		$docblock->setShortDescription($this->getDescription());
104 3
		$docblock->setLongDescription($this->getLongDescription());
105
106
		// return tag
107 3
		$this->generateTypeTag(new ReturnTag());
108
109
		// param tags
110 3
		$this->generateParamDocblock();
111 3
	}
112
}
113