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
Pull Request — feature/justified-gallery-imag... (#68)
by
unknown
02:18
created

FooGallery_Admin_Notices::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * FooGallery Admin Notices class
4
 */
5
6
if ( ! class_exists( 'FooGallery_Admin_Notices' ) ) {
7
8
    class FooGallery_Admin_Notices {
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...
9
10
        public function __construct() {
11
            add_action( 'admin_notices', array( $this, 'display_thumb_test_notice') );
12
            add_action( 'foogallery_thumbnail_generation_test', array( $this, 'save_test_results') );
13
        }
14
15
        function should_run_tests() {
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...
16
            $option = get_option( FOOGALLERY_OPTION_THUMB_TEST );
17
            $option_value = $this->generate_option_value();
18
19
            if ( !isset( $option ) ) {
20
                //we have never run tests before
21
                return true;
22
            } else {
23
                $option_key = $option['key'];
24
                if ( $option_value !== $option_key ) {
25
                    //either the PHP version or Host has changed. In either case, we should run tests again!
26
                    return true;
27
                }
28
            }
29
30
            return false;
31
        }
32
33
        function should_show_alert() {
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...
34
            $option = get_option( FOOGALLERY_OPTION_THUMB_TEST );
35
36
            if ( isset( $option ) && array_key_exists( 'results', $option ) ) {
37
                $results = $option['results'];
38
                //should show the alert if the tests were not a success
39
                return !$results['success'];
40
            }
41
42
            return false;
43
        }
44
45
        function generate_option_value() {
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...
46
            $php_version = phpversion();
47
            $host = home_url();
48
            return "php$($php_version}-{$host}";
49
        }
50
51
        function save_test_results($results) {
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...
52
            update_option( FOOGALLERY_OPTION_THUMB_TEST, array (
53
                'key' => $this->generate_option_value(),
54
                'results' => $results
55
            ));
56
        }
57
58
        function display_thumb_test_notice() {
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...
59
            //check if we are on specific admin pages
60
            if ( FOOGALLERY_CPT_GALLERY === foo_current_screen_post_type() ) {
61
62
                if ($this->should_run_tests()) {
63
                    $thumbs = new FooGallery_Thumbnails();
64
                    $thumbs->run_thumbnail_generation_tests();
65
                }
66
67
                if ($this->should_show_alert()) {
68
                    ?>
69
                    <div class="notice error">
70
                        <p>
71
                            <strong><?php _e('Thumbnail Generation Alert!', 'foogallery'); ?></strong><br/>
72
                            <?php _e('There is a problem generating thumbnails for your gallery. Please check that your hosting provider has the GD Image Library extension installed and enabled.' , 'foogallery'); ?><br />
73
                            <?php _e('If thumbnails cannot be generated, then full-sized, uncropped images will be used instead. This will result in slow page load times, and thumbnails that do not look correct.', 'foogallery'); ?>
74
                            <br/>
75
                        </p>
76
                    </div>
77
                    <?php
78
                }
79
            }
80
        }
81
    }
82
83
}