Completed
Push — master ( 88111b...b3fce7 )
by Michael
05:58
created

PersistableMlObjectHandler::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 8
Ratio 72.73 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 4
dl 8
loc 11
rs 9.4285
c 0
b 0
f 0
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');
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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