Conditions | 16 |
Paths | 3584 |
Total Lines | 103 |
Code Lines | 69 |
Lines | 11 |
Ratio | 10.68 % |
Tests | 48 |
CRAP Score | 43.005 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
13 | 94 | protected function priv_sql_compile($tree) { |
|
14 | 94 | $this->custom_ref = 0; |
|
15 | 94 | $this->custom_id = 0; |
|
16 | 94 | $this->used_tables=""; |
|
17 | 94 | $this->compile_tree($tree); |
|
18 | 94 | $nodes=$this->tbl_prefix."nodes"; |
|
19 | 94 | $objects=$this->tbl_prefix."objects"; |
|
20 | 94 | $properties=$this->tbl_prefix."prop_"; |
|
21 | 94 | $this->used_tables[$nodes]=$nodes; |
|
22 | 94 | $this->used_tables[$objects]=$objects; |
|
23 | 94 | View Code Duplication | if ($this->join_target_properties) { |
24 | $this->used_tables[$properties."references as target_reference"] = $properties."references as target_reference"; |
||
25 | $this->used_tables["$nodes as target"] = "$nodes as target"; |
||
26 | } |
||
27 | 94 | @reset($this->used_tables); |
|
28 | 94 | while (list($key, $val)=each($this->used_tables)) { |
|
29 | 94 | if ($tables) { |
|
30 | 94 | $tables.=", $key"; |
|
31 | 47 | } else { |
|
32 | 94 | $tables="$key"; |
|
33 | } |
||
34 | 94 | View Code Duplication | if ($this->select_tables[$key]) { |
35 | 92 | if ($this->join_target_properties[$key]) { |
|
36 | $prop_dep.=" and $val.object=target.object "; |
||
37 | } else { |
||
38 | 92 | $prop_dep.=" and $val.object=$objects.id "; |
|
39 | } |
||
40 | 46 | } |
|
41 | 47 | } |
|
42 | |||
43 | 94 | $join = ""; |
|
44 | 94 | if (is_array($this->nls_join)) { |
|
45 | reset($this->nls_join); |
||
46 | while (list($key, $value)=each($this->nls_join)) { |
||
47 | $join .= $value; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | |||
52 | |||
53 | 94 | $query = " where $nodes.object=$objects.id $prop_dep"; |
|
54 | 94 | $query .= " and $nodes.path like '".str_replace('_','\\_',AddSlashes($this->path))."%' "; |
|
55 | |||
56 | |||
57 | 94 | $query_string_layers = ""; |
|
58 | 94 | $layering = false; |
|
59 | 94 | foreach ($this->layers as $lPath => $lId) { |
|
60 | if ($lId) { |
||
61 | $layering = true; |
||
62 | if ($query_string_layers) { |
||
63 | $query_string_layers .= " OR "; |
||
64 | } |
||
65 | $query_string_layers .= " ( $nodes.path like '".AddSlashes($lPath)."%' and $nodes.layer = ".((int)$lId)." ) "; |
||
66 | } |
||
67 | 47 | } |
|
68 | 94 | if ($layering) { |
|
69 | $query .= " and ( |
||
70 | ( $query_string_layers ) |
||
71 | OR |
||
72 | $nodes.layer = 0 |
||
73 | and $nodes.id NOT IN ( |
||
74 | select $nodes.id from $nodes where ( $query_string_layers ) |
||
75 | ) |
||
76 | and $nodes.path NOT IN ( |
||
77 | select $nodes.path from $nodes where ( $query_string_layers ) |
||
78 | ) |
||
79 | ) |
||
80 | "; |
||
81 | } else { |
||
82 | 94 | $query .= " and $nodes.layer = 0 "; |
|
83 | } |
||
84 | |||
85 | 94 | if ($this->where_s) { |
|
86 | 94 | $query.=" and ( $this->where_s ) "; |
|
87 | 47 | } |
|
88 | 94 | if ($this->where_s_ext) { |
|
89 | $query .= " and ($this->where_s_ext) "; |
||
90 | } |
||
91 | /* do target join */ |
||
92 | 94 | if ($this->join_target_properties) { |
|
93 | $query .= " and $objects.id = target_reference.object "; |
||
94 | $query .= " and target.path = target_reference.AR_path "; |
||
95 | } |
||
96 | |||
97 | 94 | if ($this->orderby_s) { |
|
98 | $orderby = " order by $this->orderby_s, $nodes.parent ASC, $nodes.priority DESC, $nodes.path ASC "; |
||
99 | } else { |
||
100 | 94 | $orderby = " order by $nodes.parent ASC, $nodes.priority DESC, $nodes.path ASC "; |
|
101 | } |
||
102 | |||
103 | 94 | $select_query = "select distinct($nodes.path), $nodes.id as nodeId, $nodes.layer as nodeLayer, $nodes.parent, $nodes.priority, "; |
|
104 | 94 | $select_query .= "$objects.object, $objects.id, $objects.type, $objects.vtype, "; |
|
105 | 94 | $select_query .= "UNIX_TIMESTAMP($objects.lastchanged) as lastchanged "; |
|
106 | 94 | $select_query .= "from ($tables) $join $query "; |
|
107 | 94 | $select_query .= $orderby." ".$this->limit_s; |
|
108 | |||
109 | 94 | $count_query = "select count(distinct($objects.id)) as count from $tables ".$query; |
|
110 | |||
111 | return array( |
||
112 | 94 | "select_query" => $select_query, |
|
113 | 47 | "count_query" => $count_query |
|
114 | 47 | ); |
|
115 | } |
||
116 | |||
118 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.