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-datasources ( 53fbb8 )
by Brad
02:16
created

FooGalleryDatasource_MediaLibrary::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * The default Gallery Datasource which pulls attachments from the WP media library
4
 */
5
if ( ! class_exists( 'FooGalleryDatasource_MediaLibrary' ) ) {
6
7
	class FooGalleryDatasource_MediaLibrary implements IFooGalleryDatasource {
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...
8
9
		/**
10
		 * @var FooGallery
11
		 */
12
		private $foogallery;
13
14
		/**
15
		 * Sets the FooGallery object we are dealing with
16
		 *
17
		 * @param $foogallery FooGallery
18
		 */
19
		public function setGallery( $foogallery ) {
20
			$this->foogallery = $foogallery;
21
		}
22
23
		function __construct() {
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...
24
			//attachment_count
25
			//attachment_id_csv
26
			//attachments
27
			//find_featured_attachment_id
28
			//featured_attachment
29
			//featured_image_html
30
		}
31
32
		/**
33
		 * Returns the number of attachments used from the media library
34
		 * @return int
35
		 */
36
		public function getCount() {
37
			return sizeof( $this->foogallery->attachment_ids );
38
		}
39
40
		/**
41
		 * Returns a serialized string that represents the media in the datasource.
42
		 * This string is persisted when saving a FooGallery
43
		 *
44
		 * @return string
45
		 */
46
		public function getSerializedData() {
47
			if ( is_array( $this->foogallery->attachment_ids ) ) {
48
				return implode( ',', $this->foogallery->attachment_ids );
49
			}
50
51
			return '';
52
		}
53
54
		/**
55
		 * Returns an array of FooGalleryAttachments from the datasource
56
		 * @return array(FooGalleryAttachment)
0 ignored issues
show
Documentation introduced by
The doc-type array(FooGalleryAttachment) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
57
		 */
58
		public function getAttachments() {
59
			$attachments = array();
60
61
			if ( ! empty( $this->foogallery->attachment_ids ) ) {
62
63
				add_action( 'pre_get_posts', array( $this, 'force_gallery_ordering' ), 99 );
64
65
				$attachment_query_args = apply_filters( 'foogallery_attachment_get_posts_args', array(
66
					'post_type'      => 'attachment',
67
					'posts_per_page' => -1,
68
					'post__in'       => $this->foogallery->attachment_ids,
69
					'orderby'        => foogallery_sorting_get_posts_orderby_arg( $this->foogallery->sorting ),
70
					'order'          => foogallery_sorting_get_posts_order_arg( $this->foogallery->sorting )
71
				) );
72
73
				$attachment_posts = get_posts( $attachment_query_args );
74
75
				remove_action( 'pre_get_posts', array( $this, 'force_gallery_ordering' ), 99 );
76
77
				$attachments = array_map( array( 'FooGalleryAttachment', 'get' ), $attachment_posts );
78
			}
79
80
			return $attachments;
81
		}
82
83
		/**
84
		 * This forces the attachments to be fetched using the correct ordering.
85
		 * Some plugins / themes override this globally for some reason, so this is a preventative measure to ensure sorting is correct
86
		 * @param $query WP_Query
87
		 */
88
		public function force_gallery_ordering( $query ) {
89
			//only care about attachments
90
			if ( array_key_exists( 'post_type', $query->query ) &&
91
				'attachment' === $query->query['post_type'] ) {
92
				$query->set( 'orderby', foogallery_sorting_get_posts_orderby_arg( $this->foogallery->sorting ) );
93
				$query->set( 'order', foogallery_sorting_get_posts_order_arg( $this->foogallery->sorting ) );
94
			}
95
		}
96
97
		/**
98
		 * Returns the featured FooGalleryAttachment from the datasource
99
		 * @return bool|FooGalleryAttachment
100
		 */
101
		public function getFeaturedAttachment() {
102
			// TODO: Implement getFeaturedAttachment() method.
103
		}
104
105
106
	}
107
}