Skip to content

Commit 2bdee75

Browse files
committed
Remove PHP 7.2 deprecated function & Be SonarQube compliant
1 parent df65aef commit 2bdee75

File tree

14 files changed

+156
-159
lines changed

14 files changed

+156
-159
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
vendor/
99
composer.lock
1010

11+
# Scanner
12+
.scannerwork
13+
1114
# Useless auto-generated files
1215
.DS_Store
1316
.idea/

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.1 (May 5th, 2019)
2+
Remove PHP 7.2 deprecated `create_function` function
3+
Be SonarQube compliant
4+
15
## 1.0.0 (November 25th, 2018)
26
Fix helpers and make WordPress website faster
37

sonar-project.properties

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
##############################################
66

77
# Defaults
8+
sonar.host.url=https://sonarcloud.io
9+
sonar.login=cf1b9e6571847d3474a62fb33c3c8223797dbe7e
10+
sonar.organization=getolympus
811
sonar.projectKey=GetOlympus_Zeus-Core
912
sonar.projectName=Olympus Zeus framework core system used to make all your WordPress plugins and themes developments easier and efficient
10-
sonar.projectVersion=1.0.0
1113

1214
# Metadatas
1315
sonar.links.homepage=https://github.com/GetOlympus/Zeus-Core
@@ -17,6 +19,3 @@ sonar.links.issue=https://github.com/GetOlympus/Zeus-Core/issues
1719
# Standard properties
1820
sonar.sources=src/Zeus
1921
sonar.tests=tests
20-
21-
# Language specific properties
22-
sonar.php.tests.reportPath=phpunit.xml

src/Zeus/AdminPage/Controller/AdminPageHook.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,20 @@ public function renderFields()
111111
$this->saveFields();
112112

113113
// Get contents
114-
$currentPage = $this->currentPage;
115-
$currentSection = $this->currentSection;
116-
$fields = $this->fields;
117-
$options = $this->options;
114+
$pageCurrent = $this->currentPage;
115+
$sectionCurrent = $this->currentSection;
116+
$formFields = $this->fields;
117+
$contentOptions = $this->options;
118118

119119
// Get links
120-
$u_link = 'page='.$currentPage;
121-
$u_section = !empty($currentSection) ? '&section='.$currentSection : '';
120+
$u_link = 'page='.$pageCurrent;
121+
$u_section = !empty($sectionCurrent) ? '&section='.$sectionCurrent : '';
122122

123123
// Work on vars
124124
$vars = [
125-
'title' => $options['title'],
126-
'description' => $options['description'],
127-
'submit' => $options['submit'],
125+
'title' => $contentOptions['title'],
126+
'description' => $contentOptions['description'],
127+
'submit' => $contentOptions['submit'],
128128

129129
// Texts and URLs
130130
't_submit' => Translate::t('adminpage.submit'),
@@ -133,16 +133,16 @@ public function renderFields()
133133
];
134134

135135
// Display sections
136-
if (!empty($options['sections']) && is_array($options['sections'])) {
137-
foreach ($options['sections'] as $slug => $opts) {
136+
if (!empty($contentOptions['sections']) && is_array($contentOptions['sections'])) {
137+
foreach ($contentOptions['sections'] as $slug => $opts) {
138138
// Update option
139139
$opts['slug'] = $slug;
140140
$opts['u_link'] = admin_url('admin.php?'.$u_link.'&section='.$slug);
141141

142142
// Update vars
143143
$vars['sections'][] = $opts;
144144

145-
if ($slug !== $currentSection) {
145+
if ($slug !== $sectionCurrent) {
146146
continue;
147147
}
148148

@@ -152,12 +152,12 @@ public function renderFields()
152152
}
153153

154154
// Work on current vars
155-
$vars['c_page'] = $currentPage;
156-
$vars['c_section'] = $currentSection;
155+
$vars['c_page'] = $pageCurrent;
156+
$vars['c_section'] = $sectionCurrent;
157157

158158
// Display fields
159-
if (!empty($fields)) {
160-
foreach ($fields as $field) {
159+
if (!empty($formFields)) {
160+
foreach ($formFields as $field) {
161161
if (!$field) {
162162
continue;
163163
}

src/Zeus/AdminPage/Model/AdminPageModel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ public function hasPage($identifier)
111111
* Sets the value of page.
112112
*
113113
* @param string $identifier the identifier
114-
* @param array $options the options
114+
* @param array $configs the options configuration
115115
*
116116
* @return self
117117
*/
118-
public function updatePage($identifier, $options)
118+
public function updatePage($identifier, $configs)
119119
{
120-
$this->pages[$identifier] = $options;
120+
$this->pages[$identifier] = $configs;
121121

122122
return $this;
123123
}

src/Zeus/Application/Controller/Application.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ public function getComponents()
168168
'Widget' => 'GetOlympus\Zeus\Widget\Controller\Widget',
169169
];
170170

171-
// Iterate on externals to add "Field" suffix
171+
// Iterate on externals
172172
foreach ($this->externals as $shortname => $classname) {
173-
$components[$shortname.'Field'] = $classname;
173+
$components[$shortname] = $classname;
174174
}
175175

176176
return $components;
@@ -262,17 +262,17 @@ public function registerComponents()
262262
}
263263

264264
// Work on file paths
265-
foreach ($this->paths as $action => $paths) {
265+
foreach ($this->paths as $action => $actionPaths) {
266266
// Work on paths
267-
$paths = !is_array($paths) ? [$paths] : $paths;
267+
$actionPaths = !is_array($actionPaths) ? [$actionPaths] : $actionPaths;
268268

269269
// Work on file name
270270
$filepath = OL_ZEUS_CACHE.$this->classname.'-'.$action.'-components.php';
271271

272272
// Check cache file
273273
if (!file_exists($filepath)) {
274274
// Store all in cache file
275-
ClassMapGenerator::dump($paths, $filepath);
275+
ClassMapGenerator::dump($actionPaths, $filepath);
276276
}
277277

278278
$classmap = include_once $filepath;

src/Zeus/Configuration/Controller/AccessManagement.php

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace GetOlympus\Zeus\Configuration\Controller;
44

55
use GetOlympus\Zeus\Configuration\Controller\Configuration;
6-
use GetOlympus\Zeus\Helpers\Controller\Helpers;
76

87
/**
98
* Access Management controller
@@ -17,42 +16,27 @@
1716

1817
class AccessManagement extends Configuration
1918
{
20-
/**
21-
* @var array
22-
*/
23-
protected $available = [
24-
'access-url',
25-
'login-error',
26-
'login-header',
27-
'login-shake',
28-
'login-style',
29-
];
30-
3119
/**
3220
* Add all usefull WP filters and hooks.
3321
*/
3422
public function init()
3523
{
36-
// Check filepath
37-
if (empty($this->filepath)) {
24+
// Initialize filepath with configs
25+
$funcs = $this->getFunctions('AccessManagement', [
26+
'access-url',
27+
'login-error',
28+
'login-header',
29+
'login-shake',
30+
'login-style',
31+
]);
32+
33+
// Check functions
34+
if (empty($funcs)) {
3835
return;
3936
}
4037

41-
// Get configurations
42-
$configs = include $this->filepath;
43-
44-
// Check
45-
if (empty($configs)) {
46-
return;
47-
}
48-
49-
// Iterate on configs
50-
foreach ($configs as $key => $args) {
51-
if (!in_array($key, $this->available) || empty($args)) {
52-
continue;
53-
}
54-
55-
$func = Helpers::toFunctionFormat($key).'Setting';
38+
// Iterate on functions
39+
foreach ($funcs as $key => $args) {
5640
$this->$func($args);
5741
}
5842
}
@@ -62,24 +46,24 @@ public function init()
6246
*
6347
* @param string $slug
6448
*/
65-
public function accessUrlSetting($slug)
49+
public function accessUrlAccessManagement($slug)
6650
{
6751
if (empty($slug) || 'wp-login.php' === $slug) {
6852
return;
6953
}
7054

7155
// Change login URL
72-
add_filter('login_redirect', function ($url) use ($slug) {
56+
add_filter('login_redirect', function () use ($slug) {
7357
return site_url().$slug;
7458
});
7559

7660
// Customize Site URL
77-
add_filter('site_url', function ($url, $path, $scheme = null) use ($slug) {
61+
add_filter('site_url', function ($url) use ($slug) {
7862
return str_replace('wp-login.php', $slug, $url);
7963
}, 10, 3);
8064

8165
// Make the redirection works properly
82-
add_filter('wp_redirect', function ($url, $status) use ($slug) {
66+
add_filter('wp_redirect', function ($url) use ($slug) {
8367
return str_replace('wp-login.php', $slug, $url);
8468
}, 10, 2);
8569
}
@@ -89,10 +73,10 @@ public function accessUrlSetting($slug)
8973
*
9074
* @param string|boolean $error
9175
*/
92-
public function loginErrorSetting($error)
76+
public function loginErrorAccessManagement($error)
9377
{
9478
// Define default message
95-
$message = is_bool($error) && $error ? Translate::t('configuration.settings.login.error') : $error;
79+
$message = is_bool($error) && $error ? Translate::t('configuration.accessmanagement.login.error') : $error;
9680

9781
// Change login error message
9882
add_filter('login_errors', function () use ($message) {
@@ -107,7 +91,7 @@ public function loginErrorSetting($error)
10791
*
10892
* @param array $args
10993
*/
110-
public function loginHeaderSetting($args)
94+
public function loginHeaderAccessManagement($args)
11195
{
11296
if (!$args) {
11397
return;
@@ -120,14 +104,14 @@ public function loginHeaderSetting($args)
120104
], $args);
121105

122106
// Change login head URL
123-
add_filter('login_headerurl', function ($url) use ($configs) {
107+
add_filter('login_headerurl', function () use ($configs) {
124108
if (!empty($configs['url'])) {
125109
return $configs['url'];
126110
}
127111
});
128112

129113
// Change login head title
130-
add_filter('login_headertitle', function ($title) use ($configs) {
114+
add_filter('login_headertitle', function () use ($configs) {
131115
if (!empty($configs['title'])) {
132116
return $configs['title'];
133117
}
@@ -139,7 +123,7 @@ public function loginHeaderSetting($args)
139123
*
140124
* @param boolean $shake
141125
*/
142-
public function loginShakeSetting($shake)
126+
public function loginShakeAccessManagement($shake)
143127
{
144128
if ($shake) {
145129
return;
@@ -155,7 +139,7 @@ public function loginShakeSetting($shake)
155139
*
156140
* @param array $args
157141
*/
158-
public function loginStyleSetting($args)
142+
public function loginStyleAccessManagement($args)
159143
{
160144
if (!$args) {
161145
return;

src/Zeus/Configuration/Controller/Clean.php

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace GetOlympus\Zeus\Configuration\Controller;
44

55
use GetOlympus\Zeus\Configuration\Controller\Configuration;
6-
use GetOlympus\Zeus\Helpers\Controller\Helpers;
76
use GetOlympus\Zeus\Helpers\Controller\HelpersCleanCore;
87
use GetOlympus\Zeus\Helpers\Controller\HelpersCleanFeatures;
98
use GetOlympus\Zeus\Helpers\Controller\HelpersCleanHeaders;
@@ -23,42 +22,27 @@
2322

2423
class Clean extends Configuration
2524
{
26-
/**
27-
* @var array
28-
*/
29-
protected $available = [
30-
'core',
31-
'features',
32-
'headers',
33-
'plugins',
34-
];
35-
3625
/**
3726
* Add all usefull WP filters and hooks.
3827
*/
3928
public function init()
4029
{
41-
// Check filepath
42-
if (empty($this->filepath)) {
43-
return;
44-
}
45-
46-
// Get configurations
47-
$configs = include $this->filepath;
48-
49-
// Check
50-
if (empty($configs)) {
30+
// Initialize filepath with configs
31+
$funcs = $this->getFunctions('Clean', [
32+
'core',
33+
'features',
34+
'headers',
35+
'plugins',
36+
]);
37+
38+
// Check functions
39+
if (empty($funcs)) {
5140
return;
5241
}
5342

54-
// Iterate on configs
55-
foreach ($configs as $key => $args) {
56-
if (!in_array($key, $this->available) || empty($args)) {
57-
continue;
58-
}
59-
60-
$func = Helpers::toFunctionFormat($key).'Clean';
61-
$this->$func($args);
43+
// Iterate on functions
44+
foreach ($funcs as $key => $args) {
45+
$this->$key($args);
6246
}
6347
}
6448

0 commit comments

Comments
 (0)