Skip to content

Commit

Permalink
Remove PHP 7.2 deprecated function & Be SonarQube compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
crewstyle committed May 5, 2019
1 parent df65aef commit 2bdee75
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 159 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
vendor/
composer.lock

# Scanner
.scannerwork

# Useless auto-generated files
.DS_Store
.idea/
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.1 (May 5th, 2019)
Remove PHP 7.2 deprecated `create_function` function
Be SonarQube compliant

## 1.0.0 (November 25th, 2018)
Fix helpers and make WordPress website faster

Expand Down
7 changes: 3 additions & 4 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
##############################################

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

# Metadatas
sonar.links.homepage=https://github.com/GetOlympus/Zeus-Core
Expand All @@ -17,6 +19,3 @@ sonar.links.issue=https://github.com/GetOlympus/Zeus-Core/issues
# Standard properties
sonar.sources=src/Zeus
sonar.tests=tests

# Language specific properties
sonar.php.tests.reportPath=phpunit.xml
32 changes: 16 additions & 16 deletions src/Zeus/AdminPage/Controller/AdminPageHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ public function renderFields()
$this->saveFields();

// Get contents
$currentPage = $this->currentPage;
$currentSection = $this->currentSection;
$fields = $this->fields;
$options = $this->options;
$pageCurrent = $this->currentPage;
$sectionCurrent = $this->currentSection;
$formFields = $this->fields;
$contentOptions = $this->options;

// Get links
$u_link = 'page='.$currentPage;
$u_section = !empty($currentSection) ? '&section='.$currentSection : '';
$u_link = 'page='.$pageCurrent;
$u_section = !empty($sectionCurrent) ? '&section='.$sectionCurrent : '';

// Work on vars
$vars = [
'title' => $options['title'],
'description' => $options['description'],
'submit' => $options['submit'],
'title' => $contentOptions['title'],
'description' => $contentOptions['description'],
'submit' => $contentOptions['submit'],

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

// Display sections
if (!empty($options['sections']) && is_array($options['sections'])) {
foreach ($options['sections'] as $slug => $opts) {
if (!empty($contentOptions['sections']) && is_array($contentOptions['sections'])) {
foreach ($contentOptions['sections'] as $slug => $opts) {
// Update option
$opts['slug'] = $slug;
$opts['u_link'] = admin_url('admin.php?'.$u_link.'&section='.$slug);

// Update vars
$vars['sections'][] = $opts;

if ($slug !== $currentSection) {
if ($slug !== $sectionCurrent) {
continue;
}

Expand All @@ -152,12 +152,12 @@ public function renderFields()
}

// Work on current vars
$vars['c_page'] = $currentPage;
$vars['c_section'] = $currentSection;
$vars['c_page'] = $pageCurrent;
$vars['c_section'] = $sectionCurrent;

// Display fields
if (!empty($fields)) {
foreach ($fields as $field) {
if (!empty($formFields)) {
foreach ($formFields as $field) {
if (!$field) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Zeus/AdminPage/Model/AdminPageModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public function hasPage($identifier)
* Sets the value of page.
*
* @param string $identifier the identifier
* @param array $options the options
* @param array $configs the options configuration
*
* @return self
*/
public function updatePage($identifier, $options)
public function updatePage($identifier, $configs)
{
$this->pages[$identifier] = $options;
$this->pages[$identifier] = $configs;

return $this;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Zeus/Application/Controller/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ public function getComponents()
'Widget' => 'GetOlympus\Zeus\Widget\Controller\Widget',
];

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

return $components;
Expand Down Expand Up @@ -262,17 +262,17 @@ public function registerComponents()
}

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

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

// Check cache file
if (!file_exists($filepath)) {
// Store all in cache file
ClassMapGenerator::dump($paths, $filepath);
ClassMapGenerator::dump($actionPaths, $filepath);
}

$classmap = include_once $filepath;
Expand Down
64 changes: 24 additions & 40 deletions src/Zeus/Configuration/Controller/AccessManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace GetOlympus\Zeus\Configuration\Controller;

use GetOlympus\Zeus\Configuration\Controller\Configuration;
use GetOlympus\Zeus\Helpers\Controller\Helpers;

/**
* Access Management controller
Expand All @@ -17,42 +16,27 @@

class AccessManagement extends Configuration
{
/**
* @var array
*/
protected $available = [
'access-url',
'login-error',
'login-header',
'login-shake',
'login-style',
];

/**
* Add all usefull WP filters and hooks.
*/
public function init()
{
// Check filepath
if (empty($this->filepath)) {
// Initialize filepath with configs
$funcs = $this->getFunctions('AccessManagement', [
'access-url',
'login-error',
'login-header',
'login-shake',
'login-style',
]);

// Check functions
if (empty($funcs)) {
return;
}

// Get configurations
$configs = include $this->filepath;

// Check
if (empty($configs)) {
return;
}

// Iterate on configs
foreach ($configs as $key => $args) {
if (!in_array($key, $this->available) || empty($args)) {
continue;
}

$func = Helpers::toFunctionFormat($key).'Setting';
// Iterate on functions
foreach ($funcs as $key => $args) {
$this->$func($args);
}
}
Expand All @@ -62,24 +46,24 @@ public function init()
*
* @param string $slug
*/
public function accessUrlSetting($slug)
public function accessUrlAccessManagement($slug)
{
if (empty($slug) || 'wp-login.php' === $slug) {
return;
}

// Change login URL
add_filter('login_redirect', function ($url) use ($slug) {
add_filter('login_redirect', function () use ($slug) {
return site_url().$slug;
});

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

// Make the redirection works properly
add_filter('wp_redirect', function ($url, $status) use ($slug) {
add_filter('wp_redirect', function ($url) use ($slug) {
return str_replace('wp-login.php', $slug, $url);
}, 10, 2);
}
Expand All @@ -89,10 +73,10 @@ public function accessUrlSetting($slug)
*
* @param string|boolean $error
*/
public function loginErrorSetting($error)
public function loginErrorAccessManagement($error)
{
// Define default message
$message = is_bool($error) && $error ? Translate::t('configuration.settings.login.error') : $error;
$message = is_bool($error) && $error ? Translate::t('configuration.accessmanagement.login.error') : $error;

// Change login error message
add_filter('login_errors', function () use ($message) {
Expand All @@ -107,7 +91,7 @@ public function loginErrorSetting($error)
*
* @param array $args
*/
public function loginHeaderSetting($args)
public function loginHeaderAccessManagement($args)
{
if (!$args) {
return;
Expand All @@ -120,14 +104,14 @@ public function loginHeaderSetting($args)
], $args);

// Change login head URL
add_filter('login_headerurl', function ($url) use ($configs) {
add_filter('login_headerurl', function () use ($configs) {
if (!empty($configs['url'])) {
return $configs['url'];
}
});

// Change login head title
add_filter('login_headertitle', function ($title) use ($configs) {
add_filter('login_headertitle', function () use ($configs) {
if (!empty($configs['title'])) {
return $configs['title'];
}
Expand All @@ -139,7 +123,7 @@ public function loginHeaderSetting($args)
*
* @param boolean $shake
*/
public function loginShakeSetting($shake)
public function loginShakeAccessManagement($shake)
{
if ($shake) {
return;
Expand All @@ -155,7 +139,7 @@ public function loginShakeSetting($shake)
*
* @param array $args
*/
public function loginStyleSetting($args)
public function loginStyleAccessManagement($args)
{
if (!$args) {
return;
Expand Down
42 changes: 13 additions & 29 deletions src/Zeus/Configuration/Controller/Clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace GetOlympus\Zeus\Configuration\Controller;

use GetOlympus\Zeus\Configuration\Controller\Configuration;
use GetOlympus\Zeus\Helpers\Controller\Helpers;
use GetOlympus\Zeus\Helpers\Controller\HelpersCleanCore;
use GetOlympus\Zeus\Helpers\Controller\HelpersCleanFeatures;
use GetOlympus\Zeus\Helpers\Controller\HelpersCleanHeaders;
Expand All @@ -23,42 +22,27 @@

class Clean extends Configuration
{
/**
* @var array
*/
protected $available = [
'core',
'features',
'headers',
'plugins',
];

/**
* Add all usefull WP filters and hooks.
*/
public function init()
{
// Check filepath
if (empty($this->filepath)) {
return;
}

// Get configurations
$configs = include $this->filepath;

// Check
if (empty($configs)) {
// Initialize filepath with configs
$funcs = $this->getFunctions('Clean', [
'core',
'features',
'headers',
'plugins',
]);

// Check functions
if (empty($funcs)) {
return;
}

// Iterate on configs
foreach ($configs as $key => $args) {
if (!in_array($key, $this->available) || empty($args)) {
continue;
}

$func = Helpers::toFunctionFormat($key).'Clean';
$this->$func($args);
// Iterate on functions
foreach ($funcs as $key => $args) {
$this->$key($args);
}
}

Expand Down
Loading

0 comments on commit 2bdee75

Please sign in to comment.