BurningFlipside /
CommonCode
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace Data; |
||
| 3 | |||
| 4 | class ObjectDataTable extends \Data\DataTable |
||
| 5 | { |
||
| 6 | protected $dataTable; |
||
| 7 | protected $className = 'SerializableObject'; |
||
| 8 | |||
| 9 | public static function getInstance() |
||
| 10 | { |
||
| 11 | static $instance = null; |
||
| 12 | if(null === $instance) |
||
| 13 | { |
||
| 14 | $instance = new static(); |
||
|
0 ignored issues
–
show
|
|||
| 15 | } |
||
| 16 | return $instance; |
||
| 17 | } |
||
| 18 | |||
| 19 | protected function __construct($dataTable) |
||
| 20 | { |
||
| 21 | $this->dataTable = $dataTable; |
||
| 22 | } |
||
| 23 | |||
| 24 | public function create($data) |
||
| 25 | { |
||
| 26 | if(is_array($data)) |
||
| 27 | { |
||
| 28 | $data = new $this->className($data); |
||
| 29 | } |
||
| 30 | if(method_exists($data, 'preCreate')) |
||
| 31 | { |
||
| 32 | $data = $data->preCreate(); |
||
| 33 | } |
||
| 34 | return $this->dataTable->create($data); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function read($filter=false, $select=false, $count=false, $skip=false, $sort=false, $params=false) |
||
| 38 | { |
||
| 39 | $res = $this->dataTable->read($filter, $select, $count, $skip, $sort, $params); |
||
| 40 | if($res === false) |
||
| 41 | { |
||
| 42 | return false; |
||
| 43 | } |
||
| 44 | if(!is_array($res)) |
||
| 45 | { |
||
| 46 | $res = array($res); |
||
| 47 | } |
||
| 48 | $objCount = count($res); |
||
| 49 | for($i = 0; $i < $objCount; $i++) |
||
| 50 | { |
||
| 51 | $res[$i] = new $this->className($res[$i]); |
||
| 52 | } |
||
| 53 | return $res; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function update($filter, $data) |
||
| 57 | { |
||
| 58 | if(method_exists($data, 'preUpdate')) |
||
| 59 | { |
||
| 60 | $data = $data->preUpdate(); |
||
| 61 | } |
||
| 62 | return $this->dataTable->update($filter, $data); |
||
| 63 | } |
||
| 64 | |||
| 65 | public function delete($filter) |
||
| 66 | { |
||
| 67 | if(method_exists($data, 'preDelete')) |
||
|
0 ignored issues
–
show
The variable
$data seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?
This error can happen if you refactor code and forget to move the variable initialization. Let’s take a look at a simple example: function someFunction() {
$x = 5;
echo $x;
}
The above code is perfectly fine. Now imagine that we re-order the statements: function someFunction() {
echo $x;
$x = 5;
}
In that case, Loading history...
|
|||
| 68 | { |
||
| 69 | $data = $data->preDelete(); |
||
|
0 ignored issues
–
show
The variable
$data seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?
This error can happen if you refactor code and forget to move the variable initialization. Let’s take a look at a simple example: function someFunction() {
$x = 5;
echo $x;
}
The above code is perfectly fine. Now imagine that we re-order the statements: function someFunction() {
echo $x;
$x = 5;
}
In that case, Loading history...
$data is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 70 | } |
||
| 71 | return $dataTable->delete($filter); |
||
|
0 ignored issues
–
show
|
|||
| 72 | } |
||
| 73 | |||
| 74 | public function count($filter=false) |
||
| 75 | { |
||
| 76 | return parent::count($filter); |
||
| 77 | } |
||
| 78 | } |
||
| 79 |
This check looks for function calls that miss required arguments.