| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 33.33% covered (danger) | 33.33% | 1 / 3 | CRAP | 35.29% covered (danger) | 35.29% | 6 / 17
Meta | 0.00% covered (danger) | 0.00% | 0 / 1 | 33.33% covered (danger) | 33.33% | 1 / 3 | 25.34 | 35.29% covered (danger) | 35.29% | 6 / 17
install | 100.00% covered (success) | 100.00% | 1 / 1 | 2 | 100.00% covered (success) | 100.00% | 6 / 6
__get | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 | 0.00% covered (danger) | 0.00% | 0 / 3
__set | 0.00% covered (danger) | 0.00% | 0 / 1 | 20 | 0.00% covered (danger) | 0.00% | 0 / 8

1 | <?php
2 |
3 | namespace Entity;
4 |
5 | class Meta extends ModelBase
6 | {
7 | private $entity;
8 |
9 | protected function install()
10 | {
11 | $dbPrefix = $this->getDbPrefix();
12 | $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}meta` (
13 | `entity_id` INTEGER(11) UNSIGNED NOT NULL,
14 | `entityType` VARCHAR(32) NOT NULL,
15 | `lang` VARCHAR(8) NULL,
16 | `key` VARCHAR(64) NOT NULL,
17 | `value` TEXT NULL,
18 | UNIQUE(`entity_id`, `entityType`, `lang`)
19 | )");
20 | if ($result === false)
21 | throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
22 | return true;
23 | }
24 |
25 | public function __get($key)
26 | {
27 | if ($key == "entity")
28 | return $this->entity;
29 | return parent::__get($key);
30 | }
31 |
32 | public function __set($key, $value)
33 | {
34 | if ($key == "entity")
35 | {
36 | parent::__set("entityId", $value->id);
37 | parent::__set("entityType", get_class($value));
38 | return $value;
39 | }
40 | else if ($key == "entityId" || $key == "entityType")
41 | throw new \Exception("Cannot access private field {$key}");
42 | return parent::__set($key, $value);
43 | }
44 | }
45 |