Completed
Push — master ( 030796...0c67b5 )
by Asmir
30:13
created

MethodTag::generate()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 16
nop 0
1
<?php
2
/**
3
 * Zend Framework (http://framework.zend.com/)
4
 *
5
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
6
 * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7
 * @license   http://framework.zend.com/license/new-bsd New BSD License
8
 */
9
10
namespace GoetasWebservices\SoapServices\SoapClient\StubGeneration\Tag;
11
12
use Zend\Code\Generator\DocBlock\Tag\MethodTag as BaseMethodTag;
13
use Zend\Code\Generator\DocBlock\Tag\ParamTag;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GoetasWebservices\SoapSe...Generation\Tag\ParamTag.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
14
15
class MethodTag extends BaseMethodTag
16
{
17
    protected $params = [];
18
19
    public function setParams($params)
20
    {
21
        $this->params = $params;
22
    }
23
24
    public function generateParams()
25
    {
26
        $params = array_map(function (ParamTag $paramTag) {
27
            if ($paramTag instanceof \GoetasWebservices\SoapServices\SoapClient\StubGeneration\Tag\ParamTag){
28
                return $paramTag->generateForMethod();
29
            }
30
            return
31
                ((!empty($paramTag->getTypes())) ? $paramTag->getTypesAsString() : '')
32
                . ((!empty($paramTag->getVariableName())) ? ' $' . $paramTag->getVariableName() : '');
33
        }, $this->params );
34
35
36
        return implode(', ', $params);
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function generate()
43
    {
44
        $params = $this->generateParams();
45
        $output = '@method'
46
            . (($this->isStatic) ? ' static' : '')
47
            . ((!empty($this->types)) ? ' ' . $this->getTypesAsString() : '')
48
            . ((!empty($this->methodName)) ? ' ' . $this->methodName . "($params)" : '')
49
            . ((!empty($this->description)) ? ' ' . $this->description : '');
50
51
        return $output;
52
    }
53
}
54