dsifford/academic-bloggers-toolkit

View on GitHub
src/php/frontend.php

Summary

Maintainability
A
1 hr
Test Coverage

Method inject_author_meta has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function inject_author_meta() {
    global $post;
    if ( ! $post || ! is_singular() ) {
        return;
    }
Severity: Minor
Found in src/php/frontend.php - About 1 hr to fix

    Function inject_author_meta has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    function inject_author_meta() {
        global $post;
        if ( ! $post || ! is_singular() ) {
            return;
        }
    Severity: Minor
    Found in src/php/frontend.php - About 35 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 21 and the first side effect is on line 12.
    Open

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

    Expected 1 space after FUNCTION keyword; 0 found
    Open

                function( $coauthor ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

    function collect_bibliography( WP_Post $post ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces between opening bracket and argument "$coauthor"; 1 found
    Open

                function( $coauthor ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space found before closing bracket of FOREACH loop
    Open

        foreach ( $authors as $author ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            if ( is_int( $bib_index ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

    function collect_bibliography( WP_Post $post ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( is_singular() && has_block( 'abt/bibliography', $post ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( ! $post || ! is_singular() ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

                function( $coauthor ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( is_singular() ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        foreach ( $authors as $author ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space found after opening bracket of FOREACH loop
    Open

        foreach ( $authors as $author ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            if ( $author->first_name && $author->last_name ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( function_exists( 'get_coauthors' ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

        $authors = get_users(
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

                    <meta property="abt:author" content="<?php echo esc_attr( $parsed ); ?>" />
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

            if ( is_int( $bib_index ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

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

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

                $parsed = $author->first_name . '|' . $author->last_name;
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

                ?>
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

            $coauthor_ids = array_map(
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

            $bib_index = array_search( 'abt/bibliography', array_column( $blocks, 'blockName' ), true );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

                get_coauthors( $post->ID )
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

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

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

                function( $coauthor ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

                    return $coauthor->ID;
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

            $blocks    = parse_blocks( $post->post_content );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

                add_json_script( 'abt-bibliography-json', $blocks[ $bib_index ]['innerHTML'] );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

        if ( ! $post || ! is_singular() ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

            if ( $author->first_name && $author->last_name ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

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

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

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

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

        foreach ( $authors as $author ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

        $author_ids = [ $post->post_author ];
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

                'include' => $author_ids,
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

        if ( is_singular() ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

        if ( function_exists( 'get_coauthors' ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

        if ( is_singular() && has_block( 'abt/bibliography', $post ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

            return;
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

            $author_ids   = array_merge( $author_ids, $coauthor_ids );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

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

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

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

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

    Space after opening parenthesis of function call prohibited
    Open

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

    Expected 0 spaces after opening bracket; 1 found
    Open

        foreach ( $authors as $author ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

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

    Expected 0 spaces after opening bracket; 1 found
    Open

        if ( ! $post || ! is_singular() ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

            $bib_index = array_search( 'abt/bibliography', array_column( $blocks, 'blockName' ), true );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces after opening bracket; 1 found
    Open

        if ( function_exists( 'get_coauthors' ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces after opening bracket; 1 found
    Open

            if ( $author->first_name && $author->last_name ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

    add_action( 'wp_head', __NAMESPACE__ . '\inject_author_meta' );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Opening brace should be on a new line
    Open

    function inject_author_meta() {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

                    <meta property="abt:author" content="<?php echo esc_attr( $parsed ); ?>" />
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

                    <meta property="abt:author" content="<?php echo esc_attr( $parsed ); ?>" />
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            $bib_index = array_search( 'abt/bibliography', array_column( $blocks, 'blockName' ), true );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Opening brace should be on a new line
    Open

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

    Space after opening parenthesis of function call prohibited
    Open

        if ( function_exists( 'get_coauthors' ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            $bib_index = array_search( 'abt/bibliography', array_column( $blocks, 'blockName' ), true );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

                add_json_script( 'abt-bibliography-json', $blocks[ $bib_index ]['innerHTML'] );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

            $author_ids   = array_merge( $author_ids, $coauthor_ids );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

        if ( is_singular() && has_block( 'abt/bibliography', $post ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

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

    Expected 0 spaces before closing bracket; 1 found
    Open

    add_action( 'the_post', __NAMESPACE__ . '\collect_bibliography' );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

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

    Opening brace should be on a new line
    Open

    function collect_bibliography( WP_Post $post ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

            $bib_index = array_search( 'abt/bibliography', array_column( $blocks, 'blockName' ), true );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

                get_coauthors( $post->ID )
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

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

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( is_singular() && has_block( 'abt/bibliography', $post ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            if ( is_int( $bib_index ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( function_exists( 'get_coauthors' ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

                add_json_script( 'abt-bibliography-json', $blocks[ $bib_index ]['innerHTML'] );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces after opening bracket; 1 found
    Open

        if ( is_singular() ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            $author_ids   = array_merge( $author_ids, $coauthor_ids );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces after opening bracket; 1 found
    Open

        if ( is_singular() && has_block( 'abt/bibliography', $post ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

            if ( is_int( $bib_index ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

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

    Space after opening parenthesis of function call prohibited
    Open

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

    Space after opening parenthesis of function call prohibited
    Open

            $blocks    = parse_blocks( $post->post_content );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

                get_coauthors( $post->ID )
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

    add_action( 'wp_head', __NAMESPACE__ . '\inject_author_meta' );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            $blocks    = parse_blocks( $post->post_content );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

    add_action( 'the_post', __NAMESPACE__ . '\collect_bibliography' );
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces after opening bracket; 1 found
    Open

            if ( is_int( $bib_index ) ) {
    Severity: Minor
    Found in src/php/frontend.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

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

    There are no issues that match your filters.

    Category
    Status