midgard_reflector_object   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 44
ccs 20
cts 20
cp 1
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A get_property_up() 0 3 1
A get_property_primary() 0 3 1
A get_property_parent() 0 3 1
A get_property_unique() 0 4 1
A list_children() 0 8 2
A get_metadata_class() 0 6 2
A has_metadata_class() 0 3 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
8
use midgard\portable\storage\connection;
9
10
class midgard_reflector_object
11
{
12 1
    public static function get_property_primary(string $classname) : string
0 ignored issues
show
Unused Code introduced by
The parameter $classname is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

12
    public static function get_property_primary(/** @scrutinizer ignore-unused */ string $classname) : string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
13
    {
14 1
        return 'id';
15
    }
16
17 1
    public static function get_property_up(string $classname) : ?string
18
    {
19 1
        return midgard_object_class::get_property_up($classname);
20
    }
21
22 1
    public static function get_property_parent(string $classname) : ?string
23
    {
24 1
        return midgard_object_class::get_property_parent($classname);
25
    }
26
27 1
    public static function get_property_unique(string $classname) : ?string
28
    {
29 1
        $cm = connection::get_em()->getClassMetadata($classname);
30 1
        return $cm->midgard['unique_fields'][0] ?? null;
0 ignored issues
show
Bug introduced by
Accessing midgard on the interface Doctrine\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
31
    }
32
33 1
    public static function list_children(string $classname) : array
34
    {
35 1
        $cm = connection::get_em()->getClassMetadata($classname);
36 1
        if (empty($cm->midgard['childtypes'])) {
0 ignored issues
show
Bug introduced by
Accessing midgard on the interface Doctrine\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
37 1
            return [];
38
        }
39
        // @todo We filter out useful information (parent field name) in the name of mgd2 compat.
40 1
        return array_fill_keys(array_keys($cm->midgard['childtypes']), '');
41
    }
42
43 2
    public static function has_metadata_class($classname) : bool
44
    {
45 2
        return midgard_object_class::has_metadata($classname);
46
    }
47
48 1
    public static function get_metadata_class($classname) : ?string
49
    {
50 1
        if (!self::has_metadata_class($classname)) {
51 1
            return null;
52
        }
53 1
        return 'midgard_metadata';
54
    }
55
}