ArrayToMetadataStringTrait   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 1
c 3
b 1
f 0
lcom 0
cbo 0
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A metadataToString() 0 4 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