Passed
Push — master ( 4adf6f...6cecae )
by Akpé Aurelle Emmanuel Moïse
39s
created

shortcutQueryBuilder::getParameterDeclaration()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 6
nop 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
namespace EZAMA
3
4
/**
5
*
6
* @Name : Shortcut
7
* @Programmer : Akpé Aurelle Emmanuel Moïse Zinsou
8
* @Date : 2019-04-01
9
* @Released under : https://github.com/manuwhat/Shortcut/blob/master/LICENSE
10
* @Repository : https://github.com/manuwhat/Shortcut
11
*
12
**/
13
{
14
15
    
16
    class shortcutQueryBuilder
17
    {
18
        protected static function getSignature(\ReflectionMethod $method, &$signature, &$parameters, &$paramsNum, &$count)
19
        {
20
            $params=$method->getParameters();
21
            $paramsNum=count($params);
22
            $signature='';
23
            $parameters=array();
24
            $count=0;
25
            foreach ($params as $k=>$param) {
26
                self::getParameterDeclaration($param, $tmp, $count, $method);
27
                $signature.=$tmp;
28
                $parameters[]='$'.$param->getName();
29
                $tmp='';
30
                if ($k<$paramsNum-1) {
31
                    $signature.=',';
32
                }
33
            }
34
        }
35
        
36
        protected static function getParameterDeclaration(\ReflectionParameter $param, &$tmp, &$count, $method)
37
        {
38
            $tmp=$param->isPassedByReference()?'&$'.$param->getName():'$'.$param->getName();
39
            if ($param->isOptional()) {
40
                $count++;
41
                if ($method->isInternal()) {
42
                    $tmp.='="acce91966cd8eee995ee1ac30c98c3d89d8f9235"';
43
                } else {
44
                    self::handleOptionalParameter($param, $tmp);
45
                }
46
            }
47
        }
48
        
49
        protected static function handleOptionalParameter(\reflectionParameter $param, &$tmp)
50
        {
51
            if ($param->isDefaultValueConstant()) {
52
                $tmp.='='.$param->getDefaultValueConstantName();
53
            } elseif ($param->isDefaultValueAvailable()) {
54
                $tmp.='='.var_export($param->getDefaultValue(), true);
55
            } elseif ($param->allowsNull()) {
56
                $tmp.='=null';
57
            }
58
        }
59
        
60
        protected static function BuildTheSwitch(&$hasInternal, $count, $paramsNum, $parameters, $classname)
61
        {
62
            $hasInternal.='switch($count){';
63
            while ($count>0) {
64
                $hasInternal.="case $count:return new $classname(".join(',', array_slice($parameters, 0, $paramsNum-$count))."); break;";
65
                $count--;
66
            }
67
            $hasInternal.='default:return new '.$classname.'('.join(',', $parameters).');break;}';
68
        }
69
        
70
        
71
        protected static function _init($classname)
72
        {
73
            return [
74
                'reflectionClass'=>$tmp=new \ReflectionClass($classname),
75
                'classname'=>$tmp->getName(),
76
                'fullQualifiedClassname'=>str_replace('\\', '_', $classname),
77
            ];
78
        }
79
        
80
        protected static function forwardInit($name, $Dir, \ReflectionClass $reflectionClass)
81
        {
82
            self::createDir($Dir);
83
            return [
84
                'private_scope'=>false,
85
                'name'=>trim($name),
86
                'reflectionMethod'=>$reflectionClass->getConstructor(),
87
                'notInstantiable'=>false,
88
            ];
89
        }
90
        
91
        private static function createDir($Dir)
92
        {
93
            if (!file_exists($Dir)) {
94
                mkdir($Dir);
95
            }
96
        }
97
        
98
        
99
        private function __construct()
100
        {
101
        }
102
    }
103
    
104
}
105