Code Duplication    Length = 54-55 lines in 2 locations

src/Intraface/modules/debtor/DebtorGateway.php 1 location

@@ 153-206 (lines=54) @@
150
        return $object;
151
    }
152
153
    function findByIdentifier($identifier)
154
    {
155
        if (is_int($id) && $id != 0) {
156
            $types = self::getDebtorTypes();
157
158
            $db = new DB_Sql;
159
            $db->query("SELECT type FROM debtor WHERE intranet_id = ".$kernel->intranet->get('id')." AND id = ".$id);
160
            if ($db->nextRecord()) {
161
                $type = $types[$db->f("type")];
162
            } else {
163
                throw new Exception("Invalid id for debtor in Debtor::factory");
164
            }
165
        } elseif (is_string($id) && $id != '') {
166
            $types = self::getDebtorTypes();
167
168
            $db = new DB_Sql;
169
            $db->query("SELECT type, id FROM debtor WHERE intranet_id = ".$kernel->intranet->get('id')." AND identifier_key = \"".$id."\"");
170
            if ($db->nextRecord()) {
171
                $type = $types[$db->f("type")];
172
                $id = $db->f("id");
173
            } else {
174
                throw new Exception("Invalid identifier_key for debtor in Debtor::factory");
175
            }
176
        }
177
178
        switch ($type) {
179
            case "quotation":
180
                $kernel->useModule("quotation");
181
                $object = new Quotation($kernel, intval($id));
182
                return $object;
183
                break;
184
185
            case "order":
186
                $kernel->useModule("order");
187
                $object = new Order($kernel, intval($id));
188
                break;
189
190
            case "invoice":
191
                $kernel->useModule("invoice");
192
                $object = new Invoice($kernel, intval($id));
193
                break;
194
195
            case "credit_note":
196
                $kernel->useModule("invoice");
197
                $object = new CreditNote($kernel, intval($id));
198
                break;
199
200
            default:
201
                throw new Exception("Ugyldig type: '".$type."'");
202
                break;
203
        }
204
205
        return $object;
206
    }
207
208
    /**
209
     * Gets a list with debtors

src/Intraface/modules/debtor/Debtor.php 1 location

@@ 146-200 (lines=55) @@
143
     * @param integer $id     Debtor id or debtor identifier_key
144
     * @param type    $tpye   String TODO What is this used for as a last parameter?
145
     */
146
    public static function factory($kernel, $id = 0, $type = "")
147
    {
148
        if (is_int($id) && $id != 0) {
149
            $types = self::getDebtorTypes();
150
151
            $db = new DB_Sql;
152
            $db->query("SELECT type FROM debtor WHERE intranet_id = ".$kernel->intranet->get('id')." AND id = ".$id);
153
            if ($db->nextRecord()) {
154
                $type = $types[$db->f("type")];
155
            } else {
156
                throw new Exception("Invalid id for debtor in Debtor::factory");
157
            }
158
        } elseif (is_string($id) && $id != '') {
159
            $types = self::getDebtorTypes();
160
161
            $db = new DB_Sql;
162
            $db->query("SELECT type, id FROM debtor WHERE intranet_id = ".$kernel->intranet->get('id')." AND identifier_key = \"".$id."\"");
163
            if ($db->nextRecord()) {
164
                $type = $types[$db->f("type")];
165
                $id = $db->f("id");
166
            } else {
167
                throw new Exception("Invalid identifier_key for debtor in Debtor::factory");
168
            }
169
        }
170
171
        switch ($type) {
172
            case "quotation":
173
                $kernel->useModule("quotation");
174
                $object = new Quotation($kernel, intval($id));
175
                return $object;
176
                break;
177
178
            case "order":
179
                $kernel->useModule("order");
180
                $object = new Order($kernel, intval($id));
181
                break;
182
183
            case "invoice":
184
                $kernel->useModule("invoice");
185
                $object = new Invoice($kernel, intval($id));
186
                break;
187
188
            case "credit_note":
189
                $kernel->useModule("invoice");
190
                $object = new CreditNote($kernel, intval($id));
191
                break;
192
193
            default:
194
                throw new Exception("Ugyldig type: '".$type."'");
195
                break;
196
        }
197
198
        return $object;
199
    }
200
201
    /**
202
     * Loads debtor into an array
203
     *