test()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
require_once('./src/namedArgs.php');
3
require_once('./src/namedArgsHelper.php');
4
5
6
function codeWithoutRef(NamedArgs $mandatory)
7
{
8
    $required = ['first', 'fourth']; //specify required parameters here
9
    $default = ['first'=>0, 'second'=>1, 'third'=>2, 'fourth'=>9, 'fifth'=>7]; //define all parameters required and optional with their default values here
10
    extract($mandatory->getParams($required, $default));
11
    unset($mandatory);
12
    return $first + $second + $third + $fourth + $fifth;
13
}
14
15
16
function codeWithRef(NamedArgs $mandatory)
17
{
18
    $required = ['first'];
19
    $default = ['first'=>0, 'second'=>1, 'third'=>2];
20
    extract($mandatory->getParams($required, $default), EXTR_OVERWRITE | EXTR_REFS);
21
    unset($mandatory);
22
    $first = $first + $second + $third;
0 ignored issues
show
Unused Code introduced by
The assignment to $first is dead and can be removed.
Loading history...
23
}
24
25
26
function test(&$tada, &$tada2, &$test = 6)
27
{
28
    $tada = 1;
29
    $tada2 = 2;
30
    return  $tada + $tada2 + $test;
31
}
32
33
34
echo "<pre>";
35
var_dump(codeWithoutRef(Args(['fourth'=>9, 'first'=>3, 'third'=>79])));
36
var_dump(codeWithoutRef(Args([1, 2, 3, 0])));
37
38
39
$first = 3;
40
codeWithRef(Args(['third'=>79, 'first'=>&$first]));
41
var_dump($first);
42
$first2 = 3;
43
codeWithRef(Args([&$first2, 79]));
44
var_dump($first2);
45
46
$tada = $tada2 = null;
47
var_dump(NamedArgs::test(args(['tada'=>&$tada, 'tada2'=>&$tada2])), $tada, $tada2);
48
49
$tada = $tada2 = null;
50
var_dump(NamedArgs::test(args([&$tada, &$tada2])), $tada, $tada2);
51
52
53
NamedArgs::preg_match_all(args(['subpatterns'=>&$matches, 'pattern'=>'#a|o|i|u|e#', 'subject'=>'gris|gros|gras|grue']));
54
55
var_dump($matches);
56
var_dump($x = NamedArgs::strtoupper(args(['str'=>'gris|gros|gras|grue'])), NamedArgs::strtolower(args(['str'=>$x]))); //just for  funny example.
57
NamedArgs::preg_match(['subpatterns'=>&$match, 'pattern'=>'#a|o|i|u|e#', 'subject'=>'gris|gros|gras|grue']);
58
var_dump($match);
59
60
highlight_string('
61
<?php 
62
var_dump(codeWithoutRef(Args([\'third\'=>79])));//generate error here for example
63
?>
64
');
65
var_dump(codeWithoutRef(Args(['third'=>79])));
66
67
echo "</pre>";
68