Passed
Push — 4.0.0/theme-review ( 9f28a3...8d4b6c )
by Warwick
03:50
created

Frontend::enqueue_styles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
2
namespace LSX\Classes;
3
4
/**
5
 * All the functions for setting up the theme.
6
 *
7
 * @package   LSX
8
 * @author    LightSpeed
9
 * @license   GPL3
10
 * @link
11
 * @copyright 2023 LightSpeed
12
 */
13
class Frontend {
14
15
	/**
16
	 * Contructor
17
	 */
18
	public function __construct() {
19
	}
20
21
	/**
22
	 * Initiate our class.
23
	 *
24
	 * @return void
25
	 */
26
	public function init() {
27
		// Styles and Scripts
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
28
		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
29
		add_action( 'wp_enqueue_scripts', array( $this, 'yoast_faq_asset_files' ) );
30
		add_action( 'wp_enqueue_scripts', array( $this, 'woo_asset_files' ) );
31
32
		//Output on the frontend.
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// Output on the frontend." but found "//Output on the frontend."
Loading history...
33
		add_filter( 'wpforms_frontend_form_data', array( $this, 'wpforms_match_button_block' ) );
34
	}
35
36
	/**
37
	 * Enqueues the frontend styles
38
	 *
39
	 * @return void
40
	 */
41
	public function enqueue_styles() {
42
		wp_enqueue_style( 'lsx-styles', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) );
0 ignored issues
show
Bug introduced by
It seems like wp_get_theme()->get('Version') can also be of type array; however, parameter $ver of wp_enqueue_style() does only seem to accept boolean|null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
		wp_enqueue_style( 'lsx-styles', get_template_directory_uri() . '/style.css', array(), /** @scrutinizer ignore-type */ wp_get_theme()->get( 'Version' ) );
Loading history...
43
	}
44
45
46
	/**
47
	 * Load the assets files for Yoast
48
	 *
49
	 * @return void
50
	 */
51
	public function yoast_faq_asset_files() {
52
		if ( function_exists( 'wpseo_init' ) ) {
53
			wp_enqueue_style( 'lsx-yoast-faq-css', get_template_directory_uri() . '/assets/css/faq/style.css', array() );
0 ignored issues
show
introduced by
Resource version not set in call to wp_enqueue_style(). This means new versions of the style will not always be loaded due to browser caching.
Loading history...
54
			wp_enqueue_script( 'lsx-yoast-faq-js', get_template_directory_uri()  . '/assets/js/faq.js', array( "jquery" ), "1.0", true );
0 ignored issues
show
Coding Style introduced by
Concat operator must be surrounded by a single space
Loading history...
Coding Style Comprehensibility introduced by
The string literal jquery does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal 1.0 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
55
		}
56
	}
57
58
	/**
59
	 * Load the assets files for Yoast
60
	 *
61
	 * @return void
62
	 */
63
	public function woo_asset_files() {
64
		if ( class_exists( 'woocommerce' ) ) {
65
			wp_enqueue_style( 'lsx-woo-css', get_template_directory_uri() . '/assets/css/woocommerce.css', array() );
0 ignored issues
show
introduced by
Resource version not set in call to wp_enqueue_style(). This means new versions of the style will not always be loaded due to browser caching.
Loading history...
66
		}
67
	}
68
69
	/**
70
	 * WPForms submit button, match Gutenberg button block
71
	 *
72
	 * @param [type] $form_data
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
73
	 * @return void
0 ignored issues
show
Coding Style introduced by
Function return type is void, but function contains return statement
Loading history...
74
	 */
75
	function wpforms_match_button_block( $form_data ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for wpforms_match_button_block.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
76
		$form_data['settings']['submit_class'] .= ' btn';
77
		return $form_data;
78
	}
79
}
80