Category::accessToProtectedVariable()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 2
b 0
f 0
nc 3
nop 1
dl 0
loc 8
rs 10
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 = ['id', 'name', 'parent_id'];
19
20
        $this->protectedVariables = ['prot_var', 'unloadable'];
21
    }
22
23
    protected function accessToProtectedVariable(string $name): bool
24
    {
25
        switch ($name) {
26
            case 'prot_var':
27
                $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...
28
                return true;
29
            case 'unloadable':
30
                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...
31
        }
32
    }
33
}
34