Completed
Pull Request — master (#519)
by Mantas
04:19
created

InnerObject::dump()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 22
Code Lines 13

Duplication

Lines 22
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 22
loc 22
rs 9.2
cc 2
eloc 13
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\Annotation;
13
14
use ONGR\ElasticsearchBundle\Mapping\Caser;
15
use Doctrine\Common\Annotations\Annotation\Required;
16
17
/**
18
 * Annotation for property which points to inner object.
19
 *
20
 * @Annotation
21
 * @Target("PROPERTY")
22
 */
23 View Code Duplication
final class InnerObject
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    /**
26
     * Inner object class name.
27
     *
28
     * @var string Object name to map
29
     *
30
     * @Required
31
     */
32
    public $objectName;
33
34
    /**
35
     * Name of the type field. Defaults to normalized property name.
36
     *
37
     * @var string
38
     */
39
    public $name;
40
41
    /**
42
     * Defines if related object will have one or multiple values.
43
     *
44
     * If this value is set to true, in the result ObjectIterator will be provided,
45
     * otherwise you will get single object.
46
     *
47
     * @var bool Object or ObjectIterator
48
     */
49
    public $multiple;
50
51
    /**
52
     * In this field you can define options.
53
     *
54
     * @var array
55
     */
56
    public $options;
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function dump(array $exclude = [])
62
    {
63
        $array = array_diff_key(
64
            array_filter(
65
                get_object_vars($this),
66
                function ($value) {
67
                    return $value || is_bool($value);
68
                }
69
            ),
70
            array_flip(array_merge(['name', 'objectName', 'multiple'], $exclude))
71
        );
72
73
        return array_combine(
74
            array_map(
75
                function ($key) {
76
                    return Caser::snake($key);
77
                },
78
                array_keys($array)
79
            ),
80
            array_values($array)
81
        );
82
    }
83
}
84