Completed
Push — master ( b59b39...7e1c48 )
by Дмитрий
03:46
created

FunctionDefinition::getParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Definition;
7
8
use PHPSA\CompiledExpression;
9
use PHPSA\Context;
10
use PhpParser\Node;
11
12
/**
13
 * Class FunctionDefinition
14
 * @package PHPSA\Definition
15
 */
16
class FunctionDefinition extends ParentDefinition
17
{
18
    /**
19
     * @todo Use Finder
20
     *
21
     * @var string
22
     */
23
    protected $filepath;
24
25
    /**
26
     * @var Node\Stmt\Function_
27
     */
28
    protected $statement;
29
30
    /**
31
     * @var int
32
     */
33
    protected $returnTypes = CompiledExpression::MIXED;
34
35
    /**
36
     * @var array
37
     */
38
    protected $possibleReturnTypes = array();
39
40
    /**
41
     * @param $name
42
     */
43 1
    public function __construct($name, Node\Stmt\Function_ $statement)
44
    {
45 1
        $this->name = $name;
46 1
        $this->statement = $statement;
47 1
    }
48
49
    /**
50
     * Compile function to check it
51
     *
52
     * @param Context $context
53
     * @return bool
54
     */
55 1
    public function compile(Context $context)
56
    {
57 1
        if ($this->compiled) {
58
            return true;
59
        }
60
61 1
        $context->setFilepath($this->filepath);
62 1
        $this->compiled = true;
63
64 1
        $context->scopePointer = $this->getPointer();
65 1
        $context->setScope(null);
66
67 1
        if (count($this->statement->stmts) == 0) {
68
            return $context->notice(
69
                'not-implemented-function',
70
                sprintf('Function %s() is not implemented', $this->name),
71
                $this->statement
72
            );
73
        }
74
75 1
        if (count($this->statement->params) > 0) {
76
            /** @var  Node\Param $parameter */
77 1
            foreach ($this->statement->params as $parameter) {
78 1
                $context->addSymbol($parameter->name);
79 1
            }
80 1
        }
81
82 1
        foreach ($this->statement->stmts as $st) {
83 1
            \PHPSA\nodeVisitorFactory($st, $context);
84 1
        }
85
86 1
        return true;
87
    }
88
89
    /**
90
     * @return string
91
     */
92 1
    public function getFilepath()
93
    {
94 1
        return $this->filepath;
95
    }
96
97
    /**
98
     * @param string $filepath
99
     */
100 1
    public function setFilepath($filepath)
101
    {
102 1
        $this->filepath = $filepath;
103 1
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getNamespace()
109
    {
110
        return $this->namespace;
111
    }
112
113
    /**
114
    * @return array
115
    */
116 1
    public function getParams()
117
    {
118 1
        return $this->statement->params;
119
    }
120
}
121