From fca831beff2aba224df0c70ead4f05ce161fcde2 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Sat, 23 Dec 2017 23:57:36 +0100 Subject: [PATCH] added types --- Nextras/YoutubeApi/Reader.php | 18 +++++++----------- Nextras/YoutubeApi/Video.php | 3 +-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Nextras/YoutubeApi/Reader.php b/Nextras/YoutubeApi/Reader.php index 7912a0a..271bf91 100644 --- a/Nextras/YoutubeApi/Reader.php +++ b/Nextras/YoutubeApi/Reader.php @@ -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; @@ -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) { @@ -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); @@ -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, [ @@ -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)) { diff --git a/Nextras/YoutubeApi/Video.php b/Nextras/YoutubeApi/Video.php index 292afd5..7af3066 100644 --- a/Nextras/YoutubeApi/Video.php +++ b/Nextras/YoutubeApi/Video.php @@ -11,7 +11,6 @@ use Nette; - class Video { use Nette\SmartObject; @@ -30,7 +29,7 @@ class Video /** @var array */ public $thumbs; - + /** @var string */ public $embed; }