Completed
Push — master ( a4e176...8c9478 )
by Adam
02:50
created

ExtendedArrayTrait::getFromArrayUsingJsonNotation()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 8.6737
c 0
b 0
f 0
cc 6
eloc 13
nc 5
nop 3
crap 6
1
<?php
2
3
namespace BestServedCold\PhalueObjects\ExtendedArray;
4
5
use BestServedCold\PhalueObjects\String\StringTrait;
6
7
/**
8
 * Class ExtendedArrayTrait
9
 *
10
 * @package   BestServedCold\PhalueObjects\ExtendedArray
11
 * @author    Adam Lewis <[email protected]>
12
 * @copyright Copyright (c) 2015 Best Served Cold Media Limited
13
 * @license      http://http://opensource.org/licenses/GPL-3.0 GPL License
14
 * @link      http://bestservedcold.com
15
 * @since      0.0.1-alpha
16
 * @version   0.0.8-alpha
17
 */
18
trait ExtendedArrayTrait
19
{
20
    use StringTrait;
21
22
    /**
23
     * @param  array  $array
24
     * @return string
25
     */
26 1
    public function arrayToPairString(array $array)
27
    {
28
        return implode(',', array_map(function ($key, $value) {
29 1
            return $key.'='.$value;
30 1
        }, array_keys($array), $array));
31
    }
32
33
    /**
34
     * @param  array $array
35
     * @return string
36
     */
37
    public function arrayToAttributeArray(array $array)
38
    {
39
        return implode(' ', array_map(function ($key, $value) {
40
            return is_null($value) ? $key : $key.'="'.$value.'"';
41
        }, array_keys($array), $array));
42
    }
43
}
44