Completed
Push — master ( 171474...8d265e )
by Michael
01:31
created

index.php ➔ loadSampleData()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 29
Code Lines 20

Duplication

Lines 8
Ratio 27.59 %

Importance

Changes 0
Metric Value
cc 3
eloc 20
nc 2
nop 0
dl 8
loc 29
rs 8.8571
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 42 and the first side effect is on line 28.

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
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
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
/**
14
 * Module: randomquote
15
 *
16
 * @category        Module
17
 * @package         randomquote
18
 * @author          XOOPS Development Team <[email protected]> - <https://xoops.org>
19
 * @copyright       {@link https://xoops.org/ XOOPS Project}
20
 * @license         GPL 2.0 or later
21
 * @link            https://xoops.org/
22
 * @since           1.0.0
23
 */
24
25
use Xoopsmodules\randomquote;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, randomquote.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
26
use Xoopsmodules\randomquote\common;
27
28
require_once __DIR__ . '/../../../mainfile.php';
29
30
include __DIR__ . '/../preloads/autoloader.php';
31
32
$op = \Xmf\Request::getCmd('op', '');
33
34
switch ($op) {
35
    case 'load':
36
        loadSampleData();
37
        break;
38
}
39
40
// XMF TableLoad for SAMPLE data
41
42
function loadSampleData()
43
{
44
    $moduleDirName = basename(dirname(__DIR__));
45
    $helper        = randomquote\Helper::getInstance();
46
    $utility       = new randomquote\Utility();
47
    $configurator  = new common\Configurator();
48
    // Load language files
49
    $helper->loadLanguage('admin');
50
    $helper->loadLanguage('modinfo');
51
    $helper->loadLanguage('common');
52
    $quotesData = \Xmf\Yaml::readWrapped('quotes.yml');
53
    \Xmf\Database\TableLoad::truncateTable($moduleDirName . '_quotes');
54
    \Xmf\Database\TableLoad::loadTableFromArray($moduleDirName . '_quotes', $quotesData);
55
56
    $categoryData = \Xmf\Yaml::readWrapped('category.yml');
57
    \Xmf\Database\TableLoad::truncateTable($moduleDirName . '_category');
58
    \Xmf\Database\TableLoad::loadTableFromArray($moduleDirName . '_category', $categoryData);
59
60
    //  ---  COPY test folder files ---------------
61 View Code Duplication
    if (count($configurator->copyTestFolders) > 0) {
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...
62
        //        $file = __DIR__ . '/../testdata/images/';
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% 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...
63
        foreach (array_keys($configurator->copyTestFolders) as $i) {
64
            $src  = $configurator->copyTestFolders[$i][0];
65
            $dest = $configurator->copyTestFolders[$i][1];
66
            $utility::xcopy($src, $dest);
67
        }
68
    }
69
    redirect_header('../admin/index.php', 1, AM_RANDOMQUOTE_SAMPLEDATA_SUCCESS);
70
}
71