Completed
Push — develop ( 1b34c6...481302 )
by Paul
02:47
created

FunctionRenderer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B invoke() 0 26 2
1
<?php
2
3
namespace PhpUnitGen\Renderer;
4
5
use PhpUnitGen\Model\ModelInterface\FunctionModelInterface;
6
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
7
use PhpUnitGen\Model\PropertyInterface\NameInterface;
8
use PhpUnitGen\Parser\NodeParserUtil\RootRetrieverTrait;
9
10
/**
11
 * Class FunctionRenderer.
12
 *
13
 * @author     Paul Thébaud <[email protected]>.
14
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
15
 * @license    https://opensource.org/licenses/MIT The MIT license.
16
 * @link       https://github.com/paul-thebaud/phpunit-generator
17
 * @since      Class available since Release 2.0.0.
18
 */
19
class FunctionRenderer extends AbstractPhpRenderer
20
{
21
    use RootRetrieverTrait;
22
23
    protected $indent = 1;
24
25
    public function invoke(FunctionModelInterface $function): string
26
    {
27
        $this->begin();
28
29
        $parent  = $function->getParentNode();
30
        /** @var PhpFileModelInterface $phpFile */
31
        $phpFile = $this->getRoot($parent);
32
33
        if ($phpFile === $parent) {
34
            $this->doc([sprintf('Covers global method "%s"', $function->getName())]);
35
        } else {
36
            /** @var NameInterface $parent */
37
            $namespace = $phpFile->getFullnameFor($parent->getName());
38
            $this->doc([
39
                sprintf(
40
                    '@covers \\%s::%s',
41
                    $namespace,
42
                    $function->getName()
43
                )
44
            ]);
45
        }
46
        $this->add(
47
            sprintf('public function test%s()', ucfirst($function->getName()))
48
        )->add('{')->add('// Some content')->add('}')->add();
49
50
        return $this->get();
51
    }
52
}
53