Passed
Push — master ( d50d64...3e68ba )
by Maike
02:16
created

Log::getPrev()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MocOrm\Support;
4
5
/**
6
 * Implementation.
7
 */
8
class Log extends Model
9
{
10
    public function onLoad() {
11
        $this->setTableName('tb_log')
12
            ->setPrimaryKey()
13
            ->setIp()
14
            ->setSession();
15
    }
16
17
    public function setPrev($prev) {
18
        $this->prev = json_encode($prev);
0 ignored issues
show
Bug Best Practice introduced by
The property prev does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
20
        return $this;
21
    }
22
23
    public function getPrev() {
24
        return json_decode($this->prev);
25
    }
26
27
    public function setNext($next) {
28
        $this->next = json_encode($next);
0 ignored issues
show
Bug Best Practice introduced by
The property next does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
30
        return $this;
31
    }
32
33
    public function getNext() {
34
        return json_decode($this->next);
35
    }
36
37
    public function setFunction($name) {
38
        $this->function = $name;
0 ignored issues
show
Bug Best Practice introduced by
The property function does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
39
40
        return $this;
41
    }
42
43
    public function setSession() {
0 ignored issues
show
Coding Style introduced by
setSession uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
44
        $this->session = json_encode(@$_SESSION);
0 ignored issues
show
Bug Best Practice introduced by
The property session does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
45
46
        return $this;
47
    }
48
49
    public function setName($name) {
50
        $this->name = $name;
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
51
52
        return $this;
53
    }
54
55
    public function setIp() {
0 ignored issues
show
Coding Style introduced by
setIp uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
56
        $this->ip = @$_SERVER['REMOTE_ADDR'];
0 ignored issues
show
Bug Best Practice introduced by
The property ip does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
57
58
        return $this;
59
    }
60
61
62
}
63