dsifford/academic-bloggers-toolkit

View on GitHub
src/php/utils.php

Summary

Maintainability
A
1 hr
Test Coverage

Method register_script has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function register_script( string $relpath, array $extra_deps = [] ) {
    $handle        = 'abt-' . $relpath;
    $script_suffix = "/bundle/$relpath.js";
    $style_suffix  = "/bundle/$relpath.css";

Severity: Minor
Found in src/php/utils.php - About 1 hr to fix

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

            function () use ( $id, $data ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

            function () use ( $id, $data ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                        function( $id ) use ( $registered_styles ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

    function add_json_script( string $id, $data ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

    function register_script( string $relpath, array $extra_deps = [] ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                        function( $id ) use ( $registered_styles ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 1 space after FUNCTION keyword; 0 found
    Open

                        function( $id ) use ( $registered_styles ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

    function register_script( string $relpath, array $extra_deps = [] ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( file_exists( ABT_ROOT_PATH . $style_suffix ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( file_exists( ABT_ROOT_PATH . $script_suffix ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( did_action( $action ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                        function( $id ) use ( $registered_styles ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                        function( $id ) use ( $registered_styles ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

    function add_json_script( string $id, $data ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            if ( in_array( 'wp-i18n', $script_asset['dependencies'], true ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                    <script
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                        type="application/json"
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

        $script_asset_path            = ABT_ROOT_PATH . "/bundle/$relpath.asset.php";
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

                    array_filter(
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

            $action,
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

            function () use ( $id, $data ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

            'version'      => filemtime( ABT_ROOT_PATH . $script_suffix ),
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

                $handle,
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                ),
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                filemtime( ABT_ROOT_PATH . $style_suffix )
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                ABT_ROOT_URI . $script_suffix,
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                wp_set_script_translations(
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

                ABT_ROOT_URI . $style_suffix,
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                    $handle,
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

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

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

            file_get_contents( // phpcs:ignore
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

        $script_suffix = "/bundle/$relpath.js";
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

        $action = $prefix . 'footer';
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

        $script_asset                 = file_exists( $script_asset_path ) ? require $script_asset_path : [
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

            if ( in_array( 'wp-i18n', $script_asset['dependencies'], true ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                    basename( ABT_ROOT_PATH ) . '/languages'
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                        function( $id ) use ( $registered_styles ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

        $prefix = is_admin() ? 'admin_' : 'wp_';
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

                $script_asset['version'],
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

        add_action(
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                        id="<?php echo esc_attr( $id ); ?>"
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

        $style_suffix  = "/bundle/$relpath.css";
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

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

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

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

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

        if ( file_exists( ABT_ROOT_PATH . $script_suffix ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                $handle,
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

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

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

                    'academic-bloggers-toolkit',
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

        if ( file_exists( ABT_ROOT_PATH . $style_suffix ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                        ><?php echo wp_json_encode( $data ); ?></script>
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                ABT_ROOT_PATH . '/citation-styles.json'
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

        $handle        = 'abt-' . $relpath;
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

            wp_register_style(
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                array_values(
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

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

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

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

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

            throw new \RuntimeException( 'Action already fired for JSON data with ID ' . $id );
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

        return json_decode(
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                $script_asset['dependencies'],
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

        $script_asset['dependencies'] = array_merge( $script_asset['dependencies'], $extra_deps );
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

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

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

                        $script_asset['dependencies'],
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

        if ( did_action( $action ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

            wp_register_script(
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

            $registered_styles = wp_styles()->registered;
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

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

                                return array_key_exists( $id, $registered_styles );
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Opening brace should be on a new line
    Open

    function register_script( string $relpath, array $extra_deps = [] ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

        $script_asset['dependencies'] = array_merge( $script_asset['dependencies'], $extra_deps );
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        $script_asset['dependencies'] = array_merge( $script_asset['dependencies'], $extra_deps );
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

                filemtime( ABT_ROOT_PATH . $style_suffix )
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces after opening bracket; 1 found
    Open

        if ( did_action( $action ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

                        ><?php echo wp_json_encode( $data ); ?></script>
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces after opening bracket; 1 found
    Open

        if ( file_exists( ABT_ROOT_PATH . $script_suffix ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

            if ( in_array( 'wp-i18n', $script_asset['dependencies'], true ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces after opening bracket; 1 found
    Open

        if ( file_exists( ABT_ROOT_PATH . $style_suffix ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Opening brace should be on a new line
    Open

    function get_citation_styles() {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            if ( in_array( 'wp-i18n', $script_asset['dependencies'], true ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

                        id="<?php echo esc_attr( $id ); ?>"
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

                        id="<?php echo esc_attr( $id ); ?>"
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            'version'      => filemtime( ABT_ROOT_PATH . $script_suffix ),
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

        if ( file_exists( ABT_ROOT_PATH . $script_suffix ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

            throw new \RuntimeException( 'Action already fired for JSON data with ID ' . $id );
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

                    basename( ABT_ROOT_PATH ) . '/languages'
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

        if ( file_exists( ABT_ROOT_PATH . $style_suffix ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( did_action( $action ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        $script_asset                 = file_exists( $script_asset_path ) ? require $script_asset_path : [
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

                        ><?php echo wp_json_encode( $data ); ?></script>
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( file_exists( ABT_ROOT_PATH . $style_suffix ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

                                return array_key_exists( $id, $registered_styles );
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

                filemtime( ABT_ROOT_PATH . $style_suffix )
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Opening brace should be on a new line
    Open

    function add_json_script( string $id, $data ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

                                return array_key_exists( $id, $registered_styles );
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

            throw new \RuntimeException( 'Action already fired for JSON data with ID ' . $id );
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

        if ( did_action( $action ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

        $script_asset                 = file_exists( $script_asset_path ) ? require $script_asset_path : [
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

        if ( file_exists( ABT_ROOT_PATH . $script_suffix ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Space after opening parenthesis of function call prohibited
    Open

            'version'      => filemtime( ABT_ROOT_PATH . $script_suffix ),
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces after opening bracket; 1 found
    Open

            if ( in_array( 'wp-i18n', $script_asset['dependencies'], true ) ) {
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    Expected 0 spaces before closing bracket; 1 found
    Open

                    basename( ABT_ROOT_PATH ) . '/languages'
    Severity: Minor
    Found in src/php/utils.php by phpcodesniffer

    There are no issues that match your filters.

    Category
    Status