Completed
Pull Request — master (#3)
by
unknown
01:52
created

XsitemapCorePreload::eventCoreIndexStart()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 4
nop 1
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
1
<?php
2
/*
3
 * xSiteMap module
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * @package    module\xsitemap\admin
14
 * @copyright  http://xoops.org 2001-2017 XOOPS Project
15
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU Public License
16
 * @author     ZySpec <[email protected]>
17
 * @link       http://xoops.org XOOPS
18
 * @since::    1.54
19
 **/
20
21
 /**
22
  * Xoopspoll Core Preload Class
23
  *
24
  * class used to check status of mailing polls that have ended.
25
  *
26
  * @package xoopspoll
27
  * @subpackage class
28
  */
29
class XsitemapCorePreload extends XoopsPreloadItem
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...
30
{
31
    /**
32
     * plugin class for Xoops preload for index page start
33
     * @return void
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
34
     */
35
    public function eventCoreIndexStart($args)
0 ignored issues
show
Coding Style introduced by
eventCoreIndexStart uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
36
    {
37
        // check once per user session if xsitemap exists
38
        $sessionVar = 'xsitemapChecked';
39
        $retVal = true;
40
        if (empty($_SESSION[$sessionVar])) {
41
            if (!file_exists(dirname(__DIR__) . "/xsitemap.xml")) {
42
                require_once dirname(__DIR__) . "/include/functions.php";
43
                //Create the xsitemap.xml file in the site root
44
                $xsitemap_show = xsitemap_generate_sitemap();
45
                $retVal = xsitemap_save($xsitemap_show) ? true : false;
46
            }
47
            $_SESSION[$sessionVar] = 1;
48
        }
49
        return $retVal;
50
    }
51
}
52