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 — feature/gallery-template-clien... ( fadc9b...b4f512 )
by Brad
02:42
created

FooGallery_NextGen_Import_Progress::message()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 26
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 22
nc 7
nop 0
dl 0
loc 26
rs 6.7272
c 0
b 0
f 0
1
<?php
2
3
if ( ! class_exists( 'FooGallery_NextGen_Import_Progress' ) ) {
4
5
	class FooGallery_NextGen_Import_Progress extends stdClass {
6
7
		const PROGRESS_NOT_STARTED = 'not_started';
8
		const PROGRESS_QUEUED = 'queued';
9
		const PROGRESS_STARTED = 'started';
10
		const PROGRESS_COMPLETED = 'completed';
11
		const PROGRESS_ERROR = 'error';
12
13
		function __construct() {
14
			$this->nextgen_gallery_id = 0;
15
			$this->percentage_complete = 0;
16
			$this->foogallery_id = 0;
17
			$this->foogallery_title = '';
18
			$this->import_count = 0;
19
			$this->attachments = array();
20
			$this->nextgen_gallery = false;
21
			$this->nextgen_pictures = array();
22
			$this->status = self::PROGRESS_NOT_STARTED;
23
			$this->is_part_of_current_import = false;
24
		}
25
26
		function init( $nextgen_gallery_id, $foogallery_title ) {
27
			$this->nextgen_gallery_id = $nextgen_gallery_id;
28
			$this->foogallery_title = $foogallery_title;
29
			$this->status = self::PROGRESS_QUEUED;
30
31
			$nextgen = new FooGallery_NextGen_Helper();
32
33
			//load the gallery and pictures
34
			$this->nextgen_gallery  = $nextgen->get_gallery( $this->nextgen_gallery_id );
35
			$this->nextgen_pictures = $nextgen->get_gallery_images( $this->nextgen_gallery_id );
36
37
			$this->import_count = count( $this->nextgen_pictures );
38
39
			//check for zero images
40
			if ( 0 === $this->import_count ) {
41
				$this->status = self::PROGRESS_ERROR;
42
			}
43
44
			$this->is_part_of_current_import = true;
45
		}
46
47
		function message() {
48
			switch ( $this->status ) {
49
				case self::PROGRESS_NOT_STARTED:
50
					return __( 'Not imported', 'foogallery' );
51
					break;
52
				case self::PROGRESS_QUEUED:
53
					return __( 'Queued for import', 'foogallery' );
54
					break;
55
				case self::PROGRESS_STARTED:
56
					return sprintf( __( 'Imported %d of %d image(s)', 'foogallery' ),
57
						count( $this->attachments ), $this->import_count );
58
					break;
59
				case self::PROGRESS_COMPLETED:
60
					return sprintf( __( 'Done! %d image(s) imported', 'foogallery' ), $this->import_count );
61
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
62
				case self::PROGRESS_ERROR:
63
					if ( 0 === $this->import_count ) {
64
						return __( 'No images to import!', 'foogallery' );
65
					} else {
66
						return __( 'Error while importing!', 'foogallery' );
67
					}
68
					break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
69
			}
70
71
			return __( 'Unknown status!', 'foogallery' );
72
		}
73
74
		function queued_for_import() {
75
			return $this->status === self::PROGRESS_QUEUED;
76
		}
77
78
		function has_started() {
79
			return $this->status === self::PROGRESS_STARTED;
80
		}
81
82
		function is_completed() {
83
			return $this->status === self::PROGRESS_COMPLETED;
84
		}
85
86
		function not_started() {
87
			return $this->status === self::PROGRESS_NOT_STARTED;
88
		}
89
90
		function start() {
91
			$this->status = self::PROGRESS_STARTED;
92
93
			//create an empty foogallery
94
			$foogallery_args = array(
95
				'post_title'  => $this->foogallery_title,
96
				'post_type'   => FOOGALLERY_CPT_GALLERY,
97
				'post_status' => 'publish',
98
			);
99
			$this->foogallery_id = wp_insert_post( $foogallery_args );
100
101
			//set a default gallery template
102
			add_post_meta( $this->foogallery_id, FOOGALLERY_META_TEMPLATE, foogallery_default_gallery_template(), true );
103
104
			//set default settings if there are any
105
            $default_gallery_id = foogallery_get_setting( 'default_gallery_settings' );
106
            if ( $default_gallery_id ) {
107
                $settings = get_post_meta( $default_gallery_id, FOOGALLERY_META_SETTINGS, true );
108
                add_post_meta( $this->foogallery_id, FOOGALLERY_META_SETTINGS, $settings, true );
109
            }
110
		}
111
112
		function can_import() {
113
			if ( $this->status === self::PROGRESS_QUEUED ) {
114
				return true;
115
			} else if ( $this->status === self::PROGRESS_STARTED ) {
116
				return count( $this->nextgen_pictures ) > 0;
117
			}
118
119
			return false;
120
		}
121
122
		function import_next_picture() {
123
			$picture = array_pop( $this->nextgen_pictures );
124
125
			$nextgen = new FooGallery_NextGen_Helper();
126
127
			$attachment_id = $nextgen->import_picture( $this->nextgen_gallery->path, $picture );
128
129
			$attachment_ids = get_post_meta( $this->foogallery_id, FOOGALLERY_META_ATTACHMENTS, true );
130
131
			if ( empty( $attachment_ids ) ) {
132
				$attachment_ids = array();
133
			}
134
135
			$attachment_ids[] = $attachment_id;
136
137
			//link all attachments to foogallery
138
			update_post_meta( $this->foogallery_id, FOOGALLERY_META_ATTACHMENTS, $attachment_ids );
139
140
			//update our list of imported attachments
141
			$this->attachments[] = $attachment_id;
142
143
			//update our percentage complete
144
			if ( $this->import_count > 0 ) {
145
				$this->percentage_complete = count( $this->attachments ) / $this->import_count * 100;
146
			}
147
148
			//update our status if 100%
149
			if ( 100 === $this->percentage_complete ) {
150
				$this->status = self::PROGRESS_COMPLETED;
151
			}
152
		}
153
	}
154
}
155