Passed
Pull Request — master (#9)
by Michael
03:24
created

Category::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace XoopsModules\Mylinks;
4
5
/**
6
 * MyLinks category.php
7
 *
8
 * Xoops mylinks - a multicategory links module
9
 *
10
 * You may not change or alter any portion of this comment or credits
11
 * of supporting developers from this source code or any supporting source code
12
 * which is considered copyrighted (c) material of the original comment or credit authors.
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 *
17
 * @copyright ::  &copy; ZySpec Incorporated
18
 * @license   ::    {@link https://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
19
 * @package   ::    mylinks
20
 * @subpackage:: class
21
 * @since     ::      File available since version 3.11
22
 * @author    ::     zyspec ([email protected])
23
 */
24
25
26
27
$mylinksDir = basename(dirname(__DIR__));
28
29
/**
30
 * Class mylinksCategory_base
31
 */
32
class Category extends \XoopsObject
33
{
34
    /**
35
     * constructor
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
        //definitions of the table field names from the database
41
        $this->initVar('cid', XOBJ_DTYPE_INT, null, false);
42
        $this->initVar('pid', XOBJ_DTYPE_INT, 0, true);
43
        $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, true, 50);
44
        $this->initVar('imgurl', XOBJ_DTYPE_TXTAREA);
45
    }
46
47
    /**
48
     * Returns category title using PHP5
49
     * @return string
50
     */
51
    public function __toString()
52
    {
53
        return $this->title;
0 ignored issues
show
Bug Best Practice introduced by
The property title does not exist on XoopsModules\Mylinks\Category. Did you maybe forget to declare it?
Loading history...
54
    }
55
56
    /**
57
     * Generates path from the root id to a given id($id)
58
     * @param int    $id
59
     * @param string $path
60
     * @return string
61
     */
62
    public function getPathFromId($id = null, $path = '')
63
    {
64
        $id   = isset($id) ? (int)$id : $this->cid;
0 ignored issues
show
Bug Best Practice introduced by
The property cid does not exist on XoopsModules\Mylinks\Category. Did you maybe forget to declare it?
Loading history...
Unused Code introduced by
The assignment to $id is dead and can be removed.
Loading history...
65
        $myts = \MyTextSanitizer::getInstance();
66
        $name = $myts->htmlSpecialChars($this->title);
0 ignored issues
show
Bug Best Practice introduced by
The property title does not exist on XoopsModules\Mylinks\Category. Did you maybe forget to declare it?
Loading history...
67
        $path = "/{$name}{$path}";
68
        if (0 != $this->pid) {
0 ignored issues
show
Bug Best Practice introduced by
The property pid does not exist on XoopsModules\Mylinks\Category. Did you maybe forget to declare it?
Loading history...
69
            $path = $this->getPathFromId($this->pid, $path);
70
        }
71
72
        return $path;
73
    }
74
}
75