Completed
Push — master ( 5be53c...92f243 )
by Thomas
03:28
created

PhpFunction::fromReflection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
ccs 13
cts 13
cp 1
rs 9.4285
cc 2
eloc 13
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
namespace gossi\codegen\model;
19
20
use gossi\codegen\model\parts\BodyPart;
21
use gossi\codegen\model\parts\DocblockPart;
22
use gossi\codegen\model\parts\LongDescriptionPart;
23
use gossi\codegen\model\parts\ParametersPart;
24
use gossi\codegen\model\parts\QualifiedNamePart;
25
use gossi\codegen\model\parts\ReferenceReturnPart;
26
use gossi\codegen\model\parts\TypeDocblockGeneratorPart;
27
use gossi\codegen\model\parts\TypePart;
28
use gossi\docblock\Docblock;
29
use gossi\docblock\tags\ReturnTag;
30
31
/**
32
 * Represents a PHP function.
33
 *
34
 * @author Johannes M. Schmitt <[email protected]>
35
 * @author Thomas Gossmann
36
 */
37
class PhpFunction extends AbstractModel implements GenerateableInterface, NamespaceInterface, DocblockInterface, RoutineInterface {
38
39
	use BodyPart;
40
	use DocblockPart;
41
	use LongDescriptionPart;
42
	use ParametersPart;
43
	use QualifiedNamePart;
44
	use ReferenceReturnPart;
45
	use TypeDocblockGeneratorPart;
46
	use TypePart;
47
48
// 	/**
49
// 	 * Creates a PHP function from reflection
50
// 	 *
51
// 	 * @deprecated will be removed in version 0.5
52
// 	 * @param \ReflectionFunction $ref
53
// 	 * @return PhpFunction
54
// 	 */
55
// 	public static function fromReflection(\ReflectionFunction $ref) {
56
// 		$function = self::create($ref->name)
57
// 			->setReferenceReturned($ref->returnsReference())
58
// 			->setBody(ReflectionUtils::getFunctionBody($ref));
59
60
// 		$docblock = new Docblock($ref);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
// 		$function->setDocblock($docblock);
62
// 		$function->setDescription($docblock->getShortDescription());
63
// 		$function->setLongDescription($docblock->getLongDescription());
64
65
// 		foreach ($ref->getParameters() as $refParam) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
// 			assert($refParam instanceof \ReflectionParameter); // hmm - assert here?
67
68
// 			$param = PhpParameter::fromReflection($refParam);
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
69
// 			$function->addParameter($param);
70
// 		}
71
72
// 		return $function;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
73
// 	}
74
75
	/**
76
	 * Creates a new PHP function
77
	 *
78
	 * @param string $name qualified name
79
	 * @return static
80
	 */
81 6
	public static function create($name = null) {
82 6
		return new static($name);
83
	}
84
85
	/**
86
	 * Creates a new PHP function
87
	 *
88
	 * @param string $name qualified name
89
	 */
90 9
	public function __construct($name = null) {
91 9
		$this->setQualifiedName($name);
92 9
		$this->docblock = new Docblock();
93 9
		$this->initParameters();
94 9
	}
95
96
	/**
97
	 * @inheritDoc
98
	 */
99 3
	public function generateDocblock() {
100 3
		$docblock = $this->getDocblock();
101 3
		$docblock->setShortDescription($this->getDescription());
102 3
		$docblock->setLongDescription($this->getLongDescription());
103
104
		// return tag
105 3
		$this->generateTypeTag(new ReturnTag());
106
107
		// param tags
108 3
		$this->generateParamDocblock();
109 3
	}
110
}
111