dsifford/academic-bloggers-toolkit

View on GitHub
src/php/editor.php

Summary

Maintainability
A
45 mins
Test Coverage

Function init_editor_state has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
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) [
Severity: Minor
Found in src/php/editor.php - About 45 mins to fix

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

<?php
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces between argument "$post_id" and closing bracket; 1 found
Open

function init_editor_state( int $post_id ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces between opening bracket and type hint "int"; 1 found
Open

function init_editor_state( int $post_id ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 1 space after FUNCTION keyword; 0 found
Open

            'auth_callback' => function() {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

            foreach ( $legacy_meta->CSL as $id => $data ) { // phpcs:ignore
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

        if ( array_key_exists( '_abt-reflist-state', $meta ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space found before closing bracket of FOREACH loop
Open

            foreach ( $legacy_meta->CSL as $id => $data ) { // phpcs:ignore
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space found after opening bracket of FOREACH loop
Open

            foreach ( $legacy_meta->CSL as $id => $data ) { // phpcs:ignore
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            'show_in_rest'  => true,
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        $state = (object) [
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    global $post;
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    $state = init_editor_state( $post->ID );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            'single'        => true,
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            'type'          => 'string',
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            'auth_callback' => function() {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            'references' => [],
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        '_abt_state',
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    $meta = get_post_meta( $post_id );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            },
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        'post',
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    wp_enqueue_script( 'abt-editor' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    add_json_script( 'abt-editor-state', $state );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            }
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    wp_enqueue_style( 'abt-editor' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            'style'      => get_option( ABT_OPTIONS_KEY )['citation_style'],
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    register_meta(
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        [
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                return current_user_can( 'edit_posts' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        ]
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        ];
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    } else {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        add_post_meta(
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            $post_id,
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        if ( array_key_exists( '_abt-reflist-state', $meta ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            $state->style = $legacy_meta->cache->style;
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            '_abt_state',
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            true
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        $state = json_decode( $meta['_abt_state'][0] );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            $legacy_meta = json_decode( $meta['_abt-reflist-state'][0] );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                $state->references[] = $data;
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    return $state;
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        }
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            wp_slash( wp_json_encode( $state ) ),
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            foreach ( $legacy_meta->CSL as $id => $data ) { // phpcs:ignore
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    }
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

defined( 'ABSPATH' ) || exit;
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    $state = init_editor_state( $post->ID );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    add_json_script( 'abt-editor-state', $state );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    wp_enqueue_script( 'abt-editor' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_scripts' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    $state = init_editor_state( $post->ID );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    $meta = get_post_meta( $post_id );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Opening brace should be on a new line
Open

function enqueue_scripts() {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

add_action( 'init', __NAMESPACE__ . '\register_metadata' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    wp_enqueue_style( 'abt-editor' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    add_json_script( 'abt-editor-state', $state );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    $meta = get_post_meta( $post_id );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

                return current_user_can( 'edit_posts' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

                return current_user_can( 'edit_posts' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    wp_enqueue_style( 'abt-editor' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Opening brace should be on a new line
Open

function register_metadata() {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    wp_enqueue_script( 'abt-editor' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

add_action( 'init', __NAMESPACE__ . '\register_metadata' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Opening brace should be on a new line
Open

function init_editor_state( int $post_id ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

            'style'      => get_option( ABT_OPTIONS_KEY )['citation_style'],
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_scripts' );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

            'style'      => get_option( ABT_OPTIONS_KEY )['citation_style'],
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

defined( 'ABSPATH' ) || exit;
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces after opening bracket; 1 found
Open

    if ( ! array_key_exists( '_abt_state', $meta ) || ! has_blocks( $post_id ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces after opening bracket; 1 found
Open

            foreach ( $legacy_meta->CSL as $id => $data ) { // phpcs:ignore
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

            $legacy_meta = json_decode( $meta['_abt-reflist-state'][0] );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

        $state = json_decode( $meta['_abt_state'][0] );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

            wp_slash( wp_json_encode( $state ) ),
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

            wp_slash( wp_json_encode( $state ) ),
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

            wp_slash( wp_json_encode( $state ) ),
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

        $state = json_decode( $meta['_abt_state'][0] );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

        if ( array_key_exists( '_abt-reflist-state', $meta ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

        if ( array_key_exists( '_abt-reflist-state', $meta ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

            $legacy_meta = json_decode( $meta['_abt-reflist-state'][0] );
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

            wp_slash( wp_json_encode( $state ) ),
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

Expected 0 spaces after opening bracket; 1 found
Open

        if ( array_key_exists( '_abt-reflist-state', $meta ) ) {
Severity: Minor
Found in src/php/editor.php by phpcodesniffer

There are no issues that match your filters.

Category
Status