AlumniCategoryForm   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 87
Duplicated Lines 6.9 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 6
loc 87
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C __construct() 6 81 7

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
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * @copyright       XOOPS Project (https://xoops.org)
14
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author          trabis <[email protected]>
16
 * @version         $Id$
17
 */
18
class AlumniCategoryForm extends Xoops\Form\ThemeForm
0 ignored issues
show
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...
19
{
20
    /**
21
     * @param AlumniCategory|XoopsObject $obj
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $obj a bit more specific; maybe use AlumniCategory.
Loading history...
22
     */
23
    public function __construct(AlumniCategory $obj)
24
    {
25
        $xoops         = Xoops::getInstance();
26
        $moduleDirName = basename(dirname(__DIR__));
27
        $admin_lang    = '_AM_' . strtoupper($moduleDirName);
0 ignored issues
show
Coding Style introduced by
$admin_lang does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Unused Code introduced by
$admin_lang is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
29
        $title = sprintf($obj->isNew() ? AlumniLocale::ADD_CAT : AlumniLocale::EDIT_CAT);
30
        parent::__construct($title, 'form', false, 'post', true);
31
32
        include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
33
34
        $this->setExtra('enctype="multipart/form-data"');
35
36
        include_once XOOPS_ROOT_PATH . '/class/tree.php';
37
        $categoryHandler = $xoops->getModuleHandler('category', 'alumni');
38
        $arr             = $categoryHandler->getAll();
39
        $mytree          = new XoopsObjectTree($arr, 'cid', 'pid');
40
41
        $this->addElement(new Xoops\Form\Label(AlumniLocale::CATEGORY_PID, $mytree->makeSelBox('pid', 'title', '-', $obj->getVar('pid'), true)));
42
        $this->addElement(new Xoops\Form\Text(AlumniLocale::CATEGORY_TITLE, 'title', 50, 255, $obj->getVar('title')), true);
43
44
        if ($obj->isNew()) {
45
            $default_img = 'default.gif';
0 ignored issues
show
Coding Style introduced by
$default_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
46
        } else {
47
            $default_img = str_replace('alumni/', '', $obj->getVar('img', 'e'));
0 ignored issues
show
Coding Style introduced by
$default_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
48
        }
49
50
        $img         = $obj->getVar('img') ?: 'default.gif';
51
        $imgtray_img = new Xoops\Form\ElementTray(AlumniLocale::IMGCAT, '<br>');
0 ignored issues
show
Coding Style introduced by
$imgtray_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
52
        $img_path    = \XoopsBaseConfig::get('root-path') . '/modules/alumni/images/cat';
0 ignored issues
show
Coding Style introduced by
$img_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
53
54
        $imgpath_img     = sprintf(AlumniLocale::FORMIMAGE_PATH, $img_path);
0 ignored issues
show
Coding Style introduced by
$imgpath_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Unused Code introduced by
$imgpath_img is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
        $imageselect_img = new Xoops\Form\Select(sprintf(XoopsLocale::F_FILE_EXISTS_IN, $img_path . '/'), 'img', $img);
0 ignored issues
show
Coding Style introduced by
$imageselect_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
56
        $image_array_img = XoopsLists::getImgListAsArray($img_path);
0 ignored issues
show
Coding Style introduced by
$image_array_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
57
        $imageselect_img->addOption("$default_img", $default_img);
0 ignored issues
show
Coding Style introduced by
$imageselect_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
58
        foreach ($image_array_img as $image_img) {
0 ignored issues
show
Coding Style introduced by
$image_array_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
59
            $imageselect_img->addOption("$image_img", $image_img);
0 ignored issues
show
Coding Style introduced by
$imageselect_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
60
        }
61
62
        $alumni_upload_url = \XoopsBaseConfig::get('url') . '/modules/alumni/images/cat';
0 ignored issues
show
Coding Style introduced by
$alumni_upload_url does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
63
64
        $imageselect_img->setExtra("onchange='showImgSelected(\"image_img\", \"img\", \"\", \"\", \"" . $alumni_upload_url . "\")'");
0 ignored issues
show
Coding Style introduced by
$imageselect_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
65
        $imgtray_img->addElement($imageselect_img, false);
0 ignored issues
show
Coding Style introduced by
$imgtray_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
66
        $imgtray_img->addElement(new Xoops\Form\Label('', "<br><img src='" . $alumni_upload_url . '/' . $img . "' name='image_img' id='image_img' alt=''>"));
0 ignored issues
show
Coding Style introduced by
$imgtray_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
67
68
        $fileseltray_category_img = new Xoops\Form\ElementTray('<br>', '<br>');
0 ignored issues
show
Coding Style introduced by
$fileseltray_category_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
69
        $fileseltray_category_img->addElement(new Xoops\Form\File(AlumniLocale::FORMUPLOAD, 'img'), false);
0 ignored issues
show
Coding Style introduced by
$fileseltray_category_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
70
        $fileseltray_category_img->addElement(new Xoops\Form\Label(''), false);
0 ignored issues
show
Coding Style introduced by
$fileseltray_category_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
71
        $imgtray_img->addElement($fileseltray_category_img);
0 ignored issues
show
Coding Style introduced by
$imgtray_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
72
        $this->addElement($imgtray_img);
0 ignored issues
show
Coding Style introduced by
$imgtray_img does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
73
74
        $this->addElement(new Xoops\Form\Text(AlumniLocale::ORDER, 'ordre', 4, 4, $obj->getVar('ordre')), false);
75
        $this->addElement(new Xoops\Form\Label(AlumniLocale::IFSCHOOL, ''));
76
77
        $photo_old            = $obj->getVar('scphoto') ?: '';
0 ignored issues
show
Coding Style introduced by
$photo_old does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
78
        $uploadirectory_photo = XOOPS_ROOT_PATH . "/uploads/{$moduleDirName}/photos/school_photos";
0 ignored issues
show
Coding Style introduced by
$uploadirectory_photo does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
79
        $imgtray_photo        = new Xoops\Form\ElementTray(AlumniLocale::SCPHOTO, '<br>');
0 ignored issues
show
Coding Style introduced by
$imgtray_photo does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
80
        $imgpath_photo        = sprintf(AlumniLocale::FORMIMAGE_PATH, $uploadirectory_photo);
0 ignored issues
show
Coding Style introduced by
$imgpath_photo does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Unused Code introduced by
$imgpath_photo is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
81
        $fileseltray_photo    = new Xoops\Form\ElementTray('', '<br>');
0 ignored issues
show
Coding Style introduced by
$fileseltray_photo does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
82
        $fileseltray_photo->addElement(new XoopsFormFile(AlumniLocale::FORMUPLOAD, 'scphoto', $xoops->getModuleConfig('alumni_photomax')), false);
0 ignored issues
show
Coding Style introduced by
$fileseltray_photo does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
83 View Code Duplication
        if ($photo_old) {
0 ignored issues
show
Coding Style introduced by
$photo_old does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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...
84
            $fileseltray_photo->addElement(new Xoops\Form\Label(AlumniLocale::SELECTED_PHOTO, '<a href="../photos/school_photos/' . $photo_old . '">' . $photo_old . '</a>', false));
0 ignored issues
show
Coding Style introduced by
$fileseltray_photo does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
85
            $imgtray_checkbox = new Xoops\Form\Checkbox('', 'del_photo', 0);
0 ignored issues
show
Coding Style introduced by
$imgtray_checkbox does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
86
            $imgtray_checkbox->addOption(1, AlumniLocale::DELPICT);
0 ignored issues
show
Coding Style introduced by
$imgtray_checkbox does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
87
            $fileseltray_photo->addElement($imgtray_checkbox);
0 ignored issues
show
Coding Style introduced by
$fileseltray_photo does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
88
        }
89
        $imgtray_photo->addElement($fileseltray_photo);
0 ignored issues
show
Coding Style introduced by
$imgtray_photo does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
90
        $this->addElement($imgtray_photo);
0 ignored issues
show
Coding Style introduced by
$imgtray_photo does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
91
        $this->addElement(new Xoops\Form\Hidden('photo_old', $photo_old));
0 ignored issues
show
Coding Style introduced by
$photo_old does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
92
        $this->addElement(new Xoops\Form\Text(AlumniLocale::SCADDRESS, 'scaddress', 50, 255, $obj->getVar('scaddress')), false);
93
        $this->addElement(new Xoops\Form\Text(AlumniLocale::SCADDRESS2, 'scaddress2', 50, 255, $obj->getVar('scaddress2')), false);
94
        $this->addElement(new Xoops\Form\Text(AlumniLocale::SCCITY, 'sccity', 50, 255, $obj->getVar('sccity')), false);
95
        $this->addElement(new Xoops\Form\Text(AlumniLocale::SCSTATE, 'scstate', 50, 255, $obj->getVar('scstate')), false);
96
        $this->addElement(new Xoops\Form\Text(AlumniLocale::SCZIP, 'sczip', 50, 255, $obj->getVar('sczip')), false);
97
        $this->addElement(new Xoops\Form\Text(AlumniLocale::SCPHONE, 'scphone', 50, 255, $obj->getVar('scphone')), false);
98
        $this->addElement(new Xoops\Form\Text(AlumniLocale::SCFAX, 'scfax', 50, 255, $obj->getVar('scfax')), false);
99
        $this->addElement(new Xoops\Form\Text(AlumniLocale::SCMOTTO, 'scmotto', 50, 255, $obj->getVar('scmotto')), false);
100
        $this->addElement(new Xoops\Form\Text(AlumniLocale::SCURL, 'scurl', 50, 255, $obj->getVar('scurl')), false);
101
        $this->addElement(new Xoops\Form\Hidden('op', 'save_category'));
102
        $this->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit'));
103
    }
104
}
105