ArrayToMetadataStringTrait::metadataToString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * PHP Client for DDN Web Object Scalar (WOS) API
5
 *
6
 * @license http://opensource.org/licenses/MIT
7
 * @link    https://github.com/caseyamcl/wosclient
8
 * @version 1.0
9
 * @package caseyamcl/wosclient
10
 * @author  Casey McLaughlin <[email protected]>
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 *
15
 * ------------------------------------------------------------------
16
 */
17
18
namespace WosClient\Helper;
19
20
/**
21
 * Helper to turn an array of key/value pairs into a string
22
 *
23
 * The resulting string is compatible with the x-ddn-metadata header
24
 *
25
 * @author Casey McLaughlin <[email protected]>
26
 */
27
trait ArrayToMetadataStringTrait
28
{
29
    /**
30
     * Prepare metadata for DDN header
31
     *
32
     * Converts array into JSON, and removes surrounding brackets
33
     * Returns an empty string for an empty array
34
     *
35
     * @param  array $meta
36
     * @return string
37
     */
38
    protected function metadataToString(array $meta = [])
39
    {
40
        return preg_replace('/^\{(.+?)?\}$/', '$1', json_encode($meta, JSON_FORCE_OBJECT));
41
    }
42
}
43