Completed
Push — master ( 85e358...cf3219 )
by Rakesh
04:24 queued 10s
created

Zend_Gdata_YouTube   F

Complexity

Total Complexity 96

Size/Duplication

Total Lines 787
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 309
c 1
b 0
f 1
dl 0
loc 787
rs 2
wmc 96

26 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getSubscriptionFeed() 0 10 3
A getWatchOnMobileVideoFeed() 0 21 6
A getPlaylistVideoFeed() 0 8 2
A getActivityForUser() 0 23 4
A getTopRatedVideoFeed() 0 21 6
A getFullVideoEntry() 0 5 1
A getVideoFeed() 0 10 3
A getMostViewedVideoFeed() 0 21 6
A getPlaylistListFeed() 0 10 3
A getInboxFeedForCurrentUser() 0 11 2
A setHttpClient() 0 22 5
A getVideoEntry() 0 15 4
A getUserProfile() 0 10 3
A getVideoResponseFeed() 0 11 3
B sendVideoMessage() 0 42 8
A getFormUploadToken() 0 11 3
A getContactFeed() 0 10 3
A getRelatedVideoFeed() 0 11 3
A getVideoCommentFeed() 0 10 3
A getUserUploads() 0 11 3
A replyToCommentEntry() 0 19 1
B parseFormUploadTokenResponse() 0 38 9
A getRecentlyFeaturedVideoFeed() 0 21 6
A getFriendActivityForCurrentUser() 0 10 2
A getUserFavorites() 0 11 3

How to fix   Complexity   

Complex Class

Complex classes like Zend_Gdata_YouTube often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Zend_Gdata_YouTube, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * Zend Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file LICENSE.txt.
10
 * It is also available through the world-wide-web at this URL:
11
 * http://framework.zend.com/license/new-bsd
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @category   Zend
17
 * @package    Zend_Gdata
18
 * @subpackage YouTube
19
 * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
20
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
21
 * @version    $Id$
22
 */
23
24
/**
25
 * @see Zend_Gdata_Media
26
 */
27
require_once 'Zend/Gdata/Media.php';
28
29
/**
30
 * @see Zend_Gdata_YouTube_VideoEntry
31
 */
32
require_once 'Zend/Gdata/YouTube/VideoEntry.php';
33
34
/**
35
 * @see Zend_Gdata_YouTube_VideoFeed
36
 */
37
require_once 'Zend/Gdata/YouTube/VideoFeed.php';
38
39
/**
40
 * @see Zend_Gdata_YouTube_CommentFeed
41
 */
42
require_once 'Zend/Gdata/YouTube/CommentFeed.php';
43
44
/**
45
 * @see Zend_Gdata_YouTube_PlaylistListFeed
46
 */
47
require_once 'Zend/Gdata/YouTube/PlaylistListFeed.php';
48
49
/**
50
 * @see Zend_Gdata_YouTube_SubscriptionFeed
51
 */
52
require_once 'Zend/Gdata/YouTube/SubscriptionFeed.php';
53
54
/**
55
 * @see Zend_Gdata_YouTube_ContactFeed
56
 */
57
require_once 'Zend/Gdata/YouTube/ContactFeed.php';
58
59
/**
60
 * @see Zend_Gdata_YouTube_PlaylistVideoFeed
61
 */
62
require_once 'Zend/Gdata/YouTube/PlaylistVideoFeed.php';
63
64
/**
65
 * @see Zend_Gdata_YouTube_ActivityFeed
66
 */
67
require_once 'Zend/Gdata/YouTube/ActivityFeed.php';
68
69
/**
70
 * @see Zend_Gdata_YouTube_InboxFeed
71
 */
72
require_once 'Zend/Gdata/YouTube/InboxFeed.php';
73
74
/** @see Zend_Xml_Security */
75
require_once 'Zend/Xml/Security.php';
76
77
/**
78
 * Service class for interacting with the YouTube Data API.
79
 * @link http://code.google.com/apis/youtube/
80
 *
81
 * @category   Zend
82
 * @package    Zend_Gdata
83
 * @subpackage YouTube
84
 * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
85
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
86
 */
87
class Zend_Gdata_YouTube extends Zend_Gdata_Media
88
{
89
90
    const AUTH_SERVICE_NAME = 'youtube';
91
    const CLIENTLOGIN_URL = 'https://www.google.com/youtube/accounts/ClientLogin';
92
93
    const STANDARD_TOP_RATED_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/top_rated';
94
    const STANDARD_MOST_VIEWED_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/most_viewed';
95
    const STANDARD_RECENTLY_FEATURED_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/recently_featured';
96
    const STANDARD_WATCH_ON_MOBILE_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/watch_on_mobile';
97
98
    const STANDARD_TOP_RATED_URI_V2 =
99
        'https://gdata.youtube.com/feeds/api/standardfeeds/top_rated';
100
    const STANDARD_MOST_VIEWED_URI_V2 =
101
        'https://gdata.youtube.com/feeds/api/standardfeeds/most_viewed';
102
    const STANDARD_RECENTLY_FEATURED_URI_V2 =
103
        'https://gdata.youtube.com/feeds/api/standardfeeds/recently_featured';
104
    const STANDARD_WATCH_ON_MOBILE_URI_V2 =
105
        'https://gdata.youtube.com/feeds/api/standardfeeds/watch_on_mobile';
106
107
    const USER_URI = 'https://gdata.youtube.com/feeds/api/users';
108
    const VIDEO_URI = 'https://gdata.youtube.com/feeds/api/videos';
109
    const PLAYLIST_REL = 'http://gdata.youtube.com/schemas/2007#playlist';
110
    const USER_UPLOADS_REL = 'http://gdata.youtube.com/schemas/2007#user.uploads';
111
    const USER_PLAYLISTS_REL = 'http://gdata.youtube.com/schemas/2007#user.playlists';
112
    const USER_SUBSCRIPTIONS_REL = 'http://gdata.youtube.com/schemas/2007#user.subscriptions';
113
    const USER_CONTACTS_REL = 'http://gdata.youtube.com/schemas/2007#user.contacts';
114
    const USER_FAVORITES_REL = 'http://gdata.youtube.com/schemas/2007#user.favorites';
115
    const VIDEO_RESPONSES_REL = 'http://gdata.youtube.com/schemas/2007#video.responses';
116
    const VIDEO_RATINGS_REL = 'http://gdata.youtube.com/schemas/2007#video.ratings';
117
    const VIDEO_COMPLAINTS_REL = 'http://gdata.youtube.com/schemas/2007#video.complaints';
118
    const ACTIVITY_FEED_URI = 'https://gdata.youtube.com/feeds/api/events';
119
    const FRIEND_ACTIVITY_FEED_URI =
120
        'https://gdata.youtube.com/feeds/api/users/default/friendsactivity';
121
122
    /**
123
     * The URI of the in-reply-to schema for comments in reply to
124
     * other comments.
125
     *
126
     * @var string
127
     */
128
     const IN_REPLY_TO_SCHEME =
129
         'http://gdata.youtube.com/schemas/2007#in-reply-to';
130
131
    /**
132
     * The URI of the inbox feed for the currently authenticated user.
133
     *
134
     * @var string
135
     */
136
    const INBOX_FEED_URI =
137
        'https://gdata.youtube.com/feeds/api/users/default/inbox';
138
139
    /**
140
     * The maximum number of users for which activity can be requested for,
141
     * as enforced by the API.
142
     *
143
     * @var integer
144
     */
145
    const ACTIVITY_FEED_MAX_USERS = 20;
146
147
    /**
148
     * The suffix for a feed of favorites.
149
     *
150
     * @var string
151
     */
152
    const FAVORITES_URI_SUFFIX = 'favorites';
153
154
    /**
155
     * The suffix for the user's upload feed.
156
     *
157
     * @var string
158
     */
159
    const UPLOADS_URI_SUFFIX = 'uploads';
160
161
    /**
162
     * The suffix for a feed of video responses.
163
     *
164
     * @var string
165
     */
166
    const RESPONSES_URI_SUFFIX = 'responses';
167
168
    /**
169
     * The suffix for a feed of related videos.
170
     *
171
     * @var string
172
     */
173
    const RELATED_URI_SUFFIX = 'related';
174
175
    /**
176
     * The suffix for a feed of messages (inbox entries).
177
     *
178
     * @var string
179
     */
180
    const INBOX_URI_SUFFIX = 'inbox';
181
182
    /**
183
     * Namespaces used for Zend_Gdata_YouTube
184
     *
185
     * @var array
186
     */
187
    public static $namespaces = array(
188
        array('yt', 'http://gdata.youtube.com/schemas/2007', 1, 0),
189
        array('georss', 'http://www.georss.org/georss', 1, 0),
190
        array('gml', 'http://www.opengis.net/gml', 1, 0),
191
        array('media', 'http://search.yahoo.com/mrss/', 1, 0)
192
    );
193
194
    /**
195
     * Create Zend_Gdata_YouTube object
196
     *
197
     * @param Zend_Http_Client $client (optional) The HTTP client to use when
198
     *          when communicating with the Google servers.
199
     * @param string $applicationId The identity of the app in the form of
200
     *        Company-AppName-Version
201
     * @param string $clientId The clientId issued by the YouTube dashboard
202
     * @param string $developerKey The developerKey issued by the YouTube dashboard
203
     */
204
    public function __construct($client = null,
205
        $applicationId = 'MyCompany-MyApp-1.0', $clientId = null,
206
        $developerKey = null)
207
    {
208
        $this->registerPackage('Zend_Gdata_YouTube');
209
        $this->registerPackage('Zend_Gdata_YouTube_Extension');
210
        $this->registerPackage('Zend_Gdata_Media');
211
        $this->registerPackage('Zend_Gdata_Media_Extension');
212
213
        // NOTE This constructor no longer calls the parent constructor
214
        $this->setHttpClient($client, $applicationId, $clientId, $developerKey);
215
    }
216
217
    /**
218
     * Set the Zend_Http_Client object used for communication
219
     *
220
     * @param Zend_Http_Client $client The client to use for communication
221
     * @throws Zend_Gdata_App_HttpException
222
     * @return Zend_Gdata_App Provides a fluent interface
223
     */
224
    public function setHttpClient($client,
225
        $applicationId = 'MyCompany-MyApp-1.0', $clientId = null,
226
        $developerKey = null)
227
    {
228
        if ($client === null) {
229
            $client = new Zend_Http_Client();
230
        }
231
        if (!$client instanceof Zend_Http_Client) {
0 ignored issues
show
introduced by
$client is always a sub-type of Zend_Http_Client.
Loading history...
232
            require_once 'Zend/Gdata/App/HttpException.php';
233
            throw new Zend_Gdata_App_HttpException(
234
                'Argument is not an instance of Zend_Http_Client.');
235
        }
236
237
        if ($clientId != null) {
238
            $client->setHeaders('X-GData-Client', $clientId);
239
        }
240
241
        if ($developerKey != null) {
242
            $client->setHeaders('X-GData-Key', 'key='. $developerKey);
243
        }
244
245
        return parent::setHttpClient($client, $applicationId);
246
    }
247
248
    /**
249
     * Retrieves a feed of videos.
250
     *
251
     * @param mixed $location (optional) The URL to query or a
252
     *         Zend_Gdata_Query object from which a URL can be determined
253
     * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
254
     *         specified URL.
255
     */
256
    public function getVideoFeed($location = null)
257
    {
258
        if ($location == null) {
259
            $uri = self::VIDEO_URI;
260
        } else if ($location instanceof Zend_Gdata_Query) {
261
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

261
            /** @scrutinizer ignore-call */ 
262
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
262
        } else {
263
            $uri = $location;
264
        }
265
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
266
    }
267
268
    /**
269
     * Retrieves a specific video entry.
270
     *
271
     * @param mixed $videoId The ID of the video to retrieve.
272
     * @param mixed $location (optional) The URL to query or a
273
     *         Zend_Gdata_Query object from which a URL can be determined.
274
     * @param boolean $fullEntry (optional) Retrieve the full metadata for the
275
     *         entry. Only possible if entry belongs to currently authenticated
276
     *         user. An exception will be thrown otherwise.
277
     * @throws Zend_Gdata_App_HttpException
278
     * @return Zend_Gdata_YouTube_VideoEntry The video entry found at the
279
     *         specified URL.
280
     */
281
    public function getVideoEntry($videoId = null, $location = null,
282
        $fullEntry = false)
283
    {
284
        if ($videoId !== null) {
285
            if ($fullEntry) {
286
                return $this->getFullVideoEntry($videoId);
287
            } else {
288
                $uri = self::VIDEO_URI . "/" . $videoId;
289
            }
290
        } else if ($location instanceof Zend_Gdata_Query) {
291
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

291
            /** @scrutinizer ignore-call */ 
292
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
292
        } else {
293
            $uri = $location;
294
        }
295
        return parent::getEntry($uri, 'Zend_Gdata_YouTube_VideoEntry');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getEntry(...ta_YouTube_VideoEntry') returns the type string which is incompatible with the documented return type Zend_Gdata_YouTube_VideoEntry.
Loading history...
296
    }
297
298
    /**
299
     * Retrieves a video entry from the user's upload feed.
300
     *
301
     * @param mixed $videoID The ID of the video to retrieve.
302
     * @throws Zend_Gdata_App_HttpException
303
     * @return Zend_Gdata_YouTube_VideoEntry|null The video entry to be
304
     *          retrieved, or null if it was not found or the user requesting it
305
     *          did not have the appropriate permissions.
306
     */
307
    public function getFullVideoEntry($videoId)
308
    {
309
        $uri = self::USER_URI . "/default/" .
310
            self::UPLOADS_URI_SUFFIX . "/$videoId";
311
        return parent::getEntry($uri, 'Zend_Gdata_YouTube_VideoEntry');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getEntry(...ta_YouTube_VideoEntry') returns the type string which is incompatible with the documented return type Zend_Gdata_YouTube_VideoEntry|null.
Loading history...
312
    }
313
314
    /**
315
     * Retrieves a feed of videos related to the specified video ID.
316
     *
317
     * @param string $videoId The videoId of interest
318
     * @param mixed $location (optional) The URL to query or a
319
     *         Zend_Gdata_Query object from which a URL can be determined
320
     * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
321
     *         specified URL.
322
     */
323
    public function getRelatedVideoFeed($videoId = null, $location = null)
324
    {
325
        if ($videoId !== null) {
326
            $uri = self::VIDEO_URI . "/" . $videoId . "/" .
327
                self::RELATED_URI_SUFFIX;
328
        } else if ($location instanceof Zend_Gdata_Query) {
329
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

329
            /** @scrutinizer ignore-call */ 
330
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
330
        } else {
331
            $uri = $location;
332
        }
333
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
334
    }
335
336
    /**
337
     * Retrieves a feed of video responses related to the specified video ID.
338
     *
339
     * @param string $videoId The videoId of interest
340
     * @param mixed $location (optional) The URL to query or a
341
     *         Zend_Gdata_Query object from which a URL can be determined
342
     * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
343
     *         specified URL.
344
     */
345
    public function getVideoResponseFeed($videoId = null, $location = null)
346
    {
347
        if ($videoId !== null) {
348
            $uri = self::VIDEO_URI . "/" . $videoId . "/" .
349
                self::RESPONSES_URI_SUFFIX;
350
        } else if ($location instanceof Zend_Gdata_Query) {
351
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

351
            /** @scrutinizer ignore-call */ 
352
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
352
        } else {
353
            $uri = $location;
354
        }
355
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
356
    }
357
358
    /**
359
     * Retrieves a feed of comments related to the specified video ID.
360
     *
361
     * @param string $videoId The videoId of interest
362
     * @param mixed $location (optional) The URL to query or a
363
     *         Zend_Gdata_Query object from which a URL can be determined
364
     * @return Zend_Gdata_YouTube_CommentFeed The feed of videos found at the
365
     *         specified URL.
366
     */
367
    public function getVideoCommentFeed($videoId = null, $location = null)
368
    {
369
        if ($videoId !== null) {
370
            $uri = self::VIDEO_URI . "/" . $videoId . "/comments";
371
        } else if ($location instanceof Zend_Gdata_Query) {
372
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

372
            /** @scrutinizer ignore-call */ 
373
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
373
        } else {
374
            $uri = $location;
375
        }
376
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_CommentFeed');
377
    }
378
379
    /**
380
     * Retrieves a feed of comments related to the specified video ID.
381
     *
382
     * @param mixed $location (optional) The URL to query or a
383
     *         Zend_Gdata_Query object from which a URL can be determined
384
     * @return Zend_Gdata_YouTube_CommentFeed The feed of videos found at the
385
     *         specified URL.
386
     */
387
    public function getTopRatedVideoFeed($location = null)
388
    {
389
        $standardFeedUri = self::STANDARD_TOP_RATED_URI;
390
391
        if ($this->getMajorProtocolVersion() == 2) {
392
            $standardFeedUri = self::STANDARD_TOP_RATED_URI_V2;
393
        }
394
395
        if ($location == null) {
396
            $uri = $standardFeedUri;
397
        } else if ($location instanceof Zend_Gdata_Query) {
398
            if ($location instanceof Zend_Gdata_YouTube_VideoQuery) {
399
                if (!isset($location->url)) {
0 ignored issues
show
Bug Best Practice introduced by
The property url does not exist on Zend_Gdata_YouTube_VideoQuery. Since you implemented __get, consider adding a @property annotation.
Loading history...
400
                    $location->setFeedType('top rated');
401
                }
402
            }
403
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
404
        } else {
405
            $uri = $location;
406
        }
407
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getFeed($...ata_YouTube_VideoFeed') returns the type Zend_Gdata_YouTube_VideoFeed which is incompatible with the documented return type Zend_Gdata_YouTube_CommentFeed.
Loading history...
408
    }
409
410
411
    /**
412
     * Retrieves a feed of the most viewed videos.
413
     *
414
     * @param mixed $location (optional) The URL to query or a
415
     *         Zend_Gdata_Query object from which a URL can be determined
416
     * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
417
     *         specified URL.
418
     */
419
    public function getMostViewedVideoFeed($location = null)
420
    {
421
        $standardFeedUri = self::STANDARD_MOST_VIEWED_URI;
422
423
        if ($this->getMajorProtocolVersion() == 2) {
424
            $standardFeedUri = self::STANDARD_MOST_VIEWED_URI_V2;
425
        }
426
427
        if ($location == null) {
428
            $uri = $standardFeedUri;
429
        } else if ($location instanceof Zend_Gdata_Query) {
430
            if ($location instanceof Zend_Gdata_YouTube_VideoQuery) {
431
                if (!isset($location->url)) {
0 ignored issues
show
Bug Best Practice introduced by
The property url does not exist on Zend_Gdata_YouTube_VideoQuery. Since you implemented __get, consider adding a @property annotation.
Loading history...
432
                    $location->setFeedType('most viewed');
433
                }
434
            }
435
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
436
        } else {
437
            $uri = $location;
438
        }
439
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
440
    }
441
442
    /**
443
     * Retrieves a feed of recently featured videos.
444
     *
445
     * @param mixed $location (optional) The URL to query or a
446
     *         Zend_Gdata_Query object from which a URL can be determined
447
     * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
448
     *         specified URL.
449
     */
450
    public function getRecentlyFeaturedVideoFeed($location = null)
451
    {
452
        $standardFeedUri = self::STANDARD_RECENTLY_FEATURED_URI;
453
454
        if ($this->getMajorProtocolVersion() == 2) {
455
            $standardFeedUri = self::STANDARD_RECENTLY_FEATURED_URI_V2;
456
        }
457
458
        if ($location == null) {
459
            $uri = $standardFeedUri;
460
        } else if ($location instanceof Zend_Gdata_Query) {
461
            if ($location instanceof Zend_Gdata_YouTube_VideoQuery) {
462
                if (!isset($location->url)) {
0 ignored issues
show
Bug Best Practice introduced by
The property url does not exist on Zend_Gdata_YouTube_VideoQuery. Since you implemented __get, consider adding a @property annotation.
Loading history...
463
                    $location->setFeedType('recently featured');
464
                }
465
            }
466
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
467
        } else {
468
            $uri = $location;
469
        }
470
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
471
    }
472
473
    /**
474
     * Retrieves a feed of videos recently featured for mobile devices.
475
     * These videos will have RTSP links in the $entry->mediaGroup->content
476
     *
477
     * @param mixed $location (optional) The URL to query or a
478
     *         Zend_Gdata_Query object from which a URL can be determined
479
     * @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
480
     *         specified URL.
481
     */
482
    public function getWatchOnMobileVideoFeed($location = null)
483
    {
484
        $standardFeedUri = self::STANDARD_WATCH_ON_MOBILE_URI;
485
486
        if ($this->getMajorProtocolVersion() == 2) {
487
            $standardFeedUri = self::STANDARD_WATCH_ON_MOBILE_URI_V2;
488
        }
489
490
        if ($location == null) {
491
            $uri = $standardFeedUri;
492
        } else if ($location instanceof Zend_Gdata_Query) {
493
            if ($location instanceof Zend_Gdata_YouTube_VideoQuery) {
494
                if (!isset($location->url)) {
0 ignored issues
show
Bug Best Practice introduced by
The property url does not exist on Zend_Gdata_YouTube_VideoQuery. Since you implemented __get, consider adding a @property annotation.
Loading history...
495
                    $location->setFeedType('watch on mobile');
496
                }
497
            }
498
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
499
        } else {
500
            $uri = $location;
501
        }
502
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
503
    }
504
505
    /**
506
     * Retrieves a feed which lists a user's playlist
507
     *
508
     * @param string $user (optional) The username of interest
509
     * @param mixed $location (optional) The URL to query or a
510
     *         Zend_Gdata_Query object from which a URL can be determined
511
     * @return Zend_Gdata_YouTube_PlaylistListFeed The feed of playlists
512
     */
513
    public function getPlaylistListFeed($user = null, $location = null)
514
    {
515
        if ($user !== null) {
516
            $uri = self::USER_URI . '/' . $user . '/playlists';
517
        } else if ($location instanceof Zend_Gdata_Query) {
518
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

518
            /** @scrutinizer ignore-call */ 
519
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
519
        } else {
520
            $uri = $location;
521
        }
522
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_PlaylistListFeed');
523
    }
524
525
    /**
526
     * Retrieves a feed of videos in a particular playlist
527
     *
528
     * @param mixed $location (optional) The URL to query or a
529
     *         Zend_Gdata_Query object from which a URL can be determined
530
     * @return Zend_Gdata_YouTube_PlaylistVideoFeed The feed of videos found at
531
     *         the specified URL.
532
     */
533
    public function getPlaylistVideoFeed($location)
534
    {
535
        if ($location instanceof Zend_Gdata_Query) {
536
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

536
            /** @scrutinizer ignore-call */ 
537
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
537
        } else {
538
            $uri = $location;
539
        }
540
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_PlaylistVideoFeed');
541
    }
542
543
    /**
544
     * Retrieves a feed of a user's subscriptions
545
     *
546
     * @param string $user (optional) The username of interest
547
     * @param mixed $location (optional) The URL to query or a
548
     *         Zend_Gdata_Query object from which a URL can be determined
549
     * @return Zend_Gdata_YouTube_SubscriptionListFeed The feed of subscriptions
0 ignored issues
show
Bug introduced by
The type Zend_Gdata_YouTube_SubscriptionListFeed was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
550
     */
551
    public function getSubscriptionFeed($user = null, $location = null)
552
    {
553
        if ($user !== null) {
554
            $uri = self::USER_URI . '/' . $user . '/subscriptions';
555
        } else if ($location instanceof Zend_Gdata_Query) {
556
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

556
            /** @scrutinizer ignore-call */ 
557
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
557
        } else {
558
            $uri = $location;
559
        }
560
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_SubscriptionFeed');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getFeed($...Tube_SubscriptionFeed') returns the type Zend_Gdata_YouTube_SubscriptionFeed which is incompatible with the documented return type Zend_Gdata_YouTube_SubscriptionListFeed.
Loading history...
561
    }
562
563
    /**
564
     * Retrieves a feed of a user's contacts
565
     *
566
     * @param string $user (optional) The username of interest
567
     * @param mixed $location (optional) The URL to query or a
568
     *         Zend_Gdata_Query object from which a URL can be determined
569
     * @return Zend_Gdata_YouTube_ContactFeed The feed of contacts
570
     */
571
    public function getContactFeed($user = null, $location = null)
572
    {
573
        if ($user !== null) {
574
            $uri = self::USER_URI . '/' . $user . '/contacts';
575
        } else if ($location instanceof Zend_Gdata_Query) {
576
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

576
            /** @scrutinizer ignore-call */ 
577
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
577
        } else {
578
            $uri = $location;
579
        }
580
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_ContactFeed');
581
    }
582
583
    /**
584
     * Retrieves a user's uploads
585
     *
586
     * @param string $user (optional) The username of interest
587
     * @param mixed $location (optional) The URL to query or a
588
     *         Zend_Gdata_Query object from which a URL can be determined
589
     * @return Zend_Gdata_YouTube_VideoFeed The videos uploaded by the user
590
     */
591
    public function getUserUploads($user = null, $location = null)
592
    {
593
        if ($user !== null) {
594
            $uri = self::USER_URI . '/' . $user . '/' .
595
                   self::UPLOADS_URI_SUFFIX;
596
        } else if ($location instanceof Zend_Gdata_Query) {
597
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

597
            /** @scrutinizer ignore-call */ 
598
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
598
        } else {
599
            $uri = $location;
600
        }
601
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
602
    }
603
604
    /**
605
     * Retrieves a user's favorites
606
     *
607
     * @param string $user (optional) The username of interest
608
     * @param mixed $location (optional) The URL to query or a
609
     *         Zend_Gdata_Query object from which a URL can be determined
610
     * @return Zend_Gdata_YouTube_VideoFeed The videos favorited by the user
611
     */
612
    public function getUserFavorites($user = null, $location = null)
613
    {
614
        if ($user !== null) {
615
            $uri = self::USER_URI . '/' . $user . '/' .
616
                   self::FAVORITES_URI_SUFFIX;
617
        } else if ($location instanceof Zend_Gdata_Query) {
618
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

618
            /** @scrutinizer ignore-call */ 
619
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
619
        } else {
620
            $uri = $location;
621
        }
622
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
623
    }
624
625
    /**
626
     * Retrieves a user's profile as an entry
627
     *
628
     * @param string $user (optional) The username of interest
629
     * @param mixed $location (optional) The URL to query or a
630
     *         Zend_Gdata_Query object from which a URL can be determined
631
     * @return Zend_Gdata_YouTube_UserProfileEntry The user profile entry
632
     */
633
    public function getUserProfile($user = null, $location = null)
634
    {
635
        if ($user !== null) {
636
            $uri = self::USER_URI . '/' . $user;
637
        } else if ($location instanceof Zend_Gdata_Query) {
638
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

638
            /** @scrutinizer ignore-call */ 
639
            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
639
        } else {
640
            $uri = $location;
641
        }
642
        return parent::getEntry($uri, 'Zend_Gdata_YouTube_UserProfileEntry');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getEntry(...Tube_UserProfileEntry') returns the type string which is incompatible with the documented return type Zend_Gdata_YouTube_UserProfileEntry.
Loading history...
643
    }
644
645
    /**
646
     * Helper function for parsing a YouTube token response
647
     *
648
     * @param string $response The service response
649
     * @throws Zend_Gdata_App_Exception
650
     * @return array An array containing the token and URL
651
     */
652
    public static function parseFormUploadTokenResponse($response)
653
    {
654
        // Load the feed as an XML DOMDocument object
655
        @ini_set('track_errors', 1);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for ini_set(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

655
        /** @scrutinizer ignore-unhandled */ @ini_set('track_errors', 1);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
656
        $doc = new DOMDocument();
657
        $doc = @Zend_Xml_Security::scan($response, $doc);
0 ignored issues
show
Bug introduced by
The type Zend_Xml_Security was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
658
        @ini_restore('track_errors');
0 ignored issues
show
Bug introduced by
Are you sure the usage of ini_restore('track_errors') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Security Best Practice introduced by
It seems like you do not handle an error condition for ini_restore(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

658
        /** @scrutinizer ignore-unhandled */ @ini_restore('track_errors');

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
659
660
        if (!$doc) {
661
            require_once 'Zend/Gdata/App/Exception.php';
662
            throw new Zend_Gdata_App_Exception(
663
                "Zend_Gdata_YouTube::parseFormUploadTokenResponse - " .
664
                "DOMDocument cannot parse XML: $php_errormsg");
665
        }
666
        $responseElement = $doc->getElementsByTagName('response')->item(0);
667
668
        $urlText = null;
669
        $tokenText = null;
670
        if ($responseElement != null) {
671
            $urlElement =
672
                $responseElement->getElementsByTagName('url')->item(0);
673
            $tokenElement =
674
                $responseElement->getElementsByTagName('token')->item(0);
675
676
            if ($urlElement && $urlElement->hasChildNodes() &&
677
                $tokenElement && $tokenElement->hasChildNodes()) {
678
679
                $urlText = $urlElement->firstChild->nodeValue;
680
                $tokenText = $tokenElement->firstChild->nodeValue;
681
            }
682
        }
683
684
        if ($tokenText != null && $urlText != null) {
685
            return array('token' => $tokenText, 'url' => $urlText);
686
        } else {
687
            require_once 'Zend/Gdata/App/Exception.php';
688
            throw new Zend_Gdata_App_Exception(
689
                'Form upload token not found in response');
690
        }
691
    }
692
693
    /**
694
     * Retrieves a YouTube token
695
     *
696
     * @param Zend_Gdata_YouTube_VideoEntry $videoEntry The video entry
697
     * @param string $url The location as a string URL
698
     * @throws Zend_Gdata_App_Exception
699
     * @return array An array containing a token and URL
700
     */
701
    public function getFormUploadToken($videoEntry,
702
        $url='https://gdata.youtube.com/action/GetUploadToken')
703
    {
704
        if ($url != null && is_string($url)) {
705
            // $response is a Zend_Http_response object
706
            $response = $this->post($videoEntry, $url);
707
            return self::parseFormUploadTokenResponse($response->getBody());
708
        } else {
709
            require_once 'Zend/Gdata/App/Exception.php';
710
            throw new Zend_Gdata_App_Exception(
711
                'Url must be provided as a string URL');
712
        }
713
    }
714
715
    /**
716
     * Retrieves the activity feed for users
717
     *
718
     * @param mixed $usernames A string identifying the usernames for which to
719
     *              retrieve activity for. This can also be a Zend_Gdata_Query
720
     *              object from which a URL can be determined.
721
     * @throws Zend_Gdata_App_VersionException if using version less than 2.
722
     * @return Zend_Gdata_YouTube_ActivityFeed
723
     */
724
    public function getActivityForUser($username)
725
    {
726
        if ($this->getMajorProtocolVersion() == 1) {
727
            require_once 'Zend/Gdata/App/VersionException.php';
728
            throw new Zend_Gdata_App_VersionException('User activity feeds ' .
729
                'are not available in API version 1.');
730
        }
731
732
        $uri = null;
733
        if ($username instanceof Zend_Gdata_Query) {
734
            $uri = $username->getQueryUrl($this->getMajorProtocolVersion());
0 ignored issues
show
Unused Code introduced by
The call to Zend_Gdata_Query::getQueryUrl() has too many arguments starting with $this->getMajorProtocolVersion(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

734
            /** @scrutinizer ignore-call */ 
735
            $uri = $username->getQueryUrl($this->getMajorProtocolVersion());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
735
        } else {
736
            if (count(explode(',', $username)) >
737
                self::ACTIVITY_FEED_MAX_USERS) {
738
                require_once 'Zend/Gdata/App/InvalidArgumentException.php';
739
                throw new Zend_Gdata_App_InvalidArgumentException(
740
                    'Activity feed can only retrieve for activity for up to ' .
741
                    self::ACTIVITY_FEED_MAX_USERS .  ' users per request');
742
            }
743
            $uri = self::ACTIVITY_FEED_URI . '?author=' . $username;
744
        }
745
746
        return parent::getFeed($uri, 'Zend_Gdata_YouTube_ActivityFeed');
747
    }
748
749
    /**
750
     * Retrieve the activity of the currently authenticated users friend.
751
     *
752
     * @throws Zend_Gdata_App_Exception if not logged in.
753
     * @return Zend_Gdata_YouTube_ActivityFeed
754
     */
755
    public function getFriendActivityForCurrentUser()
756
    {
757
        if (!$this->isAuthenticated()) {
758
            require_once 'Zend/Gdata/App/Exception.php';
759
            throw new Zend_Gdata_App_Exception('You must be authenticated to ' .
760
                'use the getFriendActivityForCurrentUser function in Zend_' .
761
                'Gdata_YouTube.');
762
        }
763
        return parent::getFeed(self::FRIEND_ACTIVITY_FEED_URI,
764
            'Zend_Gdata_YouTube_ActivityFeed');
765
    }
766
767
    /**
768
     * Retrieve a feed of messages in the currently authenticated user's inbox.
769
     *
770
     * @throws Zend_Gdata_App_Exception if not logged in.
771
     * @return Zend_Gdata_YouTube_InboxFeed|null
772
     */
773
    public function getInboxFeedForCurrentUser()
774
    {
775
        if (!$this->isAuthenticated()) {
776
            require_once 'Zend/Gdata/App/Exception.php';
777
            throw new Zend_Gdata_App_Exception('You must be authenticated to ' .
778
                'use the getInboxFeedForCurrentUser function in Zend_' .
779
                'Gdata_YouTube.');
780
        }
781
782
        return parent::getFeed(self::INBOX_FEED_URI,
783
            'Zend_Gdata_YouTube_InboxFeed');
784
    }
785
786
    /**
787
     * Send a video message.
788
     *
789
     * Note: Either a Zend_Gdata_YouTube_VideoEntry or a valid video ID must
790
     * be provided.
791
     *
792
     * @param string $body The body of the message
793
     * @param Zend_Gdata_YouTube_VideoEntry (optional) The video entry to send
0 ignored issues
show
Bug introduced by
The type optional was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
794
     * @param string $videoId The id of the video to send
795
     * @param string $recipientUserName The username of the recipient
796
     * @throws Zend_Gdata_App_InvalidArgumentException if no valid
797
     *         Zend_Gdata_YouTube_VideoEntry or videoId were provided
798
     * @return Zend_Gdata_YouTube_InboxEntry|null The
799
     *         Zend_Gdata_YouTube_Inbox_Entry representing the sent message.
800
     *
801
     */
802
    public function sendVideoMessage($body, $videoEntry = null,
803
        $videoId = null, $recipientUserName)
804
    {
805
        if (!$videoId && !$videoEntry) {
806
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
807
            throw new Zend_Gdata_App_InvalidArgumentException(
808
                'Expecting either a valid videoID or a videoEntry object in ' .
809
                'Zend_Gdata_YouTube->sendVideoMessage().');
810
        }
811
812
        $messageEntry = new Zend_Gdata_YouTube_InboxEntry();
813
814
        if ($this->getMajorProtocolVersion() == null ||
815
            $this->getMajorProtocolVersion() == 1) {
816
817
            if (!$videoId) {
818
                $videoId = $videoEntry->getVideoId();
819
            } elseif (strlen($videoId) < 12) {
820
                //Append the full URI
821
                $videoId = self::VIDEO_URI . '/' . $videoId;
822
            }
823
824
            $messageEntry->setId($this->newId($videoId));
0 ignored issues
show
Bug introduced by
The method newId() does not exist on Zend_Gdata_YouTube. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

824
            $messageEntry->setId($this->/** @scrutinizer ignore-call */ newId($videoId));
Loading history...
825
            // TODO there seems to be a bug where v1 inbox entries dont
826
            // retain their description...
827
            $messageEntry->setDescription(
828
                new Zend_Gdata_YouTube_Extension_Description($body));
829
830
        } else {
831
            if (!$videoId) {
832
                $videoId = $videoEntry->getVideoId();
833
                $videoId = substr($videoId, strrpos($videoId, ':'));
834
            }
835
            $messageEntry->setId($this->newId($videoId));
836
            $messageEntry->setSummary($this->newSummary($body));
0 ignored issues
show
Bug introduced by
The method newSummary() does not exist on Zend_Gdata_YouTube. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

836
            $messageEntry->setSummary($this->/** @scrutinizer ignore-call */ newSummary($body));
Loading history...
837
        }
838
839
        $insertUrl = 'https://gdata.youtube.com/feeds/api/users/' .
840
            $recipientUserName . '/inbox';
841
        $response = $this->insertEntry($messageEntry, $insertUrl,
842
            'Zend_Gdata_YouTube_InboxEntry');
843
        return $response;
844
    }
845
846
    /**
847
     * Post a comment in reply to an existing comment
848
     *
849
     * @param Zend_Gdata_YouTube_CommentEntry $commentEntry The comment entry
850
     *         to reply to
851
     * @param string                          $commentText  The text of the
852
		 *         comment to post
853
     * @return Zend_Gdata_YouTube_CommentEntry the posted comment
854
     */
855
    public function replyToCommentEntry($commentEntry, $commentText)
856
    {
857
        $newComment = $this->newCommentEntry();
0 ignored issues
show
Bug introduced by
The method newCommentEntry() does not exist on Zend_Gdata_YouTube. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

857
        /** @scrutinizer ignore-call */ 
858
        $newComment = $this->newCommentEntry();
Loading history...
858
        $newComment->content = $this->newContent()->setText($commentText);
0 ignored issues
show
Bug introduced by
The method newContent() does not exist on Zend_Gdata_YouTube. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

858
        $newComment->content = $this->/** @scrutinizer ignore-call */ newContent()->setText($commentText);
Loading history...
859
        $commentId = $commentEntry->getId();
860
        $commentIdArray = explode(':', $commentId);
861
862
        // create a new link element
863
        $inReplyToLinkHref = self::VIDEO_URI . '/' . $commentIdArray[3] .
864
            '/comments/' . $commentIdArray[5];
865
        $inReplyToLink = $this->newLink($inReplyToLinkHref,
0 ignored issues
show
Bug introduced by
The method newLink() does not exist on Zend_Gdata_YouTube. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

865
        /** @scrutinizer ignore-call */ 
866
        $inReplyToLink = $this->newLink($inReplyToLinkHref,
Loading history...
866
            self::IN_REPLY_TO_SCHEME, $type="application/atom+xml");
867
        $links = $newComment->getLink();
868
        $links[] = $inReplyToLink;
869
        $newComment->setLink($links);
870
        $commentFeedPostUrl = self::VIDEO_URI . '/' . $commentIdArray[3] .
871
            '/comments';
872
        return $this->insertEntry($newComment,
873
            $commentFeedPostUrl, 'Zend_Gdata_YouTube_CommentEntry');
874
    }
875
876
}
877