Completed
Pull Request — develop (#1698)
by
unknown
01:26
created
src/wordlift/videoobject/api/class-rest-controller.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -12,165 +12,165 @@
 block discarded – undo
12 12
 use WP_REST_Server;
13 13
 
14 14
 class Rest_Controller {
15
-	/**
16
-	 * @var Videoobject_Background_Process
17
-	 */
18
-	private $background_process;
19
-
20
-	/**
21
-	 * Rest_Controller constructor.
22
-	 *
23
-	 * @param $background_process Videoobject_Background_Process
24
-	 */
25
-	public function __construct( $background_process ) {
26
-		$this->background_process = $background_process;
27
-	}
28
-
29
-	public function register_all_routes() {
30
-		$that = $this;
31
-		add_action(
32
-			'rest_api_init',
33
-			function () use ( $that ) {
34
-				$that->register_get_all_videos_route();
35
-				$that->register_save_all_videos_route();
36
-				$that->register_get_sync_state_endpoint();
37
-				$that->register_background_process_start_endpoint();
38
-				$that->register_background_process_stop_endpoint();
39
-			}
40
-		);
41
-	}
42
-
43
-	public function get_all_videos( $request ) {
44
-		$data    = $request->get_params();
45
-		$post_id = (int) $data['post_id'];
46
-		$storage = Video_Storage_Factory::get_storage();
47
-
48
-		return $storage->get_all_videos( $post_id );
49
-	}
50
-
51
-	public function save_all_videos( $request ) {
52
-		$data    = $request->get_params();
53
-		$post_id = (int) $data['post_id'];
54
-		$videos  = (array) $data['videos'];
55
-		if ( ! $videos ) {
56
-			return;
57
-		}
58
-		$storage = Video_Storage_Factory::get_storage();
59
-		$storage->remove_all_videos( $post_id );
60
-
61
-		foreach ( $videos as $video ) {
62
-			$video_obj = new Video();
63
-			$video_obj->from( (array) $video );
64
-			$storage->add_video( $post_id, $video_obj );
65
-		}
66
-
67
-	}
68
-
69
-	private function register_get_all_videos_route() {
70
-		register_rest_route(
71
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
72
-			'/videos',
73
-			array(
74
-				'methods'             => WP_REST_Server::CREATABLE,
75
-				'callback'            => array( $this, 'get_all_videos' ),
76
-				'permission_callback' => function () {
77
-					return current_user_can( 'manage_options' );
78
-				},
79
-				'args'                => array(
80
-					'post_id' => array(
81
-						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
82
-						'validate_callback' => function ( $param, $request, $key ) {
83
-							return is_numeric( $param ) && $param;
84
-						},
85
-						'required'          => true,
86
-					),
87
-				),
88
-			)
89
-		);
90
-	}
91
-
92
-	private function register_save_all_videos_route() {
93
-		register_rest_route(
94
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
95
-			'/videos/save',
96
-			array(
97
-				'methods'             => WP_REST_Server::CREATABLE,
98
-				'callback'            => array( $this, 'save_all_videos' ),
99
-				'permission_callback' => function () {
100
-					return current_user_can( 'manage_options' );
101
-				},
102
-				'args'                => array(
103
-					'post_id' => array(
104
-						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
105
-						'validate_callback' => function ( $param, $request, $key ) {
106
-							return is_numeric( $param ) && $param;
107
-						},
108
-						'required'          => true,
109
-					),
110
-					'videos'  => array(
111
-						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
112
-						'validate_callback' => function ( $param, $request, $key ) {
113
-							return is_array( $param ) && $param;
114
-						},
115
-						'required'          => true,
116
-					),
117
-				),
118
-			)
119
-		);
120
-	}
121
-
122
-	public function register_get_sync_state_endpoint() {
123
-		$that = $this;
124
-		register_rest_route(
125
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
126
-			'/videos/background/get_state',
127
-			array(
128
-				'methods'             => WP_REST_Server::CREATABLE,
129
-				'callback'            => function () use ( $that ) {
130
-					return $that->background_process->get_state()->get_array();
131
-				},
132
-				'permission_callback' => function () {
133
-					return current_user_can( 'manage_options' );
134
-				},
135
-			)
136
-		);
137
-
138
-	}
139
-
140
-	public function register_background_process_start_endpoint() {
141
-		$that = $this;
142
-		register_rest_route(
143
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
144
-			'/videos/background/start',
145
-			array(
146
-				'methods'             => WP_REST_Server::CREATABLE,
147
-				'callback'            => function () use ( $that ) {
148
-					$that->background_process->start();
149
-				},
150
-				'permission_callback' => function () {
151
-					return current_user_can( 'manage_options' );
152
-				},
153
-			)
154
-		);
155
-
156
-	}
157
-
158
-	public function register_background_process_stop_endpoint() {
159
-		$that = $this;
160
-		register_rest_route(
161
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
162
-			'/videos/background/stop',
163
-			array(
164
-				'methods'             => WP_REST_Server::CREATABLE,
165
-				'callback'            => function () use ( $that ) {
166
-					$that->background_process->cancel();
167
-				},
168
-				'permission_callback' => function () {
169
-					return current_user_can( 'manage_options' );
170
-				},
171
-			)
172
-		);
173
-
174
-	}
15
+    /**
16
+     * @var Videoobject_Background_Process
17
+     */
18
+    private $background_process;
19
+
20
+    /**
21
+     * Rest_Controller constructor.
22
+     *
23
+     * @param $background_process Videoobject_Background_Process
24
+     */
25
+    public function __construct( $background_process ) {
26
+        $this->background_process = $background_process;
27
+    }
28
+
29
+    public function register_all_routes() {
30
+        $that = $this;
31
+        add_action(
32
+            'rest_api_init',
33
+            function () use ( $that ) {
34
+                $that->register_get_all_videos_route();
35
+                $that->register_save_all_videos_route();
36
+                $that->register_get_sync_state_endpoint();
37
+                $that->register_background_process_start_endpoint();
38
+                $that->register_background_process_stop_endpoint();
39
+            }
40
+        );
41
+    }
42
+
43
+    public function get_all_videos( $request ) {
44
+        $data    = $request->get_params();
45
+        $post_id = (int) $data['post_id'];
46
+        $storage = Video_Storage_Factory::get_storage();
47
+
48
+        return $storage->get_all_videos( $post_id );
49
+    }
50
+
51
+    public function save_all_videos( $request ) {
52
+        $data    = $request->get_params();
53
+        $post_id = (int) $data['post_id'];
54
+        $videos  = (array) $data['videos'];
55
+        if ( ! $videos ) {
56
+            return;
57
+        }
58
+        $storage = Video_Storage_Factory::get_storage();
59
+        $storage->remove_all_videos( $post_id );
60
+
61
+        foreach ( $videos as $video ) {
62
+            $video_obj = new Video();
63
+            $video_obj->from( (array) $video );
64
+            $storage->add_video( $post_id, $video_obj );
65
+        }
66
+
67
+    }
68
+
69
+    private function register_get_all_videos_route() {
70
+        register_rest_route(
71
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
72
+            '/videos',
73
+            array(
74
+                'methods'             => WP_REST_Server::CREATABLE,
75
+                'callback'            => array( $this, 'get_all_videos' ),
76
+                'permission_callback' => function () {
77
+                    return current_user_can( 'manage_options' );
78
+                },
79
+                'args'                => array(
80
+                    'post_id' => array(
81
+                        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
82
+                        'validate_callback' => function ( $param, $request, $key ) {
83
+                            return is_numeric( $param ) && $param;
84
+                        },
85
+                        'required'          => true,
86
+                    ),
87
+                ),
88
+            )
89
+        );
90
+    }
91
+
92
+    private function register_save_all_videos_route() {
93
+        register_rest_route(
94
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
95
+            '/videos/save',
96
+            array(
97
+                'methods'             => WP_REST_Server::CREATABLE,
98
+                'callback'            => array( $this, 'save_all_videos' ),
99
+                'permission_callback' => function () {
100
+                    return current_user_can( 'manage_options' );
101
+                },
102
+                'args'                => array(
103
+                    'post_id' => array(
104
+                        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
105
+                        'validate_callback' => function ( $param, $request, $key ) {
106
+                            return is_numeric( $param ) && $param;
107
+                        },
108
+                        'required'          => true,
109
+                    ),
110
+                    'videos'  => array(
111
+                        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
112
+                        'validate_callback' => function ( $param, $request, $key ) {
113
+                            return is_array( $param ) && $param;
114
+                        },
115
+                        'required'          => true,
116
+                    ),
117
+                ),
118
+            )
119
+        );
120
+    }
121
+
122
+    public function register_get_sync_state_endpoint() {
123
+        $that = $this;
124
+        register_rest_route(
125
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
126
+            '/videos/background/get_state',
127
+            array(
128
+                'methods'             => WP_REST_Server::CREATABLE,
129
+                'callback'            => function () use ( $that ) {
130
+                    return $that->background_process->get_state()->get_array();
131
+                },
132
+                'permission_callback' => function () {
133
+                    return current_user_can( 'manage_options' );
134
+                },
135
+            )
136
+        );
137
+
138
+    }
139
+
140
+    public function register_background_process_start_endpoint() {
141
+        $that = $this;
142
+        register_rest_route(
143
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
144
+            '/videos/background/start',
145
+            array(
146
+                'methods'             => WP_REST_Server::CREATABLE,
147
+                'callback'            => function () use ( $that ) {
148
+                    $that->background_process->start();
149
+                },
150
+                'permission_callback' => function () {
151
+                    return current_user_can( 'manage_options' );
152
+                },
153
+            )
154
+        );
155
+
156
+    }
157
+
158
+    public function register_background_process_stop_endpoint() {
159
+        $that = $this;
160
+        register_rest_route(
161
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
162
+            '/videos/background/stop',
163
+            array(
164
+                'methods'             => WP_REST_Server::CREATABLE,
165
+                'callback'            => function () use ( $that ) {
166
+                    $that->background_process->cancel();
167
+                },
168
+                'permission_callback' => function () {
169
+                    return current_user_can( 'manage_options' );
170
+                },
171
+            )
172
+        );
173
+
174
+    }
175 175
 
176 176
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param $background_process Videoobject_Background_Process
24 24
 	 */
25
-	public function __construct( $background_process ) {
25
+	public function __construct($background_process) {
26 26
 		$this->background_process = $background_process;
27 27
 	}
28 28
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 		$that = $this;
31 31
 		add_action(
32 32
 			'rest_api_init',
33
-			function () use ( $that ) {
33
+			function() use ($that) {
34 34
 				$that->register_get_all_videos_route();
35 35
 				$that->register_save_all_videos_route();
36 36
 				$that->register_get_sync_state_endpoint();
@@ -40,28 +40,28 @@  discard block
 block discarded – undo
40 40
 		);
41 41
 	}
42 42
 
43
-	public function get_all_videos( $request ) {
43
+	public function get_all_videos($request) {
44 44
 		$data    = $request->get_params();
45 45
 		$post_id = (int) $data['post_id'];
46 46
 		$storage = Video_Storage_Factory::get_storage();
47 47
 
48
-		return $storage->get_all_videos( $post_id );
48
+		return $storage->get_all_videos($post_id);
49 49
 	}
50 50
 
51
-	public function save_all_videos( $request ) {
51
+	public function save_all_videos($request) {
52 52
 		$data    = $request->get_params();
53 53
 		$post_id = (int) $data['post_id'];
54 54
 		$videos  = (array) $data['videos'];
55
-		if ( ! $videos ) {
55
+		if ( ! $videos) {
56 56
 			return;
57 57
 		}
58 58
 		$storage = Video_Storage_Factory::get_storage();
59
-		$storage->remove_all_videos( $post_id );
59
+		$storage->remove_all_videos($post_id);
60 60
 
61
-		foreach ( $videos as $video ) {
61
+		foreach ($videos as $video) {
62 62
 			$video_obj = new Video();
63
-			$video_obj->from( (array) $video );
64
-			$storage->add_video( $post_id, $video_obj );
63
+			$video_obj->from((array) $video);
64
+			$storage->add_video($post_id, $video_obj);
65 65
 		}
66 66
 
67 67
 	}
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
72 72
 			'/videos',
73 73
 			array(
74 74
 				'methods'             => WP_REST_Server::CREATABLE,
75
-				'callback'            => array( $this, 'get_all_videos' ),
76
-				'permission_callback' => function () {
77
-					return current_user_can( 'manage_options' );
75
+				'callback'            => array($this, 'get_all_videos'),
76
+				'permission_callback' => function() {
77
+					return current_user_can('manage_options');
78 78
 				},
79 79
 				'args'                => array(
80 80
 					'post_id' => array(
81 81
 						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
82
-						'validate_callback' => function ( $param, $request, $key ) {
83
-							return is_numeric( $param ) && $param;
82
+						'validate_callback' => function($param, $request, $key) {
83
+							return is_numeric($param) && $param;
84 84
 						},
85 85
 						'required'          => true,
86 86
 					),
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
 			'/videos/save',
96 96
 			array(
97 97
 				'methods'             => WP_REST_Server::CREATABLE,
98
-				'callback'            => array( $this, 'save_all_videos' ),
99
-				'permission_callback' => function () {
100
-					return current_user_can( 'manage_options' );
98
+				'callback'            => array($this, 'save_all_videos'),
99
+				'permission_callback' => function() {
100
+					return current_user_can('manage_options');
101 101
 				},
102 102
 				'args'                => array(
103 103
 					'post_id' => array(
104 104
 						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
105
-						'validate_callback' => function ( $param, $request, $key ) {
106
-							return is_numeric( $param ) && $param;
105
+						'validate_callback' => function($param, $request, $key) {
106
+							return is_numeric($param) && $param;
107 107
 						},
108 108
 						'required'          => true,
109 109
 					),
110 110
 					'videos'  => array(
111 111
 						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
112
-						'validate_callback' => function ( $param, $request, $key ) {
113
-							return is_array( $param ) && $param;
112
+						'validate_callback' => function($param, $request, $key) {
113
+							return is_array($param) && $param;
114 114
 						},
115 115
 						'required'          => true,
116 116
 					),
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
 			'/videos/background/get_state',
127 127
 			array(
128 128
 				'methods'             => WP_REST_Server::CREATABLE,
129
-				'callback'            => function () use ( $that ) {
129
+				'callback'            => function() use ($that) {
130 130
 					return $that->background_process->get_state()->get_array();
131 131
 				},
132
-				'permission_callback' => function () {
133
-					return current_user_can( 'manage_options' );
132
+				'permission_callback' => function() {
133
+					return current_user_can('manage_options');
134 134
 				},
135 135
 			)
136 136
 		);
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 			'/videos/background/start',
145 145
 			array(
146 146
 				'methods'             => WP_REST_Server::CREATABLE,
147
-				'callback'            => function () use ( $that ) {
147
+				'callback'            => function() use ($that) {
148 148
 					$that->background_process->start();
149 149
 				},
150
-				'permission_callback' => function () {
151
-					return current_user_can( 'manage_options' );
150
+				'permission_callback' => function() {
151
+					return current_user_can('manage_options');
152 152
 				},
153 153
 			)
154 154
 		);
@@ -162,11 +162,11 @@  discard block
 block discarded – undo
162 162
 			'/videos/background/stop',
163 163
 			array(
164 164
 				'methods'             => WP_REST_Server::CREATABLE,
165
-				'callback'            => function () use ( $that ) {
165
+				'callback'            => function() use ($that) {
166 166
 					$that->background_process->cancel();
167 167
 				},
168
-				'permission_callback' => function () {
169
-					return current_user_can( 'manage_options' );
168
+				'permission_callback' => function() {
169
+					return current_user_can('manage_options');
170 170
 				},
171 171
 			)
172 172
 		);
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/class-youtube.php 2 patches
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -11,134 +11,134 @@
 block discarded – undo
11 11
 
12 12
 class Youtube extends Api_Provider {
13 13
 
14
-	const YT_API_FIELD_NAME = '__wl_video_object_youtube_api_key';
15
-
16
-	private static function get_thumbnails( $api_thumbnail_data ) {
17
-		return array_map(
18
-			function ( $item ) {
19
-				return $item['url'];
20
-
21
-			},
22
-			$api_thumbnail_data
23
-		);
24
-	}
25
-
26
-	public function get_videos_data( $videos ) {
27
-		$urls = array_map(
28
-			function ( $video ) {
29
-				/**
30
-				 * @param $video Video
31
-				 */
32
-				return $video->get_url();
33
-			},
34
-			$videos
35
-		);
36
-
37
-		return $this->get_data( $urls );
38
-
39
-	}
40
-
41
-	/**
42
-	 * @param $video_urls
43
-	 *
44
-	 * @return bool | array<Video>
45
-	 */
46
-	public function get_data( $video_urls ) {
47
-		// extract ids from the url list.
48
-		if ( ! is_array( $video_urls ) ) {
49
-			return array();
50
-		}
51
-		$response_body = $this->api_client->get_data( $video_urls );
52
-
53
-		return $this->parse_youtube_video_data_from_response( $response_body );
54
-	}
55
-
56
-	/**
57
-	 * @param $response_body string
58
-	 *
59
-	 * @return array<Video>
60
-	 */
61
-	private function parse_youtube_video_data_from_response( $response_body ) {
62
-		$result = json_decode( $response_body, true );
63
-		if ( ! is_array( $result ) ) {
64
-			// Return empty array since the response body is invalid.
65
-			return array();
66
-		}
67
-		if ( ! array_key_exists( 'items', $result ) ) {
68
-			return array();
69
-		}
70
-		$videos_json_data = $result['items'];
71
-		$videos           = array();
72
-		foreach ( $videos_json_data as $single_video_json_data ) {
73
-			$videos[] = self::create_video_from_youtube_data( $single_video_json_data );
74
-		}
75
-
76
-		return $videos;
77
-	}
78
-
79
-	public static function create_video_from_youtube_data( $video_data ) {
80
-
81
-		$video = new Video();
82
-		if ( array_key_exists( 'contentDetails', $video_data ) ) {
83
-			$video->duration = $video_data['contentDetails']['duration'];
84
-		}
85
-
86
-		if ( array_key_exists( 'id', $video_data ) ) {
87
-			$video_id           = $video_data['id'];
88
-			$video->embed_url   = "https://www.youtube.com/embed/${video_id}";
89
-			$video->content_url = "https://www.youtube.com/watch?v=${video_id}";
90
-		}
91
-		if ( ! array_key_exists( 'snippet', $video_data ) ) {
92
-			return false;
93
-		}
94
-
95
-		$video->name        = $video_data['snippet']['title'];
96
-		$video->description = $video_data['snippet']['description'];
97
-
98
-		/**
99
-		 * @since 3.30.0
100
-		 * Use title as fallback if description is not present.
101
-		 */
102
-		if ( ! $video->description ) {
103
-			$video->description = $video->name;
104
-		}
105
-
106
-		$video->upload_date = $video_data['snippet']['publishedAt'];
107
-
108
-		if ( array_key_exists( 'thumbnails', $video_data['snippet'] ) ) {
109
-			$api_thumbnail_data    = array_values( $video_data['snippet']['thumbnails'] );
110
-			$video->thumbnail_urls = self::get_thumbnails( $api_thumbnail_data );
111
-		}
112
-
113
-		if ( array_key_exists( 'statistics', $video_data )
114
-			 && array_key_exists( 'viewCount', $video_data['statistics'] ) ) {
115
-			$video->views = $video_data['statistics']['viewCount'];
116
-		}
117
-
118
-		if ( array_key_exists( 'liveStreamingDetails', $video_data ) &&
119
-			 array_key_exists( 'scheduledStartTime', $video_data['liveStreamingDetails'] ) ) {
120
-			$video->is_live_video         = true;
121
-			$video->live_video_start_date = $video_data['liveStreamingDetails']['scheduledStartTime'];
122
-			try {
123
-				$end_date = new \DateTime( $video->live_video_start_date );
124
-				/**
125
-				 * the google doc says :
126
-				 * It is required to provide the endDate once the video has finished and is no longer live.
127
-				 * If the expected endDate is unknown prior to the livestream starting, we recommend providing an approximate endDate.
128
-				 */
129
-				// we add 1 day to start date
130
-				$end_date->add( new DateInterval( 'P1D' ) );
131
-				$video->live_video_end_date = $end_date->format( 'c' );
132
-			// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
133
-			} catch ( \Exception $e ) {
134
-				// No need to do anything here.
135
-			}
136
-		}
137
-
138
-		$video->id = $video->content_url;
139
-
140
-		return $video;
141
-
142
-	}
14
+    const YT_API_FIELD_NAME = '__wl_video_object_youtube_api_key';
15
+
16
+    private static function get_thumbnails( $api_thumbnail_data ) {
17
+        return array_map(
18
+            function ( $item ) {
19
+                return $item['url'];
20
+
21
+            },
22
+            $api_thumbnail_data
23
+        );
24
+    }
25
+
26
+    public function get_videos_data( $videos ) {
27
+        $urls = array_map(
28
+            function ( $video ) {
29
+                /**
30
+                 * @param $video Video
31
+                 */
32
+                return $video->get_url();
33
+            },
34
+            $videos
35
+        );
36
+
37
+        return $this->get_data( $urls );
38
+
39
+    }
40
+
41
+    /**
42
+     * @param $video_urls
43
+     *
44
+     * @return bool | array<Video>
45
+     */
46
+    public function get_data( $video_urls ) {
47
+        // extract ids from the url list.
48
+        if ( ! is_array( $video_urls ) ) {
49
+            return array();
50
+        }
51
+        $response_body = $this->api_client->get_data( $video_urls );
52
+
53
+        return $this->parse_youtube_video_data_from_response( $response_body );
54
+    }
55
+
56
+    /**
57
+     * @param $response_body string
58
+     *
59
+     * @return array<Video>
60
+     */
61
+    private function parse_youtube_video_data_from_response( $response_body ) {
62
+        $result = json_decode( $response_body, true );
63
+        if ( ! is_array( $result ) ) {
64
+            // Return empty array since the response body is invalid.
65
+            return array();
66
+        }
67
+        if ( ! array_key_exists( 'items', $result ) ) {
68
+            return array();
69
+        }
70
+        $videos_json_data = $result['items'];
71
+        $videos           = array();
72
+        foreach ( $videos_json_data as $single_video_json_data ) {
73
+            $videos[] = self::create_video_from_youtube_data( $single_video_json_data );
74
+        }
75
+
76
+        return $videos;
77
+    }
78
+
79
+    public static function create_video_from_youtube_data( $video_data ) {
80
+
81
+        $video = new Video();
82
+        if ( array_key_exists( 'contentDetails', $video_data ) ) {
83
+            $video->duration = $video_data['contentDetails']['duration'];
84
+        }
85
+
86
+        if ( array_key_exists( 'id', $video_data ) ) {
87
+            $video_id           = $video_data['id'];
88
+            $video->embed_url   = "https://www.youtube.com/embed/${video_id}";
89
+            $video->content_url = "https://www.youtube.com/watch?v=${video_id}";
90
+        }
91
+        if ( ! array_key_exists( 'snippet', $video_data ) ) {
92
+            return false;
93
+        }
94
+
95
+        $video->name        = $video_data['snippet']['title'];
96
+        $video->description = $video_data['snippet']['description'];
97
+
98
+        /**
99
+         * @since 3.30.0
100
+         * Use title as fallback if description is not present.
101
+         */
102
+        if ( ! $video->description ) {
103
+            $video->description = $video->name;
104
+        }
105
+
106
+        $video->upload_date = $video_data['snippet']['publishedAt'];
107
+
108
+        if ( array_key_exists( 'thumbnails', $video_data['snippet'] ) ) {
109
+            $api_thumbnail_data    = array_values( $video_data['snippet']['thumbnails'] );
110
+            $video->thumbnail_urls = self::get_thumbnails( $api_thumbnail_data );
111
+        }
112
+
113
+        if ( array_key_exists( 'statistics', $video_data )
114
+             && array_key_exists( 'viewCount', $video_data['statistics'] ) ) {
115
+            $video->views = $video_data['statistics']['viewCount'];
116
+        }
117
+
118
+        if ( array_key_exists( 'liveStreamingDetails', $video_data ) &&
119
+             array_key_exists( 'scheduledStartTime', $video_data['liveStreamingDetails'] ) ) {
120
+            $video->is_live_video         = true;
121
+            $video->live_video_start_date = $video_data['liveStreamingDetails']['scheduledStartTime'];
122
+            try {
123
+                $end_date = new \DateTime( $video->live_video_start_date );
124
+                /**
125
+                 * the google doc says :
126
+                 * It is required to provide the endDate once the video has finished and is no longer live.
127
+                 * If the expected endDate is unknown prior to the livestream starting, we recommend providing an approximate endDate.
128
+                 */
129
+                // we add 1 day to start date
130
+                $end_date->add( new DateInterval( 'P1D' ) );
131
+                $video->live_video_end_date = $end_date->format( 'c' );
132
+            // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
133
+            } catch ( \Exception $e ) {
134
+                // No need to do anything here.
135
+            }
136
+        }
137
+
138
+        $video->id = $video->content_url;
139
+
140
+        return $video;
141
+
142
+    }
143 143
 
144 144
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
 
14 14
 	const YT_API_FIELD_NAME = '__wl_video_object_youtube_api_key';
15 15
 
16
-	private static function get_thumbnails( $api_thumbnail_data ) {
16
+	private static function get_thumbnails($api_thumbnail_data) {
17 17
 		return array_map(
18
-			function ( $item ) {
18
+			function($item) {
19 19
 				return $item['url'];
20 20
 
21 21
 			},
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
 		);
24 24
 	}
25 25
 
26
-	public function get_videos_data( $videos ) {
26
+	public function get_videos_data($videos) {
27 27
 		$urls = array_map(
28
-			function ( $video ) {
28
+			function($video) {
29 29
 				/**
30 30
 				 * @param $video Video
31 31
 				 */
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 			$videos
35 35
 		);
36 36
 
37
-		return $this->get_data( $urls );
37
+		return $this->get_data($urls);
38 38
 
39 39
 	}
40 40
 
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @return bool | array<Video>
45 45
 	 */
46
-	public function get_data( $video_urls ) {
46
+	public function get_data($video_urls) {
47 47
 		// extract ids from the url list.
48
-		if ( ! is_array( $video_urls ) ) {
48
+		if ( ! is_array($video_urls)) {
49 49
 			return array();
50 50
 		}
51
-		$response_body = $this->api_client->get_data( $video_urls );
51
+		$response_body = $this->api_client->get_data($video_urls);
52 52
 
53
-		return $this->parse_youtube_video_data_from_response( $response_body );
53
+		return $this->parse_youtube_video_data_from_response($response_body);
54 54
 	}
55 55
 
56 56
 	/**
@@ -58,37 +58,37 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 * @return array<Video>
60 60
 	 */
61
-	private function parse_youtube_video_data_from_response( $response_body ) {
62
-		$result = json_decode( $response_body, true );
63
-		if ( ! is_array( $result ) ) {
61
+	private function parse_youtube_video_data_from_response($response_body) {
62
+		$result = json_decode($response_body, true);
63
+		if ( ! is_array($result)) {
64 64
 			// Return empty array since the response body is invalid.
65 65
 			return array();
66 66
 		}
67
-		if ( ! array_key_exists( 'items', $result ) ) {
67
+		if ( ! array_key_exists('items', $result)) {
68 68
 			return array();
69 69
 		}
70 70
 		$videos_json_data = $result['items'];
71 71
 		$videos           = array();
72
-		foreach ( $videos_json_data as $single_video_json_data ) {
73
-			$videos[] = self::create_video_from_youtube_data( $single_video_json_data );
72
+		foreach ($videos_json_data as $single_video_json_data) {
73
+			$videos[] = self::create_video_from_youtube_data($single_video_json_data);
74 74
 		}
75 75
 
76 76
 		return $videos;
77 77
 	}
78 78
 
79
-	public static function create_video_from_youtube_data( $video_data ) {
79
+	public static function create_video_from_youtube_data($video_data) {
80 80
 
81 81
 		$video = new Video();
82
-		if ( array_key_exists( 'contentDetails', $video_data ) ) {
82
+		if (array_key_exists('contentDetails', $video_data)) {
83 83
 			$video->duration = $video_data['contentDetails']['duration'];
84 84
 		}
85 85
 
86
-		if ( array_key_exists( 'id', $video_data ) ) {
86
+		if (array_key_exists('id', $video_data)) {
87 87
 			$video_id           = $video_data['id'];
88 88
 			$video->embed_url   = "https://www.youtube.com/embed/${video_id}";
89 89
 			$video->content_url = "https://www.youtube.com/watch?v=${video_id}";
90 90
 		}
91
-		if ( ! array_key_exists( 'snippet', $video_data ) ) {
91
+		if ( ! array_key_exists('snippet', $video_data)) {
92 92
 			return false;
93 93
 		}
94 94
 
@@ -99,38 +99,38 @@  discard block
 block discarded – undo
99 99
 		 * @since 3.30.0
100 100
 		 * Use title as fallback if description is not present.
101 101
 		 */
102
-		if ( ! $video->description ) {
102
+		if ( ! $video->description) {
103 103
 			$video->description = $video->name;
104 104
 		}
105 105
 
106 106
 		$video->upload_date = $video_data['snippet']['publishedAt'];
107 107
 
108
-		if ( array_key_exists( 'thumbnails', $video_data['snippet'] ) ) {
109
-			$api_thumbnail_data    = array_values( $video_data['snippet']['thumbnails'] );
110
-			$video->thumbnail_urls = self::get_thumbnails( $api_thumbnail_data );
108
+		if (array_key_exists('thumbnails', $video_data['snippet'])) {
109
+			$api_thumbnail_data    = array_values($video_data['snippet']['thumbnails']);
110
+			$video->thumbnail_urls = self::get_thumbnails($api_thumbnail_data);
111 111
 		}
112 112
 
113
-		if ( array_key_exists( 'statistics', $video_data )
114
-			 && array_key_exists( 'viewCount', $video_data['statistics'] ) ) {
113
+		if (array_key_exists('statistics', $video_data)
114
+			 && array_key_exists('viewCount', $video_data['statistics'])) {
115 115
 			$video->views = $video_data['statistics']['viewCount'];
116 116
 		}
117 117
 
118
-		if ( array_key_exists( 'liveStreamingDetails', $video_data ) &&
119
-			 array_key_exists( 'scheduledStartTime', $video_data['liveStreamingDetails'] ) ) {
118
+		if (array_key_exists('liveStreamingDetails', $video_data) &&
119
+			 array_key_exists('scheduledStartTime', $video_data['liveStreamingDetails'])) {
120 120
 			$video->is_live_video         = true;
121 121
 			$video->live_video_start_date = $video_data['liveStreamingDetails']['scheduledStartTime'];
122 122
 			try {
123
-				$end_date = new \DateTime( $video->live_video_start_date );
123
+				$end_date = new \DateTime($video->live_video_start_date);
124 124
 				/**
125 125
 				 * the google doc says :
126 126
 				 * It is required to provide the endDate once the video has finished and is no longer live.
127 127
 				 * If the expected endDate is unknown prior to the livestream starting, we recommend providing an approximate endDate.
128 128
 				 */
129 129
 				// we add 1 day to start date
130
-				$end_date->add( new DateInterval( 'P1D' ) );
131
-				$video->live_video_end_date = $end_date->format( 'c' );
130
+				$end_date->add(new DateInterval('P1D'));
131
+				$video->live_video_end_date = $end_date->format('c');
132 132
 			// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
133
-			} catch ( \Exception $e ) {
133
+			} catch (\Exception $e) {
134 134
 				// No need to do anything here.
135 135
 			}
136 136
 		}
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/class-provider-factory.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -10,21 +10,21 @@
 block discarded – undo
10 10
  */
11 11
 class Provider_Factory {
12 12
 
13
-	const YOUTUBE = 'youtube';
13
+    const YOUTUBE = 'youtube';
14 14
 
15
-	const VIMEO = 'vimeo';
15
+    const VIMEO = 'vimeo';
16 16
 
17
-	const JWPLAYER = 'jwplayer';
17
+    const JWPLAYER = 'jwplayer';
18 18
 
19
-	public static function get_provider( $provider_name ) {
20
-		if ( self::YOUTUBE === $provider_name ) {
21
-			return new Youtube( Client_Factory::get_client( Client_Factory::YOUTUBE ) );
22
-		} elseif ( self::VIMEO === $provider_name ) {
23
-			return new Vimeo( Client_Factory::get_client( Client_Factory::VIMEO ) );
24
-		} elseif ( self::JWPLAYER === $provider_name ) {
25
-			return new Jw_Player( Client_Factory::get_client( Client_Factory::JWPLAYER ) );
26
-		}
19
+    public static function get_provider( $provider_name ) {
20
+        if ( self::YOUTUBE === $provider_name ) {
21
+            return new Youtube( Client_Factory::get_client( Client_Factory::YOUTUBE ) );
22
+        } elseif ( self::VIMEO === $provider_name ) {
23
+            return new Vimeo( Client_Factory::get_client( Client_Factory::VIMEO ) );
24
+        } elseif ( self::JWPLAYER === $provider_name ) {
25
+            return new Jw_Player( Client_Factory::get_client( Client_Factory::JWPLAYER ) );
26
+        }
27 27
 
28
-	}
28
+    }
29 29
 
30 30
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@
 block discarded – undo
16 16
 
17 17
 	const JWPLAYER = 'jwplayer';
18 18
 
19
-	public static function get_provider( $provider_name ) {
20
-		if ( self::YOUTUBE === $provider_name ) {
21
-			return new Youtube( Client_Factory::get_client( Client_Factory::YOUTUBE ) );
22
-		} elseif ( self::VIMEO === $provider_name ) {
23
-			return new Vimeo( Client_Factory::get_client( Client_Factory::VIMEO ) );
24
-		} elseif ( self::JWPLAYER === $provider_name ) {
25
-			return new Jw_Player( Client_Factory::get_client( Client_Factory::JWPLAYER ) );
19
+	public static function get_provider($provider_name) {
20
+		if (self::YOUTUBE === $provider_name) {
21
+			return new Youtube(Client_Factory::get_client(Client_Factory::YOUTUBE));
22
+		} elseif (self::VIMEO === $provider_name) {
23
+			return new Vimeo(Client_Factory::get_client(Client_Factory::VIMEO));
24
+		} elseif (self::JWPLAYER === $provider_name) {
25
+			return new Jw_Player(Client_Factory::get_client(Client_Factory::JWPLAYER));
26 26
 		}
27 27
 
28 28
 	}
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/class-vimeo.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -15,97 +15,97 @@
 block discarded – undo
15 15
  */
16 16
 class Vimeo extends Api_Provider {
17 17
 
18
-	const API_FIELD_NAME = '_wl_videoobject_vimeo_api_key';
19
-
20
-	public static function get_api_key() {
21
-		return get_option( self::API_FIELD_NAME, false );
22
-	}
23
-
24
-	public function get_videos_data( $videos ) {
25
-
26
-		$key = $this->get_api_key();
27
-
28
-		if ( ! $key ) {
29
-			return array();
30
-		}
31
-
32
-		$urls = array_map(
33
-			function ( $video ) {
34
-				return $video->get_url();
35
-			},
36
-			$videos
37
-		);
38
-
39
-		$response_body = $this->api_client->get_data( $urls );
40
-
41
-		if ( ! is_string( $response_body ) || ! $response_body ) {
42
-			return array();
43
-		}
44
-
45
-		$response = json_decode( $response_body, true );
46
-
47
-		$video_list = $response['data'];
48
-
49
-		if ( ! is_array( $video_list ) ) {
50
-			// Return if we cant parse the response.
51
-			return array();
52
-		}
53
-
54
-		return array_filter( array_map( array( $this, 'get_video_from_video_data' ), $video_list ) );
55
-
56
-	}
57
-
58
-	public function get_video_from_video_data( $vimeo_video_data ) {
59
-
60
-		if ( ! $vimeo_video_data ) {
61
-			// If valid data not supplied dont init the object.
62
-			return false;
63
-		}
64
-		$video              = new Video();
65
-		$video->name        = $vimeo_video_data['name'];
66
-		$video->description = $vimeo_video_data['description'];
67
-
68
-		$video->content_url = $vimeo_video_data['link'];
69
-		$video->embed_url   = 'https://player.vimeo.com/video/' . $this->get_id( $vimeo_video_data );
70
-		if ( is_numeric( $vimeo_video_data['duration'] ) ) {
71
-			$video->duration = 'PT' . $vimeo_video_data['duration'] . 'S';
72
-		}
73
-		$video->upload_date    = $vimeo_video_data['release_time'];
74
-		$video->thumbnail_urls = $this->set_thumbnail_urls( $vimeo_video_data );
75
-		$video->id             = $video->content_url;
76
-
77
-		if ( array_key_exists( 'stats', $vimeo_video_data )
78
-			 && array_key_exists( 'plays', $vimeo_video_data['stats'] ) ) {
79
-			$video->views = (int) $vimeo_video_data['stats']['plays'];
80
-		}
81
-
82
-		return $video;
83
-	}
84
-
85
-	private function get_id( $api_response_data ) {
86
-		return str_replace( '/videos/', '', $api_response_data['uri'] );
87
-	}
88
-
89
-	private function set_thumbnail_urls( $api_response_data ) {
90
-
91
-		if ( ! array_key_exists( 'pictures', $api_response_data ) || ! array_key_exists(
92
-			'sizes',
93
-			$api_response_data['pictures']
94
-		) ) {
95
-			return array();
96
-		}
97
-		if ( ! is_array( $api_response_data['pictures']['sizes'] ) ) {
98
-			return array();
99
-		}
100
-		$pictures = $api_response_data['pictures']['sizes'];
101
-
102
-		return array_map(
103
-			function ( $picture_data ) {
104
-				return $picture_data['link'];
105
-			},
106
-			$pictures
107
-		);
108
-
109
-	}
18
+    const API_FIELD_NAME = '_wl_videoobject_vimeo_api_key';
19
+
20
+    public static function get_api_key() {
21
+        return get_option( self::API_FIELD_NAME, false );
22
+    }
23
+
24
+    public function get_videos_data( $videos ) {
25
+
26
+        $key = $this->get_api_key();
27
+
28
+        if ( ! $key ) {
29
+            return array();
30
+        }
31
+
32
+        $urls = array_map(
33
+            function ( $video ) {
34
+                return $video->get_url();
35
+            },
36
+            $videos
37
+        );
38
+
39
+        $response_body = $this->api_client->get_data( $urls );
40
+
41
+        if ( ! is_string( $response_body ) || ! $response_body ) {
42
+            return array();
43
+        }
44
+
45
+        $response = json_decode( $response_body, true );
46
+
47
+        $video_list = $response['data'];
48
+
49
+        if ( ! is_array( $video_list ) ) {
50
+            // Return if we cant parse the response.
51
+            return array();
52
+        }
53
+
54
+        return array_filter( array_map( array( $this, 'get_video_from_video_data' ), $video_list ) );
55
+
56
+    }
57
+
58
+    public function get_video_from_video_data( $vimeo_video_data ) {
59
+
60
+        if ( ! $vimeo_video_data ) {
61
+            // If valid data not supplied dont init the object.
62
+            return false;
63
+        }
64
+        $video              = new Video();
65
+        $video->name        = $vimeo_video_data['name'];
66
+        $video->description = $vimeo_video_data['description'];
67
+
68
+        $video->content_url = $vimeo_video_data['link'];
69
+        $video->embed_url   = 'https://player.vimeo.com/video/' . $this->get_id( $vimeo_video_data );
70
+        if ( is_numeric( $vimeo_video_data['duration'] ) ) {
71
+            $video->duration = 'PT' . $vimeo_video_data['duration'] . 'S';
72
+        }
73
+        $video->upload_date    = $vimeo_video_data['release_time'];
74
+        $video->thumbnail_urls = $this->set_thumbnail_urls( $vimeo_video_data );
75
+        $video->id             = $video->content_url;
76
+
77
+        if ( array_key_exists( 'stats', $vimeo_video_data )
78
+             && array_key_exists( 'plays', $vimeo_video_data['stats'] ) ) {
79
+            $video->views = (int) $vimeo_video_data['stats']['plays'];
80
+        }
81
+
82
+        return $video;
83
+    }
84
+
85
+    private function get_id( $api_response_data ) {
86
+        return str_replace( '/videos/', '', $api_response_data['uri'] );
87
+    }
88
+
89
+    private function set_thumbnail_urls( $api_response_data ) {
90
+
91
+        if ( ! array_key_exists( 'pictures', $api_response_data ) || ! array_key_exists(
92
+            'sizes',
93
+            $api_response_data['pictures']
94
+        ) ) {
95
+            return array();
96
+        }
97
+        if ( ! is_array( $api_response_data['pictures']['sizes'] ) ) {
98
+            return array();
99
+        }
100
+        $pictures = $api_response_data['pictures']['sizes'];
101
+
102
+        return array_map(
103
+            function ( $picture_data ) {
104
+                return $picture_data['link'];
105
+            },
106
+            $pictures
107
+        );
108
+
109
+    }
110 110
 
111 111
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@  discard block
 block discarded – undo
18 18
 	const API_FIELD_NAME = '_wl_videoobject_vimeo_api_key';
19 19
 
20 20
 	public static function get_api_key() {
21
-		return get_option( self::API_FIELD_NAME, false );
21
+		return get_option(self::API_FIELD_NAME, false);
22 22
 	}
23 23
 
24
-	public function get_videos_data( $videos ) {
24
+	public function get_videos_data($videos) {
25 25
 
26 26
 		$key = $this->get_api_key();
27 27
 
28
-		if ( ! $key ) {
28
+		if ( ! $key) {
29 29
 			return array();
30 30
 		}
31 31
 
32 32
 		$urls = array_map(
33
-			function ( $video ) {
33
+			function($video) {
34 34
 				return $video->get_url();
35 35
 			},
36 36
 			$videos
37 37
 		);
38 38
 
39
-		$response_body = $this->api_client->get_data( $urls );
39
+		$response_body = $this->api_client->get_data($urls);
40 40
 
41
-		if ( ! is_string( $response_body ) || ! $response_body ) {
41
+		if ( ! is_string($response_body) || ! $response_body) {
42 42
 			return array();
43 43
 		}
44 44
 
45
-		$response = json_decode( $response_body, true );
45
+		$response = json_decode($response_body, true);
46 46
 
47 47
 		$video_list = $response['data'];
48 48
 
49
-		if ( ! is_array( $video_list ) ) {
49
+		if ( ! is_array($video_list)) {
50 50
 			// Return if we cant parse the response.
51 51
 			return array();
52 52
 		}
53 53
 
54
-		return array_filter( array_map( array( $this, 'get_video_from_video_data' ), $video_list ) );
54
+		return array_filter(array_map(array($this, 'get_video_from_video_data'), $video_list));
55 55
 
56 56
 	}
57 57
 
58
-	public function get_video_from_video_data( $vimeo_video_data ) {
58
+	public function get_video_from_video_data($vimeo_video_data) {
59 59
 
60
-		if ( ! $vimeo_video_data ) {
60
+		if ( ! $vimeo_video_data) {
61 61
 			// If valid data not supplied dont init the object.
62 62
 			return false;
63 63
 		}
@@ -66,41 +66,41 @@  discard block
 block discarded – undo
66 66
 		$video->description = $vimeo_video_data['description'];
67 67
 
68 68
 		$video->content_url = $vimeo_video_data['link'];
69
-		$video->embed_url   = 'https://player.vimeo.com/video/' . $this->get_id( $vimeo_video_data );
70
-		if ( is_numeric( $vimeo_video_data['duration'] ) ) {
71
-			$video->duration = 'PT' . $vimeo_video_data['duration'] . 'S';
69
+		$video->embed_url   = 'https://player.vimeo.com/video/'.$this->get_id($vimeo_video_data);
70
+		if (is_numeric($vimeo_video_data['duration'])) {
71
+			$video->duration = 'PT'.$vimeo_video_data['duration'].'S';
72 72
 		}
73 73
 		$video->upload_date    = $vimeo_video_data['release_time'];
74
-		$video->thumbnail_urls = $this->set_thumbnail_urls( $vimeo_video_data );
74
+		$video->thumbnail_urls = $this->set_thumbnail_urls($vimeo_video_data);
75 75
 		$video->id             = $video->content_url;
76 76
 
77
-		if ( array_key_exists( 'stats', $vimeo_video_data )
78
-			 && array_key_exists( 'plays', $vimeo_video_data['stats'] ) ) {
77
+		if (array_key_exists('stats', $vimeo_video_data)
78
+			 && array_key_exists('plays', $vimeo_video_data['stats'])) {
79 79
 			$video->views = (int) $vimeo_video_data['stats']['plays'];
80 80
 		}
81 81
 
82 82
 		return $video;
83 83
 	}
84 84
 
85
-	private function get_id( $api_response_data ) {
86
-		return str_replace( '/videos/', '', $api_response_data['uri'] );
85
+	private function get_id($api_response_data) {
86
+		return str_replace('/videos/', '', $api_response_data['uri']);
87 87
 	}
88 88
 
89
-	private function set_thumbnail_urls( $api_response_data ) {
89
+	private function set_thumbnail_urls($api_response_data) {
90 90
 
91
-		if ( ! array_key_exists( 'pictures', $api_response_data ) || ! array_key_exists(
91
+		if ( ! array_key_exists('pictures', $api_response_data) || ! array_key_exists(
92 92
 			'sizes',
93 93
 			$api_response_data['pictures']
94
-		) ) {
94
+		)) {
95 95
 			return array();
96 96
 		}
97
-		if ( ! is_array( $api_response_data['pictures']['sizes'] ) ) {
97
+		if ( ! is_array($api_response_data['pictures']['sizes'])) {
98 98
 			return array();
99 99
 		}
100 100
 		$pictures = $api_response_data['pictures']['sizes'];
101 101
 
102 102
 		return array_map(
103
-			function ( $picture_data ) {
103
+			function($picture_data) {
104 104
 				return $picture_data['link'];
105 105
 			},
106 106
 			$pictures
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/class-jw-player.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -11,81 +11,81 @@
 block discarded – undo
11 11
 
12 12
 class Jw_Player extends Api_Provider {
13 13
 
14
-	/**
15
-	 * @param $videos array<Embedded_Video>
16
-	 *
17
-	 * @return array<Video>
18
-	 */
19
-	public function get_videos_data( $videos ) {
20
-
21
-		$video_urls = array_map(
22
-			function ( $video ) {
23
-				return $video->get_url();
24
-			},
25
-			$videos
26
-		);
27
-
28
-		$videos_data = $this->api_client->get_data( $video_urls );
29
-
30
-		return array_filter(
31
-			array_map(
32
-				function ( $video_data ) {
33
-
34
-					if ( ! array_key_exists( 'playlist', $video_data )
35
-
36
-					|| ! is_array( $video_data['playlist'] )
37
-
38
-					|| count( $video_data['playlist'] ) === 0 ) {
39
-
40
-						  return false;
41
-
42
-					}
43
-
44
-					$video                 = new Video();
45
-					$video->id             = $video_data['id'];
46
-					$playlist_item_data    = $video_data['playlist'][0];
47
-					$video->name           = $playlist_item_data['title'];
48
-					$video->description    = $playlist_item_data['description'];
49
-					$video->thumbnail_urls = array_filter(
50
-						array_map(
51
-							function ( $item ) {
52
-								return $item['src'];
53
-							},
54
-							$playlist_item_data['images']
55
-						)
56
-					);
57
-
58
-					$video->duration    = 'PT' . (int) $playlist_item_data['duration'] . 'S';
59
-					$video->upload_date = gmdate( 'c', (int) $playlist_item_data['pubdate'] );
60
-
61
-					$video_content_urls_data = array_filter(
62
-						$playlist_item_data['sources'],
63
-						function ( $item ) {
64
-							return strpos( $item['type'], 'video/' ) !== false;
65
-						}
66
-					);
67
-
68
-					$video_content_urls = array_map(
69
-						function ( $item ) {
70
-							return $item['file'];
71
-						},
72
-						$video_content_urls_data
73
-					);
74
-
75
-					// Content url is a single field, so we pick the video with
76
-					// high resolution.
77
-					$video->content_url = array_pop( $video_content_urls );
78
-
79
-					// We dont have embed url for JW Player.
80
-					$video->embed_url = '';
81
-
82
-					return $video;
83
-
84
-				},
85
-				$videos_data
86
-			)
87
-		);
88
-
89
-	}
14
+    /**
15
+     * @param $videos array<Embedded_Video>
16
+     *
17
+     * @return array<Video>
18
+     */
19
+    public function get_videos_data( $videos ) {
20
+
21
+        $video_urls = array_map(
22
+            function ( $video ) {
23
+                return $video->get_url();
24
+            },
25
+            $videos
26
+        );
27
+
28
+        $videos_data = $this->api_client->get_data( $video_urls );
29
+
30
+        return array_filter(
31
+            array_map(
32
+                function ( $video_data ) {
33
+
34
+                    if ( ! array_key_exists( 'playlist', $video_data )
35
+
36
+                    || ! is_array( $video_data['playlist'] )
37
+
38
+                    || count( $video_data['playlist'] ) === 0 ) {
39
+
40
+                            return false;
41
+
42
+                    }
43
+
44
+                    $video                 = new Video();
45
+                    $video->id             = $video_data['id'];
46
+                    $playlist_item_data    = $video_data['playlist'][0];
47
+                    $video->name           = $playlist_item_data['title'];
48
+                    $video->description    = $playlist_item_data['description'];
49
+                    $video->thumbnail_urls = array_filter(
50
+                        array_map(
51
+                            function ( $item ) {
52
+                                return $item['src'];
53
+                            },
54
+                            $playlist_item_data['images']
55
+                        )
56
+                    );
57
+
58
+                    $video->duration    = 'PT' . (int) $playlist_item_data['duration'] . 'S';
59
+                    $video->upload_date = gmdate( 'c', (int) $playlist_item_data['pubdate'] );
60
+
61
+                    $video_content_urls_data = array_filter(
62
+                        $playlist_item_data['sources'],
63
+                        function ( $item ) {
64
+                            return strpos( $item['type'], 'video/' ) !== false;
65
+                        }
66
+                    );
67
+
68
+                    $video_content_urls = array_map(
69
+                        function ( $item ) {
70
+                            return $item['file'];
71
+                        },
72
+                        $video_content_urls_data
73
+                    );
74
+
75
+                    // Content url is a single field, so we pick the video with
76
+                    // high resolution.
77
+                    $video->content_url = array_pop( $video_content_urls );
78
+
79
+                    // We dont have embed url for JW Player.
80
+                    $video->embed_url = '';
81
+
82
+                    return $video;
83
+
84
+                },
85
+                $videos_data
86
+            )
87
+        );
88
+
89
+    }
90 90
 
91 91
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -16,26 +16,26 @@  discard block
 block discarded – undo
16 16
 	 *
17 17
 	 * @return array<Video>
18 18
 	 */
19
-	public function get_videos_data( $videos ) {
19
+	public function get_videos_data($videos) {
20 20
 
21 21
 		$video_urls = array_map(
22
-			function ( $video ) {
22
+			function($video) {
23 23
 				return $video->get_url();
24 24
 			},
25 25
 			$videos
26 26
 		);
27 27
 
28
-		$videos_data = $this->api_client->get_data( $video_urls );
28
+		$videos_data = $this->api_client->get_data($video_urls);
29 29
 
30 30
 		return array_filter(
31 31
 			array_map(
32
-				function ( $video_data ) {
32
+				function($video_data) {
33 33
 
34
-					if ( ! array_key_exists( 'playlist', $video_data )
34
+					if ( ! array_key_exists('playlist', $video_data)
35 35
 
36
-					|| ! is_array( $video_data['playlist'] )
36
+					|| ! is_array($video_data['playlist'])
37 37
 
38
-					|| count( $video_data['playlist'] ) === 0 ) {
38
+					|| count($video_data['playlist']) === 0) {
39 39
 
40 40
 						  return false;
41 41
 
@@ -48,25 +48,25 @@  discard block
 block discarded – undo
48 48
 					$video->description    = $playlist_item_data['description'];
49 49
 					$video->thumbnail_urls = array_filter(
50 50
 						array_map(
51
-							function ( $item ) {
51
+							function($item) {
52 52
 								return $item['src'];
53 53
 							},
54 54
 							$playlist_item_data['images']
55 55
 						)
56 56
 					);
57 57
 
58
-					$video->duration    = 'PT' . (int) $playlist_item_data['duration'] . 'S';
59
-					$video->upload_date = gmdate( 'c', (int) $playlist_item_data['pubdate'] );
58
+					$video->duration    = 'PT'.(int) $playlist_item_data['duration'].'S';
59
+					$video->upload_date = gmdate('c', (int) $playlist_item_data['pubdate']);
60 60
 
61 61
 					$video_content_urls_data = array_filter(
62 62
 						$playlist_item_data['sources'],
63
-						function ( $item ) {
64
-							return strpos( $item['type'], 'video/' ) !== false;
63
+						function($item) {
64
+							return strpos($item['type'], 'video/') !== false;
65 65
 						}
66 66
 					);
67 67
 
68 68
 					$video_content_urls = array_map(
69
-						function ( $item ) {
69
+						function($item) {
70 70
 							return $item['file'];
71 71
 						},
72 72
 						$video_content_urls_data
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 
75 75
 					// Content url is a single field, so we pick the video with
76 76
 					// high resolution.
77
-					$video->content_url = array_pop( $video_content_urls );
77
+					$video->content_url = array_pop($video_content_urls);
78 78
 
79 79
 					// We dont have embed url for JW Player.
80 80
 					$video->embed_url = '';
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/client/class-jw-player-client.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,50 +11,50 @@
 block discarded – undo
11 11
  */
12 12
 class Jw_Player_Client extends Singleton implements Client {
13 13
 
14
-	public function get_data( $video_urls ) {
14
+    public function get_data( $video_urls ) {
15 15
 
16
-		$videos_data = array();
16
+        $videos_data = array();
17 17
 
18
-		foreach ( $video_urls as $video_url ) {
19
-			$data = wp_remote_get( $video_url );
20
-			if ( is_wp_error( $data ) ) {
21
-				continue;
22
-			}
23
-			$json_body = wp_remote_retrieve_body( $data );
18
+        foreach ( $video_urls as $video_url ) {
19
+            $data = wp_remote_get( $video_url );
20
+            if ( is_wp_error( $data ) ) {
21
+                continue;
22
+            }
23
+            $json_body = wp_remote_retrieve_body( $data );
24 24
 
25
-			$video_data = json_decode( $json_body, true );
26
-			if ( ! $video_data ) {
27
-				continue;
28
-			}
29
-			$video_data['id'] = $video_url;
30
-			$videos_data[]    = $video_data;
31
-		}
25
+            $video_data = json_decode( $json_body, true );
26
+            if ( ! $video_data ) {
27
+                continue;
28
+            }
29
+            $video_data['id'] = $video_url;
30
+            $videos_data[]    = $video_data;
31
+        }
32 32
 
33
-		return $videos_data;
33
+        return $videos_data;
34 34
 
35
-	}
35
+    }
36 36
 
37
-	public function get_video_ids( $video_urls ) {
37
+    public function get_video_ids( $video_urls ) {
38 38
 
39
-		return array_filter(
40
-			$video_urls,
41
-			function ( $item ) {
42
-				return strpos( $item, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false;
43
-			}
44
-		);
39
+        return array_filter(
40
+            $video_urls,
41
+            function ( $item ) {
42
+                return strpos( $item, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false;
43
+            }
44
+        );
45 45
 
46
-	}
46
+    }
47 47
 
48
-	public static function get_api_key() {
49
-		// Method not implemented, since we dont need api key
50
-	}
48
+    public static function get_api_key() {
49
+        // Method not implemented, since we dont need api key
50
+    }
51 51
 
52
-	public static function get_api_key_option_name() {
53
-		// Method not implemented, since we dont need api key
54
-	}
52
+    public static function get_api_key_option_name() {
53
+        // Method not implemented, since we dont need api key
54
+    }
55 55
 
56
-	public function get_api_url() {
57
-		// Method not implemented, since we dont need api key
58
-	}
56
+    public function get_api_url() {
57
+        // Method not implemented, since we dont need api key
58
+    }
59 59
 
60 60
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,19 +11,19 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class Jw_Player_Client extends Singleton implements Client {
13 13
 
14
-	public function get_data( $video_urls ) {
14
+	public function get_data($video_urls) {
15 15
 
16 16
 		$videos_data = array();
17 17
 
18
-		foreach ( $video_urls as $video_url ) {
19
-			$data = wp_remote_get( $video_url );
20
-			if ( is_wp_error( $data ) ) {
18
+		foreach ($video_urls as $video_url) {
19
+			$data = wp_remote_get($video_url);
20
+			if (is_wp_error($data)) {
21 21
 				continue;
22 22
 			}
23
-			$json_body = wp_remote_retrieve_body( $data );
23
+			$json_body = wp_remote_retrieve_body($data);
24 24
 
25
-			$video_data = json_decode( $json_body, true );
26
-			if ( ! $video_data ) {
25
+			$video_data = json_decode($json_body, true);
26
+			if ( ! $video_data) {
27 27
 				continue;
28 28
 			}
29 29
 			$video_data['id'] = $video_url;
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 
35 35
 	}
36 36
 
37
-	public function get_video_ids( $video_urls ) {
37
+	public function get_video_ids($video_urls) {
38 38
 
39 39
 		return array_filter(
40 40
 			$video_urls,
41
-			function ( $item ) {
42
-				return strpos( $item, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false;
41
+			function($item) {
42
+				return strpos($item, 'https://cdn.jwplayer.com/v2/media/', 0) !== false;
43 43
 			}
44 44
 		);
45 45
 
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/client/class-client-factory.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -9,20 +9,20 @@
 block discarded – undo
9 9
  */
10 10
 class Client_Factory {
11 11
 
12
-	const YOUTUBE = 'youtube';
12
+    const YOUTUBE = 'youtube';
13 13
 
14
-	const VIMEO = 'vimeo';
14
+    const VIMEO = 'vimeo';
15 15
 
16
-	const JWPLAYER = 'jwplayer';
16
+    const JWPLAYER = 'jwplayer';
17 17
 
18
-	public static function get_client( $config ) {
19
-		if ( self::YOUTUBE === $config ) {
20
-			return Youtube_Client::get_instance();
21
-		} elseif ( self::VIMEO === $config ) {
22
-			return Vimeo_Client::get_instance();
23
-		} elseif ( self::JWPLAYER === $config ) {
24
-			return Jw_Player_Client::get_instance();
25
-		}
18
+    public static function get_client( $config ) {
19
+        if ( self::YOUTUBE === $config ) {
20
+            return Youtube_Client::get_instance();
21
+        } elseif ( self::VIMEO === $config ) {
22
+            return Vimeo_Client::get_instance();
23
+        } elseif ( self::JWPLAYER === $config ) {
24
+            return Jw_Player_Client::get_instance();
25
+        }
26 26
 
27
-	}
27
+    }
28 28
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@
 block discarded – undo
15 15
 
16 16
 	const JWPLAYER = 'jwplayer';
17 17
 
18
-	public static function get_client( $config ) {
19
-		if ( self::YOUTUBE === $config ) {
18
+	public static function get_client($config) {
19
+		if (self::YOUTUBE === $config) {
20 20
 			return Youtube_Client::get_instance();
21
-		} elseif ( self::VIMEO === $config ) {
21
+		} elseif (self::VIMEO === $config) {
22 22
 			return Vimeo_Client::get_instance();
23
-		} elseif ( self::JWPLAYER === $config ) {
23
+		} elseif (self::JWPLAYER === $config) {
24 24
 			return Jw_Player_Client::get_instance();
25 25
 		}
26 26
 
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/client/class-youtube-client.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -11,75 +11,75 @@
 block discarded – undo
11 11
  */
12 12
 class Youtube_Client extends Singleton implements Client {
13 13
 
14
-	const YOUTUBE_REGEX = '/(?:https?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z0-9\_-]+)/m';
14
+    const YOUTUBE_REGEX = '/(?:https?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z0-9\_-]+)/m';
15 15
 
16
-	public static $requests_sent = 0;
16
+    public static $requests_sent = 0;
17 17
 
18
-	public static function get_api_key_option_name() {
19
-		return '__wl_video_object_youtube_api_key';
20
-	}
18
+    public static function get_api_key_option_name() {
19
+        return '__wl_video_object_youtube_api_key';
20
+    }
21 21
 
22
-	public static function get_api_key() {
23
-		return get_option( self::get_api_key_option_name(), false );
24
-	}
22
+    public static function get_api_key() {
23
+        return get_option( self::get_api_key_option_name(), false );
24
+    }
25 25
 
26
-	public function get_api_url() {
27
-		return 'https://www.googleapis.com/youtube/v3/videos';
28
-	}
26
+    public function get_api_url() {
27
+        return 'https://www.googleapis.com/youtube/v3/videos';
28
+    }
29 29
 
30
-	public function get_data( $video_urls ) {
31
-		$video_ids = $this->get_video_ids_as_string( $video_urls );
32
-		$url       = add_query_arg(
33
-			array(
34
-				'part' => 'snippet,contentDetails,statistics,liveStreamingDetails',
35
-				'id'   => $video_ids,
36
-				'key'  => $this->get_api_key(),
37
-			),
38
-			$this->get_api_url()
39
-		);
30
+    public function get_data( $video_urls ) {
31
+        $video_ids = $this->get_video_ids_as_string( $video_urls );
32
+        $url       = add_query_arg(
33
+            array(
34
+                'part' => 'snippet,contentDetails,statistics,liveStreamingDetails',
35
+                'id'   => $video_ids,
36
+                'key'  => $this->get_api_key(),
37
+            ),
38
+            $this->get_api_url()
39
+        );
40 40
 
41
-		$response = wp_remote_get( $url );
41
+        $response = wp_remote_get( $url );
42 42
 
43
-		++ self::$requests_sent;
43
+        ++ self::$requests_sent;
44 44
 
45
-		return wp_remote_retrieve_body( $response );
46
-	}
45
+        return wp_remote_retrieve_body( $response );
46
+    }
47 47
 
48
-	private function get_video_ids_as_string( $video_urls ) {
49
-		// validate the urls.
50
-		$video_urls = array_filter(
51
-			$video_urls,
52
-			function ( $url ) {
53
-				return filter_var( $url, FILTER_VALIDATE_URL );
54
-			}
55
-		);
48
+    private function get_video_ids_as_string( $video_urls ) {
49
+        // validate the urls.
50
+        $video_urls = array_filter(
51
+            $video_urls,
52
+            function ( $url ) {
53
+                return filter_var( $url, FILTER_VALIDATE_URL );
54
+            }
55
+        );
56 56
 
57
-		// extract the video ids.
58
-		return join( ',', $this->get_video_ids( $video_urls ) );
59
-	}
57
+        // extract the video ids.
58
+        return join( ',', $this->get_video_ids( $video_urls ) );
59
+    }
60 60
 
61
-	public function get_video_ids( $video_urls ) {
61
+    public function get_video_ids( $video_urls ) {
62 62
 
63
-		$regex = self::YOUTUBE_REGEX;
63
+        $regex = self::YOUTUBE_REGEX;
64 64
 
65
-		$video_ids = array_map(
66
-			function ( $url ) use ( $regex ) {
67
-				$matches = array();
68
-				preg_match( $regex, $url, $matches );
65
+        $video_ids = array_map(
66
+            function ( $url ) use ( $regex ) {
67
+                $matches = array();
68
+                preg_match( $regex, $url, $matches );
69 69
 
70
-				// Return video id or return false.
71
-				if ( isset( $matches[1] ) && is_string( $matches[1] ) ) {
72
-					  return $matches[1];
73
-				}
70
+                // Return video id or return false.
71
+                if ( isset( $matches[1] ) && is_string( $matches[1] ) ) {
72
+                        return $matches[1];
73
+                }
74 74
 
75
-				return false;
75
+                return false;
76 76
 
77
-			},
78
-			$video_urls
79
-		);
77
+            },
78
+            $video_urls
79
+        );
80 80
 
81
-		return array_values( array_filter( $video_ids ) );
81
+        return array_values( array_filter( $video_ids ) );
82 82
 
83
-	}
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,15 +20,15 @@  discard block
 block discarded – undo
20 20
 	}
21 21
 
22 22
 	public static function get_api_key() {
23
-		return get_option( self::get_api_key_option_name(), false );
23
+		return get_option(self::get_api_key_option_name(), false);
24 24
 	}
25 25
 
26 26
 	public function get_api_url() {
27 27
 		return 'https://www.googleapis.com/youtube/v3/videos';
28 28
 	}
29 29
 
30
-	public function get_data( $video_urls ) {
31
-		$video_ids = $this->get_video_ids_as_string( $video_urls );
30
+	public function get_data($video_urls) {
31
+		$video_ids = $this->get_video_ids_as_string($video_urls);
32 32
 		$url       = add_query_arg(
33 33
 			array(
34 34
 				'part' => 'snippet,contentDetails,statistics,liveStreamingDetails',
@@ -38,37 +38,35 @@  discard block
 block discarded – undo
38 38
 			$this->get_api_url()
39 39
 		);
40 40
 
41
-		$response = wp_remote_get( $url );
41
+		$response = wp_remote_get($url);++ self::$requests_sent;
42 42
 
43
-		++ self::$requests_sent;
44
-
45
-		return wp_remote_retrieve_body( $response );
43
+		return wp_remote_retrieve_body($response);
46 44
 	}
47 45
 
48
-	private function get_video_ids_as_string( $video_urls ) {
46
+	private function get_video_ids_as_string($video_urls) {
49 47
 		// validate the urls.
50 48
 		$video_urls = array_filter(
51 49
 			$video_urls,
52
-			function ( $url ) {
53
-				return filter_var( $url, FILTER_VALIDATE_URL );
50
+			function($url) {
51
+				return filter_var($url, FILTER_VALIDATE_URL);
54 52
 			}
55 53
 		);
56 54
 
57 55
 		// extract the video ids.
58
-		return join( ',', $this->get_video_ids( $video_urls ) );
56
+		return join(',', $this->get_video_ids($video_urls));
59 57
 	}
60 58
 
61
-	public function get_video_ids( $video_urls ) {
59
+	public function get_video_ids($video_urls) {
62 60
 
63 61
 		$regex = self::YOUTUBE_REGEX;
64 62
 
65 63
 		$video_ids = array_map(
66
-			function ( $url ) use ( $regex ) {
64
+			function($url) use ($regex) {
67 65
 				$matches = array();
68
-				preg_match( $regex, $url, $matches );
66
+				preg_match($regex, $url, $matches);
69 67
 
70 68
 				// Return video id or return false.
71
-				if ( isset( $matches[1] ) && is_string( $matches[1] ) ) {
69
+				if (isset($matches[1]) && is_string($matches[1])) {
72 70
 					  return $matches[1];
73 71
 				}
74 72
 
@@ -78,7 +76,7 @@  discard block
 block discarded – undo
78 76
 			$video_urls
79 77
 		);
80 78
 
81
-		return array_values( array_filter( $video_ids ) );
79
+		return array_values(array_filter($video_ids));
82 80
 
83 81
 	}
84 82
 
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/client/class-vimeo-client.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -11,83 +11,83 @@
 block discarded – undo
11 11
  */
12 12
 class Vimeo_Client extends Singleton implements Client {
13 13
 
14
-	public static $requests_sent = 0;
14
+    public static $requests_sent = 0;
15 15
 
16
-	const VIMEO_URL_REGEX = '/https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/';
16
+    const VIMEO_URL_REGEX = '/https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/';
17 17
 
18
-	public function get_data( $video_urls ) {
18
+    public function get_data( $video_urls ) {
19 19
 
20
-		$vimeo_ids = $this->get_video_ids( $video_urls );
20
+        $vimeo_ids = $this->get_video_ids( $video_urls );
21 21
 
22
-		$vimeo_api_ids = array_map(
23
-			function ( $item ) {
24
-				return '/videos/' . $item;
25
-			},
26
-			$vimeo_ids
27
-		);
22
+        $vimeo_api_ids = array_map(
23
+            function ( $item ) {
24
+                return '/videos/' . $item;
25
+            },
26
+            $vimeo_ids
27
+        );
28 28
 
29
-		$ids = join( ',', $vimeo_api_ids );
29
+        $ids = join( ',', $vimeo_api_ids );
30 30
 
31
-		if ( ! $ids ) {
32
-			return array();
33
-		}
31
+        if ( ! $ids ) {
32
+            return array();
33
+        }
34 34
 
35
-		$api_url = $this->get_api_url() . '/videos/';
36
-		$api_url = add_query_arg(
37
-			array(
38
-				'uris'   => $ids,
39
-				'fields' => 'name,description,link,uri,duration,release_time,pictures,stats',
40
-			),
41
-			$api_url
42
-		);
35
+        $api_url = $this->get_api_url() . '/videos/';
36
+        $api_url = add_query_arg(
37
+            array(
38
+                'uris'   => $ids,
39
+                'fields' => 'name,description,link,uri,duration,release_time,pictures,stats',
40
+            ),
41
+            $api_url
42
+        );
43 43
 
44
-		$response = wp_remote_get(
45
-			$api_url,
46
-			array(
47
-				'headers' => array(
48
-					'Authorization' => 'bearer ' . $this->get_api_key(),
49
-				),
50
-			)
51
-		);
44
+        $response = wp_remote_get(
45
+            $api_url,
46
+            array(
47
+                'headers' => array(
48
+                    'Authorization' => 'bearer ' . $this->get_api_key(),
49
+                ),
50
+            )
51
+        );
52 52
 
53
-		++ self::$requests_sent;
53
+        ++ self::$requests_sent;
54 54
 
55
-		return wp_remote_retrieve_body( $response );
56
-	}
55
+        return wp_remote_retrieve_body( $response );
56
+    }
57 57
 
58
-	public static function get_api_key() {
59
-		return get_option( self::get_api_key_option_name(), false );
60
-	}
58
+    public static function get_api_key() {
59
+        return get_option( self::get_api_key_option_name(), false );
60
+    }
61 61
 
62
-	public static function get_api_key_option_name() {
63
-		return '_wl_videoobject_vimeo_api_key';
64
-	}
62
+    public static function get_api_key_option_name() {
63
+        return '_wl_videoobject_vimeo_api_key';
64
+    }
65 65
 
66
-	public function get_api_url() {
67
-		return 'https://api.vimeo.com';
68
-	}
66
+    public function get_api_url() {
67
+        return 'https://api.vimeo.com';
68
+    }
69 69
 
70
-	public function get_video_ids( $video_urls ) {
70
+    public function get_video_ids( $video_urls ) {
71 71
 
72
-		$that = $this;
72
+        $that = $this;
73 73
 
74
-		return array_filter(
75
-			array_map(
76
-				function ( $video_url ) use ( $that ) {
77
-					if ( ! $video_url ) {
78
-						  return false;
79
-					}
80
-					preg_match( $that::VIMEO_URL_REGEX, $video_url, $matches );
74
+        return array_filter(
75
+            array_map(
76
+                function ( $video_url ) use ( $that ) {
77
+                    if ( ! $video_url ) {
78
+                            return false;
79
+                    }
80
+                    preg_match( $that::VIMEO_URL_REGEX, $video_url, $matches );
81 81
 
82
-					if ( ! array_key_exists( 3, $matches ) ) {
83
-						return false;
84
-					}
82
+                    if ( ! array_key_exists( 3, $matches ) ) {
83
+                        return false;
84
+                    }
85 85
 
86
-					return $matches[3];
86
+                    return $matches[3];
87 87
 
88
-				},
89
-				$video_urls
90
-			)
91
-		);
92
-	}
88
+                },
89
+                $video_urls
90
+            )
91
+        );
92
+    }
93 93
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -18 removed lines patch added patch discarded remove patch
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 
16 16
 	const VIMEO_URL_REGEX = '/https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/';
17 17
 
18
-	public function get_data( $video_urls ) {
18
+	public function get_data($video_urls) {
19 19
 
20
-		$vimeo_ids = $this->get_video_ids( $video_urls );
20
+		$vimeo_ids = $this->get_video_ids($video_urls);
21 21
 
22 22
 		$vimeo_api_ids = array_map(
23
-			function ( $item ) {
24
-				return '/videos/' . $item;
23
+			function($item) {
24
+				return '/videos/'.$item;
25 25
 			},
26 26
 			$vimeo_ids
27 27
 		);
28 28
 
29
-		$ids = join( ',', $vimeo_api_ids );
29
+		$ids = join(',', $vimeo_api_ids);
30 30
 
31
-		if ( ! $ids ) {
31
+		if ( ! $ids) {
32 32
 			return array();
33 33
 		}
34 34
 
35
-		$api_url = $this->get_api_url() . '/videos/';
35
+		$api_url = $this->get_api_url().'/videos/';
36 36
 		$api_url = add_query_arg(
37 37
 			array(
38 38
 				'uris'   => $ids,
@@ -45,18 +45,16 @@  discard block
 block discarded – undo
45 45
 			$api_url,
46 46
 			array(
47 47
 				'headers' => array(
48
-					'Authorization' => 'bearer ' . $this->get_api_key(),
48
+					'Authorization' => 'bearer '.$this->get_api_key(),
49 49
 				),
50 50
 			)
51
-		);
52
-
53
-		++ self::$requests_sent;
51
+		);++ self::$requests_sent;
54 52
 
55
-		return wp_remote_retrieve_body( $response );
53
+		return wp_remote_retrieve_body($response);
56 54
 	}
57 55
 
58 56
 	public static function get_api_key() {
59
-		return get_option( self::get_api_key_option_name(), false );
57
+		return get_option(self::get_api_key_option_name(), false);
60 58
 	}
61 59
 
62 60
 	public static function get_api_key_option_name() {
@@ -67,19 +65,19 @@  discard block
 block discarded – undo
67 65
 		return 'https://api.vimeo.com';
68 66
 	}
69 67
 
70
-	public function get_video_ids( $video_urls ) {
68
+	public function get_video_ids($video_urls) {
71 69
 
72 70
 		$that = $this;
73 71
 
74 72
 		return array_filter(
75 73
 			array_map(
76
-				function ( $video_url ) use ( $that ) {
77
-					if ( ! $video_url ) {
74
+				function($video_url) use ($that) {
75
+					if ( ! $video_url) {
78 76
 						  return false;
79 77
 					}
80
-					preg_match( $that::VIMEO_URL_REGEX, $video_url, $matches );
78
+					preg_match($that::VIMEO_URL_REGEX, $video_url, $matches);
81 79
 
82
-					if ( ! array_key_exists( 3, $matches ) ) {
80
+					if ( ! array_key_exists(3, $matches)) {
83 81
 						return false;
84 82
 					}
85 83
 
Please login to merge, or discard this patch.