Passed
Push — master ( efafc0...b76ebc )
by Andreas
03:23
created

classmetadata   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 68.75%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 24
c 4
b 0
f 0
dl 0
loc 41
ccs 11
cts 16
cp 0.6875
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __sleep() 0 5 1
A get_schema_properties() 0 19 4
1
<?php
2
/**
3
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
4
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
6
 */
7
namespace midgard\portable\mapping;
8
9
use Doctrine\ORM\Mapping\ClassMetadata as base_metadata;
10
11
class classmetadata extends base_metadata
12
{
13
    public $midgard = [
14
        'parent' => null,
15
        'parentfield' => null,
16
        'upfield' => null,
17
        'unique_fields' => [],
18
        'childtypes' => [],
19
        'field_aliases' => []
20
    ];
21
22
    public function __sleep()
23
    {
24
        $serialized = parent::__sleep();
25
        $serialized[] = 'midgard';
26
        return $serialized;
27
    }
28
29
    /**
30
     * @param boolean $metadata Return metadata properties instead
31
     * @return string[]
32
     */
33 1
    public function get_schema_properties($metadata = false)
34
    {
35 1
        if ($metadata === true) {
36 1
            $metadata = 0;
37
        }
38 1
        $properties = array_merge($this->getFieldNames(), $this->getAssociationNames(), array_keys($this->midgard['field_aliases']));
39
        $properties = array_filter($properties, function($input) use ($metadata) {
40 1
            if (strpos($input, 'metadata_') === $metadata) {
41 1
                return $input;
42
            }
43 1
        });
44 1
        if ($metadata === false) {
45 1
            $properties[] = 'metadata';
46
        } else {
47
            $properties = array_map(function($input) {
48
                return str_replace('metadata_', '', $input);
49 1
            }, $properties);
50
        }
51 1
        return $properties;
52
    }
53
}
54