dsifford/academic-bloggers-toolkit

View on GitHub
src/academic-bloggers-toolkit.php

Summary

Maintainability
A
1 hr
Test Coverage
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 23 and the first side effect is on line 21.
<?php
/**
* Plugin Name: Academic Blogger's Toolkit
* Plugin URI: https://github.com/dsifford/academic-bloggers-toolkit/
* Description: A plugin extending the functionality of WordPress for academic blogging
* Version: {{VERSION}}
* Author: Derek P Sifford
* Author URI: https://github.com/dsifford
* License: GPL3 or later.
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: academic-bloggers-toolkit
* Domain Path: /languages
*
* @package ABT
*/
 
declare(strict_types=1);
 
namespace ABT;
 
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
defined( 'ABSPATH' ) || exit;
 
define(
Spaces must be used to indent lines; tabs are not allowed
'ABT_ACTIONS',
Spaces must be used to indent lines; tabs are not allowed
[
Spaces must be used to indent lines; tabs are not allowed
'SET_CITATION_STYLE' => 'abt-form-set-citation-style',
Spaces must be used to indent lines; tabs are not allowed
]
);
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
define( 'ABT_NONCE', 'abt_nonce' );
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
define( 'ABT_OPTIONS_KEY', 'abt_options' );
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
define( 'ABT_ROOT_PATH', __DIR__ );
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
define( 'ABT_ROOT_URI', plugins_url( '', __FILE__ ) );
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
define( 'ABT_VERSION', '{{VERSION}}' );
 
use function ABT\Utils\register_script;
 
/**
* Load plugin translations.
*/
Opening brace should be on a new line
function plugin_textdomain() {
Spaces must be used to indent lines; tabs are not allowed
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
load_plugin_textdomain( 'academic-bloggers-toolkit', false, basename( ABT_ROOT_PATH ) . '/languages' );
}
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_textdomain' );
 
/**
* Cleans up options during uninstall.
*/
Opening brace should be on a new line
function uninstall() {
Spaces must be used to indent lines; tabs are not allowed
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
delete_option( ABT_OPTIONS_KEY );
}
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
register_uninstall_hook( __FILE__, __NAMESPACE__ . '\uninstall' );
 
/**
* Refactors the defined plugin options.
*
* @link https://app.quicktype.io?share=E2qRt1Cg3TR6qmHbXDcY
*/
Opening brace should be on a new line
function refactor_options() {
Spaces must be used to indent lines; tabs are not allowed
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
$options = get_option( ABT_OPTIONS_KEY );
Expected 0 spaces before closing bracket; 1 found
Spaces must be used to indent lines; tabs are not allowed
Expected 0 spaces after opening bracket; 1 found
Space after opening parenthesis of function call prohibited
if ( version_compare( ABT_VERSION, $options['VERSION'] ?? '0', '>' ) ) {
Spaces must be used to indent lines; tabs are not allowed
$new_options = [
Spaces must be used to indent lines; tabs are not allowed
'VERSION' => ABT_VERSION,
Spaces must be used to indent lines; tabs are not allowed
'citation_style' => [
Spaces must be used to indent lines; tabs are not allowed
'kind' => $options['citation_style']['kind'] ?? 'predefined',
Spaces must be used to indent lines; tabs are not allowed
'label' => $options['citation_style']['label'] ?? 'American Medical Association',
Spaces must be used to indent lines; tabs are not allowed
'value' => $options['citation_style']['value'] ?? 'american-medical-association',
Spaces must be used to indent lines; tabs are not allowed
],
Spaces must be used to indent lines; tabs are not allowed
];
Spaces must be used to indent lines; tabs are not allowed
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
update_option( ABT_OPTIONS_KEY, $new_options );
Spaces must be used to indent lines; tabs are not allowed
}
}
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
add_action( 'admin_init', __NAMESPACE__ . '\refactor_options' );
 
/**
* Adds link on the plugin page to the options page.
*
* @param string[] $links array of links.
*/
Expected 0 spaces between opening bracket and type hint "array"; 1 found
Expected 0 spaces between argument "$links" and closing bracket; 1 found
Opening brace should be on a new line
function add_options_link( array $links ): array {
Spaces must be used to indent lines; tabs are not allowed
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
$url = admin_url( 'options-general.php?page=abt-options' );
Spaces must be used to indent lines; tabs are not allowed
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
$text = __( 'Plugin Settings', 'academic-bloggers-toolkit' );
Spaces must be used to indent lines; tabs are not allowed
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
return array_merge( $links, [ "<a href='$url'>$text</a>" ] );
}
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), __NAMESPACE__ . '\add_options_link' );
 
/**
* Adds donation link to the plugin meta.
*
* @param mixed[] $links The array having default links for the plugin.
* @param string $file The name of the plugin file.
*/
Expected 0 spaces between opening bracket and type hint "array"; 1 found
Expected 0 spaces between argument "$file" and closing bracket; 1 found
Opening brace should be on a new line
function add_donate_link( array $links, string $file ): array {
Expected 0 spaces before closing bracket; 1 found
Spaces must be used to indent lines; tabs are not allowed
Space after opening parenthesis of function call prohibited
Expected 0 spaces after opening bracket; 1 found
if ( plugin_basename( __FILE__ ) === $file ) {
Spaces must be used to indent lines; tabs are not allowed
$links[] = sprintf(
Spaces must be used to indent lines; tabs are not allowed
'&hearts; <a href="%s">%s</a>',
Spaces must be used to indent lines; tabs are not allowed
'https://donorbox.org/academic-bloggers-toolkit',
Spaces must be used to indent lines; tabs are not allowed
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
__( 'Donate', 'academic-bloggers-toolkit' )
Spaces must be used to indent lines; tabs are not allowed
);
Spaces must be used to indent lines; tabs are not allowed
}
Spaces must be used to indent lines; tabs are not allowed
return $links;
}
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
add_filter( 'plugin_row_meta', __NAMESPACE__ . '\add_donate_link', 10, 2 );
 
/**
* Registers all scripts/styles used by this plugin.
*/
Method `register_scripts` has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Opening brace should be on a new line
function register_scripts() {
Spaces must be used to indent lines; tabs are not allowed
//
Spaces must be used to indent lines; tabs are not allowed
// Editor.
Spaces must be used to indent lines; tabs are not allowed
//
Spaces must be used to indent lines; tabs are not allowed
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
register_script( 'editor-stores' );
Spaces must be used to indent lines; tabs are not allowed
register_script(
Spaces must be used to indent lines; tabs are not allowed
'editor-blocks',
Spaces must be used to indent lines; tabs are not allowed
[
Spaces must be used to indent lines; tabs are not allowed
'abt-editor-stores',
Spaces must be used to indent lines; tabs are not allowed
]
Spaces must be used to indent lines; tabs are not allowed
);
Spaces must be used to indent lines; tabs are not allowed
register_script(
Spaces must be used to indent lines; tabs are not allowed
'editor-formats',
Spaces must be used to indent lines; tabs are not allowed
[
Spaces must be used to indent lines; tabs are not allowed
'abt-editor-stores',
Spaces must be used to indent lines; tabs are not allowed
]
Spaces must be used to indent lines; tabs are not allowed
);
Spaces must be used to indent lines; tabs are not allowed
register_script(
Spaces must be used to indent lines; tabs are not allowed
'editor',
Spaces must be used to indent lines; tabs are not allowed
[
Spaces must be used to indent lines; tabs are not allowed
'abt-editor-blocks',
Spaces must be used to indent lines; tabs are not allowed
'abt-editor-formats',
Spaces must be used to indent lines; tabs are not allowed
'abt-editor-stores',
Spaces must be used to indent lines; tabs are not allowed
]
Spaces must be used to indent lines; tabs are not allowed
);
 
Spaces must be used to indent lines; tabs are not allowed
//
Spaces must be used to indent lines; tabs are not allowed
// Options Page.
Spaces must be used to indent lines; tabs are not allowed
//
Spaces must be used to indent lines; tabs are not allowed
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
register_script( 'options-page' );
 
Spaces must be used to indent lines; tabs are not allowed
//
Spaces must be used to indent lines; tabs are not allowed
// Frontend.
Spaces must be used to indent lines; tabs are not allowed
//
Spaces must be used to indent lines; tabs are not allowed
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
register_script( 'frontend' );
 
Spaces must be used to indent lines; tabs are not allowed
//
Spaces must be used to indent lines; tabs are not allowed
// Vendor.
Spaces must be used to indent lines; tabs are not allowed
//
Spaces must be used to indent lines; tabs are not allowed
wp_register_script(
Spaces must be used to indent lines; tabs are not allowed
'citeproc',
Spaces must be used to indent lines; tabs are not allowed
ABT_ROOT_URI . '/vendor/citeproc.js',
Spaces must be used to indent lines; tabs are not allowed
[],
Spaces must be used to indent lines; tabs are not allowed
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
filemtime( ABT_ROOT_PATH . '/vendor/citeproc.js' ),
Spaces must be used to indent lines; tabs are not allowed
true
Spaces must be used to indent lines; tabs are not allowed
);
 
Spaces must be used to indent lines; tabs are not allowed
//
Spaces must be used to indent lines; tabs are not allowed
// Third party.
Spaces must be used to indent lines; tabs are not allowed
//
Spaces must be used to indent lines; tabs are not allowed
wp_register_script(
Spaces must be used to indent lines; tabs are not allowed
'codepen',
Spaces must be used to indent lines; tabs are not allowed
'//assets.codepen.io/assets/embed/ei.js',
Spaces must be used to indent lines; tabs are not allowed
[],
Spaces must be used to indent lines; tabs are not allowed
ABT_VERSION,
Spaces must be used to indent lines; tabs are not allowed
true
Spaces must be used to indent lines; tabs are not allowed
);
}
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
add_action( 'wp_loaded', __NAMESPACE__ . '\register_scripts' );
 
/**
* Adds an ajax nonce to pages that require it.
*/
Opening brace should be on a new line
function ajax_nonce() {
Spaces must be used to indent lines; tabs are not allowed
?>
Spaces must be used to indent lines; tabs are not allowed
<script type="text/javascript">
Spaces must be used to indent lines; tabs are not allowed
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
window._abt_nonce = '<?php echo esc_html( wp_create_nonce( 'abt-ajax' ) ); ?>'
Spaces must be used to indent lines; tabs are not allowed
</script>
Spaces must be used to indent lines; tabs are not allowed
<?php
}
Expected 0 spaces before closing bracket; 1 found
Space after opening parenthesis of function call prohibited
add_action( 'admin_head-post-new.php', __NAMESPACE__ . '\ajax_nonce' );
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
add_action( 'admin_head-post.php', __NAMESPACE__ . '\ajax_nonce' );
Space after opening parenthesis of function call prohibited
Expected 0 spaces before closing bracket; 1 found
add_action( 'admin_head-settings_page_abt-options', __NAMESPACE__ . '\ajax_nonce' );
 
require_once __DIR__ . '/php/utils.php';
require_once __DIR__ . '/php/endpoints.php';
 
Expected 0 spaces before closing bracket; 1 found
Expected 0 spaces after opening bracket; 1 found
if ( is_admin() ) {
Spaces must be used to indent lines; tabs are not allowed
require_once __DIR__ . '/php/editor.php';
Spaces must be used to indent lines; tabs are not allowed
require_once __DIR__ . '/php/options.php';
} else {
Spaces must be used to indent lines; tabs are not allowed
require_once __DIR__ . '/php/frontend.php';
}