Completed
Push — master ( 5f25ab...068d7d )
by Mathieu
06:40 queued 04:51
created

Category   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 22
c 4
b 0
f 1
dl 0
loc 35
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
A accessToProtectedVariable() 0 8 3
1
<?php
2
3
class Category extends \Suricate\DBObject
4
{
5
    protected $tableName = 'categories';
6
    protected $tableIndex = 'id';
7
8
    public function __construct()
9
    {
10
        parent::__construct();
11
        $database = new \Suricate\Database();
12
        $database->configure([
13
            'type' => 'sqlite',
14
            'file' => '/tmp/test.db',
15
        ]);
16
        $this->dbLink = $database;
17
18
        $this->dbVariables = [
19
            'id',
20
            'name',
21
            'parent_id',
22
        ];
23
24
        $this->protectedVariables = [
25
            'prot_var',
26
            'unloadable',
27
        ];
28
    }
29
30
    protected function accessToProtectedVariable(string $name): bool
31
    {
32
        switch ($name) {
33
            case 'prot_var':
34
                $this->prot_var = 42;
0 ignored issues
show
Bug Best Practice introduced by
The property prot_var does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
                return true;
36
            case 'unloadable':
37
                return false;
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
38
        }
39
    }
40
}
41