index.php ➔ loadSampleData()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 29

Duplication

Lines 8
Ratio 27.59 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 8
loc 29
rs 9.456
c 0
b 0
f 0
1
<?php
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/';
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