SmartpartnerPartner_cat_linkHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 28
loc 28
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getParentIds() 12 12 2

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 37 and the first side effect is on line 31.

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.

Loading history...
2
// 
3
// ------------------------------------------------------------------------ //
4
//               XOOPS - PHP Content Management System                      //
5
//                   Copyright (c) 2000-2016 XOOPS.org                           //
6
//                      <http://xoops.org/>                             //
7
// ------------------------------------------------------------------------ //
8
// This program is free software; you can redistribute it and/or modify     //
9
// it under the terms of the GNU General Public License as published by     //
10
// the Free Software Foundation; either version 2 of the License, or        //
11
// (at your option) any later version.                                      //
12
13
// You may not change or alter any portion of this comment or credits       //
14
// of supporting developers from this source code or any supporting         //
15
// source code which is considered copyrighted (c) material of the          //
16
// original comment or credit authors.                                      //
17
// This program is distributed in the hope that it will be useful,          //
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
20
// GNU General Public License for more details.                             //
21
22
// You should have received a copy of the GNU General Public License        //
23
// along with this program; if not, write to the Free Software              //
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
25
// ------------------------------------------------------------------------ //
26
// URL: http://xoops.org/                                               //
27
// Project: XOOPS Project                                               //
28
// -------------------------------------------------------------------------//
29
30
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
31
include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
32
include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjecthandler.php';
33
34
/**
35
 * Class SmartpartnerPartnerCatLink
36
 */
37 View Code Duplication
class SmartpartnerPartner_cat_link extends SmartObject
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
38
{
39
    /**
40
     * SmartpartnerPartnerCatLink constructor.
41
     */
42
    public function __construct()
43
    {
44
        $this->initVar('partner_cat_linkid', XOBJ_DTYPE_INT, '', true);
45
        $this->initVar('partnerid', XOBJ_DTYPE_INT, '', true);
46
        $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true);
47
    }
48
}
49
50
/**
51
 * Class SmartpartnerPartnerCatLinkHandler
52
 */
53 View Code Duplication
class SmartpartnerPartner_cat_linkHandler extends SmartPersistableObjectHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
54
{
55
    /**
56
     * SmartpartnerPartnerCatLinkHandler constructor.
57
     * @param object|XoopsDatabase $db
58
     */
59
    public function __construct(XoopsDatabase $db)
60
    {
61
        parent::__construct($db, 'partner_cat_link', array('partnerid', 'categoryid'), '', false, 'smartpartner');
62
    }
63
64
    /**
65
     * @param $partnerid
66
     * @return string
67
     */
68
    public function getParentIds($partnerid)
69
    {
70
        $criteria = new CriteriaCompo();
71
        $criteria->add(new Criteria('partnerid', $partnerid));
72
        $links        = $this->getObjects($criteria);
73
        $parent_array = array();
74
        foreach ($links as $link) {
75
            $parent_array[] = $link->getVar('categoryid');
76
        }
77
78
        return implode('|', $parent_array);
79
    }
80
}
81