Completed
Push — master ( 65d75b...14a491 )
by
unknown
02:57
created

Model   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A where() 0 8 2
A count() 0 3 2
A all() 0 3 2
A primaryKey() 0 4 1
A create() 0 8 2
1
<?php
2
3
/**
4
 * Model class
5
 *
6
 * Base class for an ORM.
7
 *
8
 * @package core
9
 * @author [email protected]
10
 * @copyright Caffeina srl - 2015 - http://caffeina.it
11
 */
12
13
abstract class Model {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
14
    use Module, Persistence, Events;
15
16
    public static function where($where_sql = false, $params = [], $flush = false){
0 ignored issues
show
Unused Code introduced by
The parameter $flush is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
      $key   = static::persistenceOptions('key');
18
19
      return SQL::reduce("SELECT {$key} FROM " . static::persistenceOptions('table') . ($where_sql ? " where {$where_sql}" : ''), $params, function($results, $row) use ($key) {
20
           $results[] = static::load($row->{$key});
21
           return $results;
22
      }, []);
23
    }
24
25
    public static function count($where_sql = false, $params = []) {
26
      return SQL::value('SELECT COUNT(1) FROM ' . static::persistenceOptions('table') . ($where_sql ? " where {$where_sql}" : ''), $params);
27
    }
28
29
    public static function all($page=1, $limit=-1){
30
      return static::where($limit < 1 ? "" : "1 limit {$limit} offset " . (max(1,$page)-1)*$limit);
0 ignored issues
show
Documentation introduced by
$limit < 1 ? '' : "1 lim...1, $page) - 1) * $limit is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
    }
32
33
    public function primaryKey(){
34
      $key  = static::persistenceOptions('key');
35
      return $this->{$key};
36
    }
37
38
    public static function create($data){
39
      $tmp = new static;
40
      foreach ((array)$data as $key => $value) {
41
         $tmp->$key = $value;
42
      }
43
      $tmp->save();
44
      return $tmp;
45
    }
46
47
}
48