GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b3ee5f...a83cd4 )
by Brad
06:08 queued 03:01
created

FooGallery_Gutenberg::attach_gallery_to_post()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 2
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 7.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * FooGallery Gutenberg Functionality
4
 * Date: 28/10/2018
5
 */
6
7
require_once( FOOGALLERY_PATH . 'gutenberg/class-foogallery-blocks.php' );
8
require_once( FOOGALLERY_PATH . 'gutenberg/class-foogallery-rest-routes.php' );
9
10
if ( ! class_exists( 'FooGallery_Gutenberg' ) ) {
11
12
	class FooGallery_Gutenberg {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
14
		function __construct() {
15
			new FooGallery_Blocks();
16
			new FooGallery_Rest_Routes();
17
18
			add_action( 'foogallery_attach_gallery_to_post', array( $this, 'attach_gallery_to_post' ), 10, 2 );
19
		}
20
21
		/**
22
		 * Use the built-in Block Parser to "attach" a gallery to a post
23
		 *
24
		 * @param $post_id
25
		 * @param $post
26
		 */
27
		function attach_gallery_to_post( $post_id, $post ) {
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...
28
			if ( !class_exists( 'WP_Block_Parser' ) ) {
29
				return;
30
			}
31
32
			$parser = new WP_Block_Parser();
33
			$blocks = $parser->parse( $post->post_content );
34
35
			foreach ( $blocks as $block ) {
36
				if ( array_key_exists( 'id', $block['attrs'] ) ) {
37
					$gallery_id = $block['attrs']['id'];
38
39
					add_post_meta( $post_id, FOOGALLERY_META_POST_USAGE, $gallery_id, false );
40
41
					do_action( 'foogallery_attach_gallery_to_post', $post_id, $gallery_id );
42
				}
43
			}
44
		}
45
	}
46
}