ObjectToArray::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 7
cp 0.8571
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2.0116
1
<?php
2
/**
3
 * This file is part of the Drest package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author Lee Davis
9
 * @copyright Copyright (c) Lee Davis <@leedavis81>
10
 * @link https://github.com/leedavis81/drest/blob/master/LICENSE
11
 * @license http://opensource.org/licenses/MIT The MIT X License (MIT)
12
 */
13
namespace Drest\Helper;
14
15
16
class ObjectToArray
17
{
18
    /**
19
     * Get an objects variables (including private / protected) as an array
20
     * @param $object
21
     * @throws \InvalidArgumentException
22
     * @return array
23
     */
24 3
    public static function execute($object)
25
    {
26 3
        if (!is_object($object)) {
27
            throw new \InvalidArgumentException('To extract variables from an object, you must supply an object.');
28
        }
29
30 3
        $objectArray = (array) $object;
31 3
        $out = json_encode($objectArray);
32 3
        $out = preg_replace('/\\\u0000[*a-zA-Z_\x7f-\xff\\\][a-zA-Z0-9_\x7f-\xff\\\]*\\\u0000/', '', $out);
33
34 3
        return json_decode($out, true);
35
    }
36
}