Completed
Push — master ( 55b21a...aec22b )
by Thomas
06:20
created

PhpMethod::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
cc 1
eloc 3
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
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();
1 ignored issue
show
Unused Code introduced by
The call to the method gossi\codegen\model\PhpMethod::initParameters() seems un-needed as the method has no side-effects.

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:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

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:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

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:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
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