Completed
Push — master ( 59578f...470184 )
by Andreas
04:46
created

classmetadata   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 41
ccs 14
cts 15
cp 0.9333
rs 10
c 4
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_schema_properties() 0 18 4
A __sleep() 0 5 1
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
        'field_order' => []
21
    ];
22
23 12
    public function __sleep()
24
    {
25 12
        $serialized = parent::__sleep();
26 12
        $serialized[] = 'midgard';
27 12
        return $serialized;
28
    }
29
30
    /**
31
     * @param boolean $metadata Return metadata properties instead
32
     * @return string[]
33
     */
34 1
    public function get_schema_properties(bool $metadata = false) : array
35
    {
36 1
        if ($metadata === true) {
37 1
            $metadata = 0;
38
        }
39
        $properties = array_filter($this->midgard['field_order'], 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