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

Images::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 1
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 image functions for the theme.
6
 *
7
 * @package   LSX
8
 * @author    LightSpeed
9
 * @license   GPL3
10
 * @link
11
 * @copyright 2023 LightSpeed
12
 */
13
class Images {
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
		add_action( 'after_setup_theme', array( $this, 'register_image_sizes' ), 10 );
28
		add_filter( 'image_size_names_choose', array( $this, 'register_media_editor_sizes' ), 10, 1 );
29
		add_filter( 'render_block_data', array( $this, 'render_post_image_data' ), 10, 3 );
30
	}
31
32
	/**
33
	 * Register our image size
34
	 *
35
	 * @return void
36
	 */
37
	public function register_image_sizes() {
38
		add_image_size( 'lsx-blog-thumbnail', 640, 480, array( 'center', 'center' ) );
39
		add_image_size( 'lsx-product-thumbnail', 480, 480, array( 'center', 'center' ) );
40
	}
41
42
	/**
43
	 * Add ing the image sizes to the media editor.
44
	 *
45
	 * @param array $sizes
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
46
	 * @return void
0 ignored issues
show
Coding Style introduced by
Function return type is void, but function contains return statement
Loading history...
47
	 */
48
	public function register_media_editor_sizes( $sizes = array() ) {
49
		return array_merge( $sizes, array(
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_merge($size...og Thumbnail', 'lsx'))) returns the type array which is incompatible with the documented return type void.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
50
			'lsx-blog-thumbnail' => __( 'LSX Blog Thumbnail', 'lsx' ),
51
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
52
	}
53
54
	/**
55
	 * Sets the post image fields
56
	 *
57
	 * @param array         $parsed_block The block being rendered.
58
	 * @param array         $source_block An un-modified copy of $parsed_block, as it appeared in the source content.
59
	 * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block.
0 ignored issues
show
Bug introduced by
The type LSX\Classes\WP_Block was not found. Did you mean WP_Block? If so, make sure to prefix the type with \.
Loading history...
60
	 * @return array
61
	 */
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
62
	
63
	public function render_post_image_data( $parsed_block, $source_block, $parent_block ) {
0 ignored issues
show
Unused Code introduced by
The parameter $parent_block is not used and could be removed. ( Ignorable by Annotation )

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

63
	public function render_post_image_data( $parsed_block, $source_block, /** @scrutinizer ignore-unused */ $parent_block ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $source_block is not used and could be removed. ( Ignorable by Annotation )

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

63
	public function render_post_image_data( $parsed_block, /** @scrutinizer ignore-unused */ $source_block, $parent_block ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
		if ( ! is_home() || !is_front_page() || is_archive() && 'core/post-featured-image' === $parsed_block['blockName'] ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
65
			$parsed_block['attrs']['sizeSlug'] = 'lsx-blog-thumbnail';
66
		}
67
		if ( function_exists( 'is_woocommerce' ) && is_woocommerce() && 'woocommerce/product-image' === $parsed_block['blockName'] ) {
68
			$parsed_block['attrs']['sizeSlug'] = 'lsx-product-thumbnail';
69
		}
70
		return $parsed_block;
71
	}
72
}
73