Skip to content

Commit

Permalink
added types
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Dec 23, 2017
1 parent 6bf2042 commit fca831b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
18 changes: 7 additions & 11 deletions Nextras/YoutubeApi/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Reader
{
use Nette\SmartObject;
/** @var string */
const FETCH_URL = 'https://www.googleapis.com/youtube/v3/videos?key=%s&part=snippet,contentDetails&id=%s';
private const FETCH_URL = 'https://www.googleapis.com/youtube/v3/videos?key=%s&part=snippet,contentDetails&id=%s';

/** @var string */
private $apiKey;
Expand All @@ -26,7 +26,7 @@ class Reader
private $httpClient;


public function __construct($apiKey, Client $httpClient = null)
public function __construct(string $apiKey, ?Client $httpClient = null)
{
$this->apiKey = $apiKey;
if ($httpClient === null) {
Expand All @@ -38,10 +38,8 @@ public function __construct($apiKey, Client $httpClient = null)

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

Expand All @@ -59,17 +57,15 @@ public function getVideoByUrl($videoUrl)


/**
* Fetchs video data
* @param string $videoId
* @return Video
* Fetches video data
*/
public function getVideo($videoId)
public function getVideo(string $videoId): Video
{
return $this->parseData($this->getData($videoId), $videoId);
}


protected function getData($videoId)
protected function getData(string $videoId): string
{
$url = sprintf(self::FETCH_URL, $this->apiKey, $videoId);
$response = $this->httpClient->get($url, [
Expand All @@ -84,7 +80,7 @@ protected function getData($videoId)
}


protected function parseData($data, $videoId)
protected function parseData(string $data, string $videoId): Video
{
$data = Nette\Utils\Json::decode($data);
if (!isset($data->items[0]->snippet) || !isset($data->items[0]->contentDetails)) {
Expand Down
3 changes: 1 addition & 2 deletions Nextras/YoutubeApi/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Nette;



class Video
{
use Nette\SmartObject;
Expand All @@ -30,7 +29,7 @@ class Video

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

/** @var string */
public $embed;
}

0 comments on commit fca831b

Please sign in to comment.