Passed
Push — master ( 83cee0...2131d7 )
by Andreas
19:23
created

midcom_db_parameter::get_parent_guid_uncached()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package midcom.db
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
/**
10
 * MidCOM level replacement for the Midgard Parameter record with framework support.
11
 *
12
 * The uplink is the parentguid parameter.
13
 *
14
 * @property string $domain Namespace of the parameter
15
 * @property string $name Key of the parameter
16
 * @property string $value Value of the parameter
17
 * @property string $parentguid GUID of the object the parameter extends
18
 * @package midcom.db
19
 */
20
class midcom_db_parameter extends midcom_core_dbaobject
21
{
22
    public $__midcom_class_name__ = __CLASS__;
23
    public $__mgdschema_class_name__ = 'midgard_parameter';
24
25
    public $_use_rcs = false;
26
27
    /**
28
     * Read a parameter without loading the corresponding object.
29
     * This is primarily for improving performance, so the function does not check
30
     * for privileges.
31
     *
32
     * @param string $objectguid The object's GUID
33
     * @param string $domain The parameter's domain
34
     * @param string $name The parameter to look for
35
     */
36 7
    public static function get_by_objectguid(string $objectguid, string $domain, string $name)
37
    {
38 7
        static $parameter_cache = [];
39 7
        $cache_key = $objectguid . '::' . $domain . '::' . $name;
40
41 7
        if (!array_key_exists($cache_key, $parameter_cache)) {
42
43 2
            $mc = midgard_parameter::new_collector('parentguid', $objectguid);
44 2
            $mc->set_key_property('value');
45 2
            $mc->add_constraint('name', '=', $name);
46 2
            $mc->add_constraint('domain', '=', $domain);
47 2
            $mc->set_limit(1);
48 2
            $mc->execute();
49
50 2
            $parameter_cache[$cache_key] = key($mc->list_keys());
51
        }
52 7
        return $parameter_cache[$cache_key];
53
    }
54
55
    public function get_label() : string
56
    {
57
        return "{$this->domain} {$this->name}";
58
    }
59
}
60