SocialnetworkForm::message()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
cc 4
nc 4
nop 3
1
<?php
2
3
namespace XoopsModules\Xoosocialnetwork\Form;
4
5
/**
6
 * Xoosocialnetwork module
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xoosocialnetwork
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
21
 */
22
23
/**
24
 * Class SocialnetworkForm
25
 */
26
class SocialnetworkForm extends \Xoops\Form\ThemeForm
27
{
28
    /**
29
     * @param \XooSocialNetworkSocialnetwork|\XoopsObject $obj
0 ignored issues
show
Bug introduced by
The type XooSocialNetworkSocialnetwork was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
     */
31
    public function __construct($obj = null)
32
    {
33
        $this->xoopsObject = $obj;
0 ignored issues
show
Bug Best Practice introduced by
The property xoopsObject does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
34
35
        $helper = \XoopsModules\Xoosocialnetwork\Helper::getInstance();
36
        $socialnetworkHandler = $helper->getHandler('Socialnetwork');
0 ignored issues
show
Unused Code introduced by
The assignment to $socialnetworkHandler is dead and can be removed.
Loading history...
37
38
        if ($this->xoopsObject->isNew()) {
0 ignored issues
show
Bug introduced by
The method isNew() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        if ($this->xoopsObject->/** @scrutinizer ignore-call */ isNew()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
            parent::__construct('', 'form_socialnetwork', 'index.php', 'post', true);
40
        } else {
41
            parent::__construct('', 'form_socialnetwork', 'index.php', 'post', true);
42
        }
43
        $this->setExtra('enctype="multipart/form-data"');
44
45
        // Title
46
        $this->addElement(new \Xoops\Form\Text(_AM_XOO_SN_TITLE, 'xoosocialnetwork_title', 5, 255, $this->xoopsObject->getVar('xoosocialnetwork_title')), true);
0 ignored issues
show
Bug introduced by
It seems like $this->xoopsObject->getV...oosocialnetwork_title') can also be of type string[]; however, parameter $value of Xoops\Form\Text::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        $this->addElement(new \Xoops\Form\Text(_AM_XOO_SN_TITLE, 'xoosocialnetwork_title', 5, 255, /** @scrutinizer ignore-type */ $this->xoopsObject->getVar('xoosocialnetwork_title')), true);
Loading history...
47
48
        // Url
49
        $this->addElement(new \Xoops\Form\Text(_AM_XOO_SN_URL, 'xoosocialnetwork_url', 7, 255, $this->xoopsObject->getVar('xoosocialnetwork_url')), true);
50
51
        // Query string URL
52
        $queryUrl = new \Xoops\Form\Text(_AM_XOO_SN_QUERY_URL, 'xoosocialnetwork_query_url', 5, 20, $this->xoopsObject->getVar('xoosocialnetwork_query_url'));
53
        $queryUrl->setDatalist([
54
                                   'u',
55
                                   'url', ]);
56
        $this->addElement($queryUrl, true);
57
58
        // Query string title
59
        $queryString = new \Xoops\Form\Text(_AM_XOO_SN_QUERY_TITLE, 'xoosocialnetwork_query_title', 5, 20, $this->xoopsObject->getVar('xoosocialnetwork_query_title'));
60
        $queryString->setDatalist([
61
                                      't',
62
                                      'title', ]);
63
        $this->addElement($queryString);
64
65
        // image
66
        $xoops = \Xoops::getInstance();
67
        $imageTray = new \Xoops\Form\ElementTray(_AM_XOO_SN_IMAGE, '');
68
        $imageArray = \XoopsLists::getImgListAsArray($xoops->path('modules/xoosocialnetwork/assets/icons/Default'));
69
        $imageSelect = new \Xoops\Form\Select('', 'xoosocialnetwork_image', $this->xoopsObject->getVar('xoosocialnetwork_image'));
70
        $imageSelect->addOptionArray($imageArray);
71
        $imageSelect->setExtra("onchange='showImgSelected(\"select_image\", \"xoosocialnetwork_image\", \"" . '/' . '", "", "' . $xoops->url('modules/xoosocialnetwork/assets/icons/Default') . "\")'");
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

71
        /** @scrutinizer ignore-deprecated */ $imageSelect->setExtra("onchange='showImgSelected(\"select_image\", \"xoosocialnetwork_image\", \"" . '/' . '", "", "' . $xoops->url('modules/xoosocialnetwork/assets/icons/Default') . "\")'");

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
72
        $imageTray->addElement($imageSelect);
73
        $imageTray->addElement(new \Xoops\Form\Label('', "<br><img src='" . $xoops->url('modules/xoosocialnetwork/assets/icons/Default/') . $this->xoopsObject->getVar('xoosocialnetwork_image') . "' name='select_image' id='select_image' alt=''>"));
74
        $this->addElement($imageTray);
75
76
        // order
77
        $this->addElement(new \Xoops\Form\Text(_AM_XOO_SN_ORDER, 'xoosocialnetwork_order', 1, 3, $this->xoopsObject->getVar('xoosocialnetwork_order')));
78
79
        // display
80
        $this->addElement(new \Xoops\Form\RadioYesNo(_AM_XOO_SN_DISPLAY, 'xoosocialnetwork_display', $this->xoopsObject->getVar('xoosocialnetwork_display')));
0 ignored issues
show
Bug introduced by
It seems like $this->xoopsObject->getV...socialnetwork_display') can also be of type string[]; however, parameter $value of Xoops\Form\RadioYesNo::__construct() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

80
        $this->addElement(new \Xoops\Form\RadioYesNo(_AM_XOO_SN_DISPLAY, 'xoosocialnetwork_display', /** @scrutinizer ignore-type */ $this->xoopsObject->getVar('xoosocialnetwork_display')));
Loading history...
81
82
        // hidden
83
        $this->addElement(new \Xoops\Form\Hidden('xoosocialnetwork_id', $this->xoopsObject->getVar('xoosocialnetwork_id')));
0 ignored issues
show
Bug introduced by
It seems like $this->xoopsObject->getVar('xoosocialnetwork_id') can also be of type string[]; however, parameter $value of Xoops\Form\Hidden::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

83
        $this->addElement(new \Xoops\Form\Hidden('xoosocialnetwork_id', /** @scrutinizer ignore-type */ $this->xoopsObject->getVar('xoosocialnetwork_id')));
Loading history...
84
85
        // button
86
        $buttonTray = new \Xoops\Form\ElementTray('', '');
87
        $buttonTray->addElement(new \Xoops\Form\Hidden('op', 'save'));
88
        $buttonTray->addElement(new \Xoops\Form\Button('', 'submit', \XoopsLocale::A_SUBMIT, 'submit'));
89
        $buttonTray->addElement(new \Xoops\Form\Button('', 'reset', \XoopsLocale::A_RESET, 'reset'));
90
        $buttonCancelSend = new \Xoops\Form\Button('', 'cancel', \XoopsLocale::A_CANCEL, 'button');
91
        $buttonCancelSend->setExtra("onclick='javascript:history.go(-1);'");
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

91
        /** @scrutinizer ignore-deprecated */ $buttonCancelSend->setExtra("onclick='javascript:history.go(-1);'");

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
92
        $buttonTray->addElement($buttonCancelSend);
93
        $this->addElement($buttonTray);
94
    }
95
96
    /**
97
     * @param        $msg
98
     * @param string $title
99
     * @param string $class
100
     * @return string
101
     */
102
    public function message($msg, $title = '', $class = 'errorMsg')
103
    {
104
        $ret = "<div class='" . $class . "'>";
105
        if ('' != $title) {
106
            $ret .= '<strong>' . $title . '</strong>';
107
        }
108
        if (is_array($msg) || is_object($msg)) {
109
            $ret .= implode('<br>', $msg);
0 ignored issues
show
Bug introduced by
It seems like $msg can also be of type object; however, parameter $pieces of implode() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
            $ret .= implode('<br>', /** @scrutinizer ignore-type */ $msg);
Loading history...
110
        } else {
111
            $ret .= $msg;
112
        }
113
        $ret .= '</div>';
114
115
        return $ret;
116
    }
117
}
118