Passed
Push — master ( c9d06c...84202a )
by Andreas
06:32
created

classmetadata   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 43
ccs 0
cts 19
cp 0
rs 10
c 1
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __sleep() 0 6 1
A get_schema_properties() 0 20 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 = array(
14
        'parent' => null,
15
        'parentfield' => null,
16
        'upfield' => null,
17
        'unique_fields' => array(),
18
        'childtypes' => array(),
19
        'field_aliases' => array()
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
    public function get_schema_properties($metadata = false)
34
    {
35
        if ($metadata === true) {
36
            $metadata = 0;
37
        }
38
        $properties = array_merge($this->getFieldNames(), $this->getAssociationNames(), array_keys($this->midgard['field_aliases']));
39
        $properties = array_filter($properties, function($input) use ($metadata) {
40
            if (strpos($input, 'metadata_') === $metadata) {
41
                return $input;
42
            }
43
        });
44
            if ($metadata === false) {
45
                $properties[] = 'metadata';
46
            } else {
47
                $properties = array_map(function($input) {
48
                    return str_replace('metadata_', '', $input);
49
                }, $properties);
50
            }
51
            return $properties;
52
    }
53
}
54