SocialnetworkHandler::readConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace XoopsModules\Xoosocialnetwork;
4
5
/**
6
 * Xoosocialnetwork module
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xoosocialnetwork
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
21
 */
22
use Xoops\Core\Database\Connection;
23
24
/**
25
 * Class SocialnetworkHandler
26
 */
27
class SocialnetworkHandler extends \XoopsPersistableObjectHandler
28
{
29
    /**
30
     * @param null|\Xoops\Core\Database\Connection $db
31
     */
32
    public function __construct(Connection $db = null)
33
    {
34
        $this->configPath = \XoopsBaseConfig::get('var-path') . '/configs/xoosocialnetwork/';
0 ignored issues
show
Bug Best Practice introduced by
The property configPath does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
        $this->configFile = 'xoosocialnetwork';
0 ignored issues
show
Bug Best Practice introduced by
The property configFile does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
36
        $this->configFileExt = '.php';
0 ignored issues
show
Bug Best Practice introduced by
The property configFileExt does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37
38
        parent::__construct($db, 'xoosocialnetwork', Socialnetwork::class, 'xoosocialnetwork_id', 'xoosocialnetwork_title');
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function renderAdminList()
45
    {
46
        $criteria = new \CriteriaCompo();
47
        $criteria->setSort('xoosocialnetwork_order');
48
        $criteria->setOrder('asc');
49
50
        return $this->getObjects($criteria, true, false);
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getDisplayed()
57
    {
58
        $criteria = new \CriteriaCompo();
59
        $criteria->add(new \Criteria('xoosocialnetwork_display', 1));
60
        $criteria->setSort('xoosocialnetwork_order');
61
        $criteria->setOrder('asc');
62
63
        return $this->getObjects($criteria, true, false);
64
    }
65
66
    /**
67
     * @return bool|mixed
68
     */
69
    public function loadConfig()
70
    {
71
        $cached_config = $this->readConfig();
72
        if (empty($cached_config)) {
73
            $cached_config = $this->createConfig();
74
        }
75
76
        return $cached_config;
77
    }
78
79
    /**
80
     * @return mixed
81
     */
82
    public function readConfig()
83
    {
84
        $path_file = $this->configPath . $this->configFile . $this->configFileExt;
85
        \XoopsLoad::load('XoopsFile');
86
        $file = \XoopsFile::getHandler('file', $path_file);
87
88
        return eval(@$file->read());
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
89
    }
90
91
    /**
92
     * @return bool
93
     */
94
    public function createConfig()
95
    {
96
        return $this->writeConfig($this->getDisplayed());
97
    }
98
99
    /**
100
     * @param $data
101
     * @return bool
102
     */
103
    public function writeConfig($data)
104
    {
105
        $path_file = $this->configPath . $this->configFile . $this->configFileExt;
106
        \XoopsLoad::load('XoopsFile');
107
        $file = \XoopsFile::getHandler('file', $path_file);
108
109
        return $file->write('return ' . var_export($data, true) . ';');
0 ignored issues
show
Bug introduced by
The method write() does not exist on XoopsFolderHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
        return $file->/** @scrutinizer ignore-call */ write('return ' . var_export($data, true) . ';');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
110
    }
111
}
112