Completed
Push — master ( c40551...5ee518 )
by Michael
03:07
created

martin.hotel.php ➔ martin_hotel_search_show()   C

Complexity

Conditions 8
Paths 20

Size

Total Lines 49
Code Lines 32

Duplication

Lines 11
Ratio 22.45 %

Importance

Changes 0
Metric Value
cc 8
eloc 32
nc 20
nop 1
dl 11
loc 49
rs 6.1403
c 0
b 0
f 0
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 18 and the first side effect is on line 10.

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
 * @license   http://www.blags.org/
5
 * @created   :2010年05月19日 22时38分
6
 * @copyright 1997-2010 The Martin Group
7
 * @author    Martin <[email protected]>
8
 * */
9
if (!defined('XOOPS_ROOT_PATH')) {
10
    exit();
11
}
12
13
/**
14
 * hoel search show function
15
 * @param $options
16
 * @return
17
 */
18
function martin_hotel_search_show($options)
19
{
20
    global $xoopsModuleConfig, $xoopsModule, $xoopsTpl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
21
    //新闻
22
    /*if($xoopsModule->dirname() != 'martin')
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
23
    {*/
24
    $module_handler    =& xoops_gethandler('module');
25
    $config_handler    =& xoops_gethandler('config');
26
    $xoopsModule       =& $module_handler->getByDirname('martin');
27
    $xoopsModuleConfig =& $config_handler->getConfigsByCat(0, $xoopsModule->getVar('mid'));
28
    /*}*/
29
    //var_dump($xoopsModuleConfig);
30
31
    include_once XOOPS_ROOT_PATH . '/modules/martin/include/functions.php';
32
    $hotel_handler   =& xoops_getmodulehandler("hotel", 'martin');
33
    $group_handler   =& xoops_getmodulehandler("group", 'martin');
34
    $auction_handler =& xoops_getmodulehandler("auction", 'martin');
35
    $news_handler    =& xoops_getmodulehandler("hotelnews", 'martin');
36
37
    $hotel_guide         = explode(",", $xoopsModuleConfig['hotel_guide']);
38
    $hotel_today_special = explode(",", $xoopsModuleConfig['hotel_today_special']);
39
    $hotel_news_ids      = (is_array($hotel_guide) && is_array($hotel_today_special)) ? array_merge($hotel_guide, $hotel_today_special) : null;
40
    $hotelnews           = $news_handler->GetHotelNews($hotel_news_ids);
41
42
    $hotel_guide_rows         = array();
43
    $hotel_today_special_rows = array();
44 View Code Duplication
    foreach ($hotelnews as $key => $row) {
0 ignored issues
show
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...
45
        if (in_array($key, $hotel_guide) && count($hotel_guide_rows) < 6) {
46
            $hotel_guide_rows[] = $row;
47
        }
48
        if (in_array($key, $hotel_today_special) && count($hotel_today_special_rows) < 6) {
49
            $hotel_today_special_rows[] = $row;
50
        }
51
    }
52
53
    $block['module_url']               = XOOPS_URL . '/modules/martin/';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$block was never initialized. Although not strictly required by PHP, it is generally a good practice to add $block = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
54
    $block['hotelrank']                = getModuleArray('hotelrank', 'hotelrank', true, null, $xoopsModuleConfig);
55
    $block['groupList']                = $group_handler->GetGroupList();
56
    $block['auctionList']              = $auction_handler->GetAuctionList();
57
    $block['hotel_guide_rows']         = $hotel_guide_rows;
58
    $block['hotel_today_special_rows'] = $hotel_today_special_rows;
59
    $block['cityList']                 = $hotel_handler->GetCityList('WHERE city_parentid = 0');
60
    $block['hotel_static_prefix']      = $xoopsModuleConfig['hotel_static_prefix'];
61
62
    unset($hotel_handler, $group_handler, $auction_handler, $news_handler, $hotel_guide_rows, $hotel_today_special_rows);
63
64
    //var_dump($block);
65
    return $block;
66
}
67
68
/**
69
 * hoel search edit function
70
 * @param $options
71
 * @return string
72
 */
73
function martin_hotel_search_edit($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
{
75
    return '';
76
}
77