Conditions | 10 |
Paths | 28 |
Total Lines | 70 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 declare(strict_types=1); |
||
58 | public function insert(\XoopsObject $object, $force = false) |
||
59 | { |
||
60 | if (!$object instanceof MyiframeBase) { |
||
61 | return false; |
||
62 | } |
||
63 | if (!$object->isDirty()) { |
||
64 | return true; |
||
65 | } |
||
66 | if (!$object->cleanVars()) { |
||
67 | foreach ($object->getErrors() as $oneerror) { |
||
68 | \trigger_error($oneerror); |
||
69 | } |
||
70 | |||
71 | return false; |
||
72 | } |
||
73 | foreach ($object->cleanVars as $k => $v) { |
||
74 | ${$k} = $v; |
||
75 | } |
||
76 | |||
77 | if ($object->isNew()) { |
||
78 | $format = 'INSERT INTO %s (frame_created, frame_uid, frame_description, frame_width, frame_height, frame_align, frame_frameborder, frame_marginwidth, frame_marginheight, frame_scrolling, frame_hits, frame_url) VALUES (%u, %u, %s, %s, %s, %d, %d, %d, %d, %d, %u, %s)'; |
||
79 | $sql = \sprintf( |
||
80 | $format, |
||
81 | $this->db->prefix('myiframe'), |
||
82 | $frame_created, |
||
|
|||
83 | $frame_uid, |
||
84 | $this->db->quoteString($frame_description), |
||
85 | $this->db->quoteString($frame_width), |
||
86 | $this->db->quoteString($frame_height), |
||
87 | $frame_align, |
||
88 | $frame_frameborder, |
||
89 | $frame_marginwidth, |
||
90 | $frame_marginheight, |
||
91 | $frame_scrolling, |
||
92 | $frame_hits, |
||
93 | $this->db->quoteString($frame_url) |
||
94 | ); |
||
95 | $force = true; |
||
96 | } else { |
||
97 | $format = 'UPDATE %s SET frame_description=%s, frame_width=%s, frame_height=%s, frame_align="%d", frame_frameborder="%d", frame_marginwidth="%d", frame_marginheight="%d", frame_scrolling="%d", frame_hits="%u", frame_url=%s WHERE frame_frameid=%u'; |
||
98 | $sql = \sprintf( |
||
99 | $format, |
||
100 | $this->db->prefix('myiframe'), |
||
101 | $this->db->quoteString($frame_description), |
||
102 | $this->db->quoteString($frame_width), |
||
103 | $this->db->quoteString($frame_height), |
||
104 | $frame_align, |
||
105 | $frame_frameborder, |
||
106 | $frame_marginwidth, |
||
107 | $frame_marginheight, |
||
108 | $frame_scrolling, |
||
109 | $frame_hits, |
||
110 | $this->db->quoteString($frame_url), |
||
111 | $frame_frameid |
||
112 | ); |
||
113 | } |
||
114 | if (false !== $force) { |
||
115 | $result = $this->db->queryF($sql); |
||
116 | } else { |
||
117 | $result = $this->db->query($sql); |
||
118 | } |
||
119 | if (!$result) { |
||
120 | return false; |
||
121 | } |
||
122 | if (empty($frame_frameid)) { |
||
123 | $frame_frameid = $this->db->getInsertId(); |
||
124 | } |
||
125 | $object->assignVar('frame_frameid', $frame_frameid); |
||
126 | |||
127 | return $frame_frameid; |
||
128 | } |
||
230 |