Completed
Pull Request — master (#885)
by
unknown
03:00
created
lib/timber-post-getter.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -8,19 +8,19 @@  discard block
 block discarded – undo
8 8
 	 * @return array|bool|null
9 9
 	 */
10 10
 	static function get_post($query = false, $PostClass = 'TimberPost') {
11
-		$posts = self::get_posts( $query, $PostClass );
12
-		if ( $post = reset($posts ) ) {
11
+		$posts = self::get_posts($query, $PostClass);
12
+		if ( $post = reset($posts) ) {
13 13
 			return $post;
14 14
 		}
15 15
 	}
16 16
 
17
-	static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) {
18
-		$posts = self::query_posts( $query, $PostClass );
19
-		return apply_filters('timber_post_getter_get_posts', $posts->get_posts( $return_collection ));
17
+	static function get_posts($query = false, $PostClass = 'TimberPost', $return_collection = false) {
18
+		$posts = self::query_posts($query, $PostClass);
19
+		return apply_filters('timber_post_getter_get_posts', $posts->get_posts($return_collection));
20 20
 	}
21 21
 
22
-	static function query_post( $query = false, $PostClass = 'TimberPost' ) {
23
-		$posts = self::query_posts( $query, $PostClass );
22
+	static function query_post($query = false, $PostClass = 'TimberPost') {
23
+		$posts = self::query_posts($query, $PostClass);
24 24
 		if ( method_exists($posts, 'current') && $post = $posts->current() ) {
25 25
 			return $post;
26 26
 		}
@@ -31,32 +31,32 @@  discard block
 block discarded – undo
31 31
 	 * @param string $PostClass
32 32
 	 * @return array|bool|null
33 33
 	 */
34
-	static function query_posts($query = false, $PostClass = 'TimberPost' ) {
35
-		if ($type = self::is_post_class_or_class_map($query)) {
34
+	static function query_posts($query = false, $PostClass = 'TimberPost') {
35
+		if ( $type = self::is_post_class_or_class_map($query) ) {
36 36
 			$PostClass = $type;
37 37
 			$query = false;
38 38
 		}
39 39
 
40
-		if (is_object($query) && !is_a($query, 'WP_Query') ){
40
+		if ( is_object($query) && !is_a($query, 'WP_Query') ) {
41 41
 			// The only object other than a query is a type of post object
42
-			$query = array( $query );
42
+			$query = array($query);
43 43
 		}
44 44
 
45
-		if ( is_array( $query ) && count( $query ) && isset( $query[0] ) && is_object( $query[0] ) ) {
45
+		if ( is_array($query) && count($query) && isset($query[0]) && is_object($query[0]) ) {
46 46
 			// We have an array of post objects that already have data
47
-			return new TimberPostsCollection( $query, $PostClass );
47
+			return new TimberPostsCollection($query, $PostClass);
48 48
 		} else {
49 49
 			// We have a query (of sorts) to work with
50
-			$tqi = new TimberQueryIterator( $query, $PostClass );
50
+			$tqi = new TimberQueryIterator($query, $PostClass);
51 51
 			return $tqi;
52 52
 		}
53 53
 	}
54 54
 
55
-	static function get_pids($query){
55
+	static function get_pids($query) {
56 56
 		$posts = self::get_posts($query);
57 57
 		$pids = array();
58
-		foreach($posts as $post){
59
-			if (isset($post->ID)){
58
+		foreach ($posts as $post) {
59
+			if ( isset($post->ID) ) {
60 60
 				$pids[] = $post->ID;
61 61
 			}
62 62
 		}
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	}
65 65
 
66 66
 	static function loop_to_id() {
67
-		if (!self::wp_query_has_posts()) { return false; }
67
+		if ( !self::wp_query_has_posts() ) { return false; }
68 68
 
69 69
 		global $wp_query;
70 70
 		$post_num = property_exists($wp_query, 'current_post')
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 				  : 0
73 73
 				  ;
74 74
 
75
-		if (!isset($wp_query->posts[$post_num])) { return false; }
75
+		if ( !isset($wp_query->posts[$post_num]) ) { return false; }
76 76
 
77 77
 		return $wp_query->posts[$post_num]->ID;
78 78
 	}
@@ -89,18 +89,18 @@  discard block
 block discarded – undo
89 89
 	 * @param string|array $arg
90 90
 	 * @return bool
91 91
 	 */
92
-	static function is_post_class_or_class_map($arg){
92
+	static function is_post_class_or_class_map($arg) {
93 93
 		$type = false;
94 94
 
95
-		if(is_string($arg)) {
95
+		if ( is_string($arg) ) {
96 96
 			$type = $arg;
97
-		} else if(is_array($arg) && isset($arg['post_type'])) {
97
+		} else if ( is_array($arg) && isset($arg['post_type']) ) {
98 98
 			$type = $arg['post_type'];
99 99
 		}
100 100
 
101
-		if(!$type) return false;
101
+		if ( !$type ) return false;
102 102
 
103
-		if (class_exists($type) && is_subclass_of($type, 'TimberPost')) {
103
+		if ( class_exists($type) && is_subclass_of($type, 'TimberPost') ) {
104 104
 			return $type;
105 105
 		}
106 106
 	}
Please login to merge, or discard this patch.
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 			$query = false;
38 38
 		}
39 39
 
40
-		if (is_object($query) && !is_a($query, 'WP_Query') ){
40
+		if (is_object($query) && !is_a($query, 'WP_Query') ) {
41 41
 			// The only object other than a query is a type of post object
42 42
 			$query = array( $query );
43 43
 		}
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 		}
53 53
 	}
54 54
 
55
-	static function get_pids($query){
55
+	static function get_pids($query) {
56 56
 		$posts = self::get_posts($query);
57 57
 		$pids = array();
58
-		foreach($posts as $post){
59
-			if (isset($post->ID)){
58
+		foreach($posts as $post) {
59
+			if (isset($post->ID)) {
60 60
 				$pids[] = $post->ID;
61 61
 			}
62 62
 		}
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 * @param string|array $arg
90 90
 	 * @return bool
91 91
 	 */
92
-	static function is_post_class_or_class_map($arg){
92
+	static function is_post_class_or_class_map($arg) {
93 93
 		$type = false;
94 94
 
95 95
 		if(is_string($arg)) {
@@ -98,7 +98,9 @@  discard block
 block discarded – undo
98 98
 			$type = $arg['post_type'];
99 99
 		}
100 100
 
101
-		if(!$type) return false;
101
+		if(!$type) {
102
+			return false;
103
+		}
102 104
 
103 105
 		if (class_exists($type) && is_subclass_of($type, 'TimberPost')) {
104 106
 			return $type;
Please login to merge, or discard this patch.