Completed
Push — master ( 494091...32c874 )
by David
27s
created

PluginArray   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 12 4
1
<?php
2
/**
3
 * Copyright (c) 2013-2017
4
 *
5
 * @category  Library
6
 * @package   Dwoo\Plugins\Helpers
7
 * @author    Jordi Boggiano <[email protected]>
8
 * @author    David Sanchez <[email protected]>
9
 * @copyright 2008-2013 Jordi Boggiano
10
 * @copyright 2013-2017 David Sanchez
11
 * @license   http://dwoo.org/LICENSE Modified BSD License
12
 * @version   1.3.2
13
 * @date      2017-01-06
14
 * @link      http://dwoo.org/
15
 */
16
17
namespace Dwoo\Plugins\Helpers;
18
19
use Dwoo\Compiler;
20
use Dwoo\ICompilable;
21
use Dwoo\Plugin;
22
23
/**
24
 * Builds an array with all the provided variables, use named parameters to make an associative array
25
 * <pre>
26
 *  * rest : any number of variables, strings or anything that you want to store in the array
27
 * </pre>
28
 * Example :
29
 * <code>
30
 * {array(a, b, c)} results in array(0=>'a', 1=>'b', 2=>'c')
31
 * {array(a=foo, b=5, c=array(4,5))} results in array('a'=>'foo', 'b'=>5, 'c'=>array(0=>4, 1=>5))
32
 * </code>
33
 * This software is provided 'as-is', without any express or implied warranty.
34
 * In no event will the authors be held liable for any damages arising from the use of this software.
35
 */
36
class PluginArray extends Plugin implements ICompilable
37
{
38
    /**
39
     * @param Compiler $compiler
40
     * @param array    $rest
41
     *
42
     * @return string
43
     */
44
    public static function compile(Compiler $compiler, array $rest = array())
0 ignored issues
show
Unused Code introduced by
The parameter $compiler is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
        $out = array();
47
        foreach ($rest as $key => $value) {
48
            if (!is_numeric($key) && !strstr($key, '$this->scope')) {
49
                $key = "'" . $key . "'";
50
            }
51
            $out[] = $key . '=>' . $value;
52
        }
53
54
        return 'array(' . implode(', ', $out) . ')';
55
    }
56
}