PersistableMlObjectHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 32.2 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 19
loc 59
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getObjects() 11 24 3
A get() 8 11 2
A changeTableNameForML() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace XoopsModules\Smartobject;
2
3
/**
4
 * Contains the basis classes for managing any objects derived from SmartObjects
5
 *
6
 * @license    GNU
7
 * @author     marcan <[email protected]>
8
 * @link       http://smartfactory.ca The SmartFactory
9
 * @package    SmartObject
10
 * @subpackage SmartObjectCore
11
 */
12
13
use XoopsModules\Smartobject;
14
15
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
16
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
17
18
19
/**
20
 * Class SmartPersistableMlObjectHandler
21
 */
22
class PersistableMlObjectHandler extends Smartobject\PersistableObjectHandler
23
{
24
    /**
25
     * @param  null|\CriteriaElement  $criteria
26
     * @param  bool $id_as_key
27
     * @param  bool $as_object
28
     * @param  bool $debug
29
     * @param  bool $language
30
     * @return array
31
     */
32
    public function getObjects(
33
        \CriteriaElement $criteria = null,
34
        $id_as_key = false,
35
        $as_object = true,
36
        $debug = false,
37
        $language = false
38
    ) {
39
        // Create the first part of the SQL query to join the "_text" table
40
        $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->table . '_text AS ' . $this->_itemname . '_text ON ' . $this->_itemname . '.' . $this->keyName . '=' . $this->_itemname . '_text.' . $this->keyName;
41
42 View Code Duplication
        if ($language) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
            // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language
44
45
            // if no criteria was previously created, let's create it
46
            if (!$criteria) {
47
                $criteria = new \CriteriaCompo();
48
            }
49
            $criteria->add(new \Criteria('language', $language));
50
51
            return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql);
52
        }
53
54
        return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql);
55
    }
56
57
    /**
58
     * @param  mixed $id
59
     * @param  bool  $language
60
     * @param  bool  $as_object
61
     * @param  bool  $debug
62
     * @return mixed
63
     */
64
    public function &get($id, $language = false, $as_object = true, $debug = false)
65
    {
66 View Code Duplication
        if (!$language) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
            return parent::get($id, $as_object, $debug);
68
        } else {
69
            $criteria = new \CriteriaCompo();
70
            $criteria->add(new \Criteria('language', $language));
71
72
            return parent::get($id, $as_object, $debug, $criteria);
73
        }
74
    }
75
76
    public function changeTableNameForML()
77
    {
78
        $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text');
79
    }
80
}
81