Failed Conditions
Pull Request — 4.0 (#4528)
by Kentaro
07:39
created

EntityUtil::isEmpty()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 15
ccs 4
cts 6
cp 0.6667
crap 3.3332
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.ec-cube.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Util;
15
16
use Doctrine\ORM\EntityNotFoundException;
17
use Doctrine\ORM\Proxy\Proxy;
18
19
class EntityUtil
20
{
21
    /**
22
     * エンティティのプロパティを配列で返す.
23
     *
24
     * このメソッドはエンティティの内容をログ出力する際などに使用する.
25
     * AbstractEntity::toArray() と異なり再帰処理しない.
26
     * プロパティの値がオブジェクトの場合は、クラス名を出力する.
27
     *
28
     * @param object $entity 対象のエンティティ
29
     *
30
     * @return array エンティティのプロパティの配列
31
     */
32
    public static function dumpToArray($entity)
33
    {
34
        $objReflect = new \ReflectionClass($entity);
35
        $arrProperties = $objReflect->getProperties();
36
        $arrResults = [];
37 5
        foreach ($arrProperties as $objProperty) {
38
            $objProperty->setAccessible(true);
39 5
            $name = $objProperty->getName();
40
            $value = $objProperty->getValue($entity);
41 1
            $arrResults[$name] = is_object($value) ? get_class($value) : $value;
42
        }
43
44
        return $arrResults;
45
    }
46
}
47