Module   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 59
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getByAlias() 0 4 2
A createByArray() 0 8 1
A deleteByAlias() 0 4 1
1
<?php
2
namespace Redaxscript\Model;
3
4
/**
5
 * parent class to provide the module model
6
 *
7
 * @since 3.3.0
8
 *
9
 * @package Redaxscript
10
 * @category Model
11
 * @author Henry Ruhs
12
 */
13
14
class Module extends ModelAbstract
15
{
16
	/**
17
	 * name of the table
18
	 *
19
	 * @var string
20
	 */
21
22
	protected $_table = 'modules';
23
24
	/**
25
	 * get the module by alias
26
	 *
27
	 * @since 4.5.0
28
	 *
29
	 * @param string $moduleAlias alias of the module
30
	 *
31
	 * @return object|null
32
	 */
33
34
	public function getByAlias(string $moduleAlias = null) : ?object
35
	{
36
		return $this->query()->where('alias', $moduleAlias)->findOne() ? : null;
37
	}
38
39
	/**
40
	 * create the module by array
41
	 *
42
	 * @since 3.3.0
43
	 *
44
	 * @param array $createArray array of the create
45
	 *
46
	 * @return bool
47
	 */
48
49 1
	public function createByArray(array $createArray = []) : bool
50
	{
51
		return $this
52 1
			->query()
53 1
			->create()
54 1
			->set($createArray)
55 1
			->save();
56
	}
57
58
	/**
59
	 * delete the module by alias
60
	 *
61
	 * @since 3.3.0
62
	 *
63
	 * @param string $moduleAlias alias of the module
64
	 *
65
	 * @return bool
66
	 */
67
68 1
	public function deleteByAlias(string $moduleAlias = null) : bool
69
	{
70 1
		return $this->query()->where('alias', $moduleAlias)->deleteMany();
0 ignored issues
show
Documentation Bug introduced by
The method deleteMany does not exist on object<Redaxscript\Db>? 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...
71
	}
72
}
73