Completed
Push — 1.0 ( 916c87...0a54d3 )
by Simonas
02:30
created

Property::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\Enum;
16
use Doctrine\Common\Annotations\Annotation\Required;
17
18
/**
19
 * Annotation used to check mapping type during the parsing process.
20
 *
21
 * @Annotation
22
 * @Target("PROPERTY")
23
 */
24 View Code Duplication
final class Property
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...
25
{
26
    /**
27
     * Field type.
28
     *
29
     * @var string
30
     *
31
     * @Required
32
     * @Enum({"string", "boolean", "integer", "float", "long", "short", "byte", "double", "date",
33
     *        "geo_point", "geo_shape", "ip", "binary", "token_count" })
34
     */
35
    public $type;
36
37
    /**
38
     * Name of the type field. Defaults to normalized property name.
39
     *
40
     * @var string
41
     */
42
    public $name;
43
44
    /**
45
     * In this field you can define options (like analyzers and etc) for specific field types.
46
     *
47
     * @var array
48
     */
49
    public $options;
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function dump(array $exclude = [])
55
    {
56
        $array = array_diff_key(
57
            array_filter(
58
                get_object_vars($this),
59
                function ($value) {
60
                    return $value || is_bool($value);
61
                }
62
            ),
63
            array_flip(array_merge(['name'], $exclude))
64
        );
65
66
        return array_combine(
67
            array_map(
68
                function ($key) {
69
                    return Caser::snake($key);
70
                },
71
                array_keys($array)
72
            ),
73
            array_values($array)
74
        );
75
    }
76
}
77