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
|
|
|
namespace gossi\codegen\model; |
18
|
|
|
|
19
|
|
|
use gossi\codegen\model\parts\AbstractPart; |
20
|
|
|
use gossi\codegen\model\parts\BodyPart; |
21
|
|
|
use gossi\codegen\model\parts\FinalPart; |
22
|
|
|
use gossi\codegen\model\parts\ParametersPart; |
23
|
|
|
use gossi\codegen\model\parts\ReferenceReturnPart; |
24
|
|
|
use gossi\codegen\model\parts\TypeDocblockGeneratorPart; |
25
|
|
|
use gossi\docblock\Docblock; |
26
|
|
|
use gossi\docblock\tags\ReturnTag; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Represents a PHP method. |
30
|
|
|
* |
31
|
|
|
* @author Johannes M. Schmitt <[email protected]> |
32
|
|
|
* @author Thomas Gossmann |
33
|
|
|
*/ |
34
|
|
|
class PhpMethod extends AbstractPhpMember implements RoutineInterface { |
35
|
|
|
|
36
|
|
|
use AbstractPart; |
37
|
|
|
use BodyPart; |
38
|
|
|
use FinalPart; |
39
|
|
|
use ParametersPart; |
40
|
|
|
use ReferenceReturnPart; |
41
|
|
|
use TypeDocblockGeneratorPart; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Creates a new PHP method. |
45
|
|
|
* |
46
|
|
|
* @param string $name the method name |
47
|
|
|
*/ |
48
|
22 |
|
public static function create($name) { |
49
|
22 |
|
return new static($name); |
50
|
|
|
} |
51
|
|
|
|
52
|
37 |
|
public function __construct($name) { |
53
|
37 |
|
parent::__construct($name); |
54
|
37 |
|
$this->initParameters(); |
|
|
|
|
55
|
37 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Generates docblock based on provided information |
59
|
|
|
*/ |
60
|
11 |
|
public function generateDocblock() { |
61
|
11 |
|
$docblock = $this->getDocblock(); |
62
|
11 |
|
$docblock->setShortDescription($this->getDescription()); |
63
|
11 |
|
$docblock->setLongDescription($this->getLongDescription()); |
64
|
|
|
|
65
|
|
|
// return tag |
66
|
11 |
|
$this->generateTypeTag(new ReturnTag()); |
67
|
|
|
|
68
|
|
|
// param tags |
69
|
11 |
|
$this->generateParamDocblock(); |
70
|
11 |
|
} |
71
|
|
|
} |
72
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: