Passed
Pull Request — master (#8)
by Michael
14:42
created

myiframe_iframe.php ➔ b_myiframe_iframe_show()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 26
nc 2
nop 1
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * ****************************************************************************
5
 * MYIFRAME - MODULE FOR XOOPS
6
 * Copyright (c) Hervé Thouzard of Instant Zero (https://www.instant-zero.com)
7
 * ****************************************************************************
8
 */
9
10
use XoopsModules\Newbb;
0 ignored issues
show
Bug introduced by
The type XoopsModules\Newbb 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...
11
use XoopsModules\Myiframe\{
12
    Constants,
13
    Helper
14
};
15
/** @var Helper $helper */
16
17
require_once XOOPS_ROOT_PATH . '/modules/myiframe/include/functions.php';
18
19
/**
20
 * @param $options
21
 * @return array
22
 */
23
function b_myiframe_iframe_show($options)
24
{
25
    if (!class_exists(Helper::class)) {
26
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type array.
Loading history...
27
    }
28
    $frame         = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $frame is dead and can be removed.
Loading history...
29
    $helper = Helper::getInstance();
30
    $block         = [];
31
    $tblalign      = [
32
        'top',
33
        'middle',
34
        'bottom',
35
        'left',
36
        'rigth',
37
    ];
38
    $tblscrolling  = [
39
        'yes',
40
        'no',
41
        'auto',
42
    ];
43
    $iframeHandler = $helper->getHandler('MyiframeBase');
44
    $frame         = $iframeHandler->get($options[0]);
45
46
    if (is_object($frame)) {
47
        $block['longdesc']     = $frame->getVar('frame_description');
48
        $block['width']        = $frame->getVar('frame_width');
49
        $block['height']       = $frame->getVar('frame_height');
50
        $block['align']        = $tblalign[$frame->getVar('frame_align') - 1];
51
        $block['frameborder']  = $frame->getVar('frame_frameborder');
52
        $block['marginwidth']  = $frame->getVar('frame_marginwidth');
53
        $block['marginheight'] = $frame->getVar('frame_marginheight');
54
        $block['scrolling']    = $tblscrolling[$frame->getVar('frame_scrolling') - 1];
55
        $block['url']          = $frame->getVar('frame_url');
56
    }
57
58
    return $block;
59
}
60
61
/**
62
 * @param $options
63
 * @return string
64
 */
65
function b_myiframe_iframe_edit($options)
66
{
67
    if (!class_exists(Helper::class)) {
68
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
69
    }
70
    $helper = Helper::getInstance();
71
72
    /** @var \MyiframeBaseHandler $iframeHandler */
73
    $iframeHandler = $helper->getHandler('MyiframeBase');
74
    $frarray       = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $frarray is dead and can be removed.
Loading history...
75
    $critere       = new \Criteria('1', '1', '=');
76
    $critere->setSort('frame_description');
77
    $frarray = $iframeHandler->getObjects($critere);
78
79
    $form = '' . _MB_MYIFRAME_IFRAME . "&nbsp;<select name='options[0]'>";
80
    /** @var Myiframe $oneframe */
81
    foreach ($frarray as $oneframe) {
82
        $form .= "<option value='" . $oneframe->getVar('frame_frameid') . "'";
83
        if ($options[0] == $oneframe->getVar('frame_frameid')) {
84
            $form .= " selected='selected'";
85
        }
86
        $form .= '>' . $oneframe->getVar('frame_description') . '</option>';
87
    }
88
    $form .= "</select>\n";
89
90
    return $form;
91
}
92
93
/**
94
 * @param $options
95
 */
96
function b_myiframe_iframe_onthefly($options): void
97
{
98
    $options = explode('|', $options);
99
    $block   = b_myiframe_iframe_show($options);
100
101
    $tpl = new \XoopsTpl();
102
    $tpl->assign('block', $block);
103
    $tpl->display('db:myiframe_block_show.tpl');
104
}
105