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

classmetadata::__sleep()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
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