Repository::create()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 1
nop 3
1
<?php
2
3
namespace App\Libraries\Metaable;
4
5
use App\Repositories\Repository as BaseRepository;
6
7
class Repository extends BaseRepository
8
{
9
    /**
10
     * @return Meta
11
     */
12
    public function getModel()
13
    {
14
        return new Meta();
15
    }
16
17
    /**
18
     * Create meta.
19
     * 
20
     * @param $metaable
21
     * @param $key
22
     * @param $value
23
     * @param $group
24
     * @return Meta
25
     */
26
    public function create($metaable, $meta, $group)
27
    {
28
        return $this->getModel()
29
            ->create([
30
                'metaable_id'   => $metaable->id,
31
                'metaable_type' => get_class($metaable),
32
                'key'           => $meta['key'],
33
                'value'         => $meta['value'],
34
                'group'         => (! is_null($group)) ? $group : 'other',
35
                'key_unique'    => $meta['key_unique']
36
            ]);
37
    }
38
39
    /**
40
     * Deletes group
41
     *
42
     * @param $group
43
     * @return mixed
44
     */
45
    public function removeGroup($group)
46
    {
47
        return self::getModel()
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Libraries\Metaable\Meta>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
48
            ->where('group', $group)
49
            ->delete();
50
    }
51
52
    /**
53
     * Remove by id.
54
     *
55
     * @param $id
56
     * @return mixed
57
     */
58
    public function removeById($id)
59
    {
60
        return self::getModel()
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<App\Libraries\Metaable\Meta>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
61
            ->find($id)
62
            ->delete();
63
    }
64
    public function removeByKey($key)
65
    {
66
        return self::getModel()
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Libraries\Metaable\Meta>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
67
            ->where('key_unique',$key)
68
            ->first()
69
            ->delete();
70
    }
71
    public function removeGroupById($group, $id)
72
    {
73
        return self::getModel()
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Libraries\Metaable\Meta>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
74
            ->where('group', $group)
75
            ->where('metaable_id', $id)
76
            ->delete();
77
    }
78
}