Completed
Pull Request — development (#812)
by
unknown
12:05
created

CachesEntity::isNew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Oc\Entity;
4
5
use Oc\Repository\AbstractEntity;
6
use Doctrine\ORM\Mapping as ORM;
7
8
/**
9
 * @ORM\Entity(repositoryClass="Oc\Repository\CachesRepository")
10
 */
11
class CachesEntity extends AbstractEntity
12
{
13
    /** @var int */
14
    protected $cache_id;
15
16
    /** @var datetime */
17
    protected $date_Created;
18
19
    /** @var datetime */
20
    protected $last_Modified;
21
22
    /** @var int */
23
    protected $user_Id;
24
25
    /** @var string */
26
    protected $name;
27
28
    /** @var float */
29
    protected $longitude;
30
31
    /** @var float */
32
    protected $latitude;
33
34
    /** @var int */
35
    protected $status;
36
37
    /** @var string */
38
    protected $country;
39
40
    /** @var float */
41
    protected $difficulty;
42
43
    /** @var float */
44
    protected $terrain;
45
46
    /** @var int */
47
    protected $size;
48
49
    /** @var string */
50
    protected $wp_gc;
51
52
    /** @var string */
53
    protected $wp_oc;
54
55
    public function isNew()
56
    : bool
57
    {
58
        return $this->cache_id === null;
59
    }
60
61
    public function isActiveAndFindable()
62
    : bool
63
    {
64
        if ($this->status == 1) {
65
            return $this->true;
0 ignored issues
show
Bug introduced by
The property true does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
66
        } else {
67
            return $this->false;
0 ignored issues
show
Bug introduced by
The property false does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
68
        }
69
    }
70
71
    public function getCacheId()
72
    : int
73
    {
74
        return $this->cache_id;
75
    }
76
77
    public function setCacheId($arg)
78
    {
79
        $this->cache_id = $arg;
80
    }
81
82
    public function getName()
83
    : string
84
    {
85
        return $this->name;
86
    }
87
88
    public function setName($arg)
89
    {
90
        $this->name = $arg;
91
    }
92
93
    public function getUserId()
94
    : string
95
    {
96
        return $this->user_Id;
97
    }
98
99
    public function setUserId($arg)
100
    {
101
        $this->user_Id = $arg;
102
    }
103
104
    public function getGCid()
105
    : string
106
    {
107
        return $this->wp_gc;
108
    }
109
110
    /**
111
     * Set wpGC
112
     * @param string $arg
113
     */
114
    public function setGCid($arg)
115
    {
116
        $this->wp_gc = $arg;
117
    }
118
119
    public function getOCid()
120
    : string
121
    {
122
        return $this->wp_oc;
123
    }
124
125
    /**
126
     * Set wpOC
127
     * @param string $arg
128
     */
129
    public function setOCid($arg)
130
    {
131
        $this->wp_oc = $arg;
132
    }
133
134
    public function getDifficulty()
135
    : string
136
    {
137
        return $this->difficulty;
138
    }
139
140
    public function getTerrain()
141
    : string
142
    {
143
        return $this->difficulty;
144
    }
145
146
    public function convertEntityToArray() : array
147
    {
148
        $entityArray = [];
149
150
        foreach ($this as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<Oc\Entity\CachesEntity> is not traversable.
Loading history...
151
            $entityArray = array_merge($entityArray, [$key => $value]);
152
        }
153
154
        $entityArrayX[0] = $entityArray;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$entityArrayX was never initialized. Although not strictly required by PHP, it is generally a good practice to add $entityArrayX = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
155
156
        return $entityArrayX;
157
    }
158
}
159