Skip to content

Commit

Permalink
better coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Sep 28, 2016
1 parent 50ccfc4 commit 0a5f731
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
22 changes: 9 additions & 13 deletions Nextras/YoutubeApi/Reader.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?php

/**
* This file is part of the Nextras community extensions of Nette Framework
*
* Copyright (c) 2012 Jan Skrasek (http://jan.skrasek.com)
*
* This file is part of the YoutubeApi library.
* @license MIT
* @link https://github.com/nextras
* @link https://github.com/nextras/youtube-api
*/

namespace Nextras\YoutubeApi;
Expand Down Expand Up @@ -42,20 +39,20 @@ public function __construct($apiKey, Client $httpClient = null)


/**
* Fetchs video data by youtube url
* @param string youtube url
* Fetches video data by youtube url
* @param string $videoUrl YouTube url
* @return Video
*/
public function getVideoByUrl($videoUrl)
{
$url = new Nette\Http\Url($videoUrl);

if (stripos($url->host, 'youtu.be') !== FALSE) {
if (stripos($url->host, 'youtu.be') !== false) {
return $this->getVideo(trim($url->getPath(), '/'));
}

$videoId = $url->getQueryParameter('v');
if (stripos($url->host, 'youtube.com') === FALSE || $videoId === NULL) {
if (stripos($url->host, 'youtube.com') === false || $videoId === null) {
throw new Nette\InvalidArgumentException('videoUrl must be valid youtube url.');
}

Expand All @@ -66,7 +63,7 @@ public function getVideoByUrl($videoUrl)

/**
* Fetchs video data
* @param string video id
* @param string $videoId
* @return Video
*/
public function getVideo($videoId)
Expand All @@ -80,7 +77,7 @@ protected function getData($videoId)
{
$url = sprintf($this->youtubeFetchUrl, $this->apiKey, $videoId);
$response = $this->httpClient->get($url, [
'http_errors' => FALSE,
'http_errors' => false,
]);

if ($response->getStatusCode() !== 200) {
Expand All @@ -102,7 +99,7 @@ protected function parseData($data, $videoId)
$snippet = $data->items[0]->snippet;
$details = $data->items[0]->contentDetails;

$video = new Video;
$video = new Video();

$video->title = $snippet->title;
$video->description = $snippet->description;
Expand All @@ -119,5 +116,4 @@ protected function parseData($data, $videoId)

return $video;
}

}
9 changes: 2 additions & 7 deletions Nextras/YoutubeApi/Video.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?php

/**
* This file is part of the Nextras community extensions of Nette Framework
*
* Copyright (c) 2012 Jan Skrasek (http://jan.skrasek.com)
*
* This file is part of the YoutubeApi library.
* @license MIT
* @link https://github.com/nextras
* @link https://github.com/nextras/youtube-api
*/

namespace Nextras\YoutubeApi;
Expand All @@ -17,7 +14,6 @@

class Video extends Nette\Object
{

/** @var string */
public $title;

Expand All @@ -32,5 +28,4 @@ class Video extends Nette\Object

/** @var array */
public $thumbs;

}

0 comments on commit 0a5f731

Please sign in to comment.