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.

FooGallery_Admin_Columns::get_local_gallery()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/*
3
 * FooGallery Admin Columns class
4
 */
5
6
if ( ! class_exists( 'FooGallery_Admin_Columns' ) ) {
7
8
	class FooGallery_Admin_Columns {
9
10
		private $include_clipboard_script = false;
11
		private $_foogallery = false;
12
13
		public function __construct() {
14
			add_filter( 'manage_edit-' . FOOGALLERY_CPT_GALLERY . '_columns', array( $this, 'gallery_custom_columns' ) );
15
			add_action( 'manage_posts_custom_column', array( $this, 'gallery_custom_column_content' ) );
16
			add_action( 'admin_footer', array( $this, 'include_clipboard_script' ) );
17
		}
18
19
		public function gallery_custom_columns( $columns ) {
20
			return array_slice( $columns, 0, 1, true ) +
21
					array( 'icon' => '' ) +
22
					array_slice( $columns, 1, null, true ) +
23
					array(
24
						FOOGALLERY_CPT_GALLERY . '_template' => __( 'Template', 'foogallery' ),
25
						FOOGALLERY_CPT_GALLERY . '_count' => __( 'Media', 'foogallery' ),
26
						FOOGALLERY_CPT_GALLERY . '_shortcode' => __( 'Shortcode', 'foogallery' ),
27
						FOOGALLERY_CPT_GALLERY . '_usage' => __( 'Usage', 'foogallery' ),
28
					);
29
		}
30
31
		private function get_local_gallery( $post ) {
32
			if ( false === $this->_foogallery ) {
33
				$this->_foogallery = FooGallery::get( $post );
0 ignored issues
show
Documentation Bug introduced by
It seems like \FooGallery::get($post) of type object<FooGallery> is incompatible with the declared type boolean of property $_foogallery.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
			} else if ( $this->_foogallery->ID !== $post->ID) {
35
				$this->_foogallery = FooGallery::get( $post );
36
			}
37
38
			return $this->_foogallery;
39
		}
40
41
		public function gallery_custom_column_content( $column ) {
42
			global $post;
43
44
			switch ( $column ) {
45
				case FOOGALLERY_CPT_GALLERY . '_template':
46
					$gallery = $this->get_local_gallery( $post );
47
					echo $gallery->gallery_template_name();
48
					break;
49
				case FOOGALLERY_CPT_GALLERY . '_count':
50
					$gallery = $this->get_local_gallery( $post );
51
					echo $gallery->image_count();
52
					break;
53
				case FOOGALLERY_CPT_GALLERY . '_shortcode':
54
					$gallery = $this->get_local_gallery( $post );
55
					$shortcode = $gallery->shortcode();
56
57
					echo '<input type="text" readonly="readonly" size="' . strlen( $shortcode )  . '" value="' . esc_attr( $shortcode ) . '" class="foogallery-shortcode" />';
58
59
					$this->include_clipboard_script = true;
60
61
					break;
62
				case 'icon':
63
					$gallery = $this->get_local_gallery( $post );
64
					$html_img = foogallery_find_featured_attachment_thumbnail_html( $gallery, array(
0 ignored issues
show
Bug introduced by
It seems like $gallery defined by $this->get_local_gallery($post) on line 63 can also be of type boolean; however, foogallery_find_featured...chment_thumbnail_html() does only seem to accept object<FooGallery>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
65
						'width' => 60,
66
						'height' => 60,
67
						'force_use_original_thumb' => true
68
					) );
69
					if ( $html_img ) {
70
						echo $html_img;
71
					}
72
					break;
73
				case FOOGALLERY_CPT_GALLERY . '_usage':
74
					$gallery = $this->get_local_gallery( $post );
75
					$posts = $gallery->find_usages();
76
					if ( $posts && count( $posts ) > 0 ) {
77
						echo '<ul class="ul-disc">';
78
						foreach ( $posts as $post ) {
79
							echo edit_post_link( $post->post_title, '<li>', '</li>', $post->ID );
80
						}
81
						echo '</ul>';
82
					} else {
83
						_e( 'Not used!', 'foogallery' );
84
					}
85
					break;
86
			}
87
		}
88
89
		public function include_clipboard_script() {
90
			if ( $this->include_clipboard_script ) { ?>
91
				<script>
92
					jQuery(function($) {
93
						$('.foogallery-shortcode').click( function () {
94
							try {
95
								//select the contents
96
								this.select();
97
								//copy the selection
98
								document.execCommand('copy');
99
								//show the copied message
100
								$('.foogallery-shortcode-message').remove();
101
								$(this).after('<p class="foogallery-shortcode-message"><?php _e( 'Shortcode copied to clipboard :)','foogallery' ); ?></p>');
102
							} catch(err) {
103
								console.log('Oops, unable to copy!');
104
							}
105
						});
106
					});
107
				</script>
108
				<?php
109
			}
110
		}
111
	}
112
}
113