src/php/editor.php
Function init_editor_state
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
function init_editor_state( int $post_id ) {
$meta = get_post_meta( $post_id );
if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
$state = (object) [
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
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 19 and the first side effect is on line 12. Open
Open
<?php
- Exclude checks
Expected 0 spaces between argument "$post_id" and closing bracket; 1 found Open
Open
function init_editor_state( int $post_id ) {
- Exclude checks
Expected 0 spaces between opening bracket and type hint "int"; 1 found Open
Open
function init_editor_state( int $post_id ) {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
Open
'auth_callback' => function() {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
foreach ( $legacy_meta->CSL as $id => $data ) { // phpcs:ignore
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
if ( array_key_exists( '_abt-reflist-state', $meta ) ) {
- Exclude checks
Space found before closing bracket of FOREACH loop Open
Open
foreach ( $legacy_meta->CSL as $id => $data ) { // phpcs:ignore
- Exclude checks
Space found after opening bracket of FOREACH loop Open
Open
foreach ( $legacy_meta->CSL as $id => $data ) { // phpcs:ignore
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'show_in_rest' => true,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$state = (object) [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
global $post;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$state = init_editor_state( $post->ID );
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'single' => true,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'type' => 'string',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'auth_callback' => function() {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'references' => [],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'_abt_state',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$meta = get_post_meta( $post_id );
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
},
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'post',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
wp_enqueue_script( 'abt-editor' );
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
add_json_script( 'abt-editor-state', $state );
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
wp_enqueue_style( 'abt-editor' );
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'style' => get_option( ABT_OPTIONS_KEY )['citation_style'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
register_meta(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
[
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return current_user_can( 'edit_posts' );
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
add_post_meta(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$post_id,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ( array_key_exists( '_abt-reflist-state', $meta ) ) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$state->style = $legacy_meta->cache->style;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'_abt_state',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
true
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$state = json_decode( $meta['_abt_state'][0] );
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$legacy_meta = json_decode( $meta['_abt-reflist-state'][0] );
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$state->references[] = $data;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $state;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
wp_slash( wp_json_encode( $state ) ),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach ( $legacy_meta->CSL as $id => $data ) { // phpcs:ignore
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
defined( 'ABSPATH' ) || exit;
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
$state = init_editor_state( $post->ID );
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
add_json_script( 'abt-editor-state', $state );
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
wp_enqueue_script( 'abt-editor' );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_scripts' );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
$state = init_editor_state( $post->ID );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
$meta = get_post_meta( $post_id );
- Exclude checks
Opening brace should be on a new line Open
Open
function enqueue_scripts() {
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
add_action( 'init', __NAMESPACE__ . '\register_metadata' );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
wp_enqueue_style( 'abt-editor' );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
add_json_script( 'abt-editor-state', $state );
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
$meta = get_post_meta( $post_id );
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
return current_user_can( 'edit_posts' );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
return current_user_can( 'edit_posts' );
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
wp_enqueue_style( 'abt-editor' );
- Exclude checks
Opening brace should be on a new line Open
Open
function register_metadata() {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
wp_enqueue_script( 'abt-editor' );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
add_action( 'init', __NAMESPACE__ . '\register_metadata' );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
- Exclude checks
Opening brace should be on a new line Open
Open
function init_editor_state( int $post_id ) {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
'style' => get_option( ABT_OPTIONS_KEY )['citation_style'],
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_scripts' );
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
'style' => get_option( ABT_OPTIONS_KEY )['citation_style'],
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
defined( 'ABSPATH' ) || exit;
- Exclude checks
Expected 0 spaces after opening bracket; 1 found Open
Open
if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
- Exclude checks
Expected 0 spaces after opening bracket; 1 found Open
Open
foreach ( $legacy_meta->CSL as $id => $data ) { // phpcs:ignore
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
$legacy_meta = json_decode( $meta['_abt-reflist-state'][0] );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
$state = json_decode( $meta['_abt_state'][0] );
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
wp_slash( wp_json_encode( $state ) ),
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
wp_slash( wp_json_encode( $state ) ),
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
wp_slash( wp_json_encode( $state ) ),
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
$state = json_decode( $meta['_abt_state'][0] );
- Exclude checks
Space after opening parenthesis of function call prohibited Open
Open
if ( array_key_exists( '_abt-reflist-state', $meta ) ) {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
if ( array_key_exists( '_abt-reflist-state', $meta ) ) {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
$legacy_meta = json_decode( $meta['_abt-reflist-state'][0] );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
Open
wp_slash( wp_json_encode( $state ) ),
- Exclude checks
Expected 0 spaces after opening bracket; 1 found Open
Open
if ( array_key_exists( '_abt-reflist-state', $meta ) ) {
- Exclude checks