From 46032e1ee16af24a94b21d972712579770c74bac Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 30 Mar 2016 01:49:08 +0200 Subject: [PATCH] Use PSR-2 --- Gruntfile.js | 3 +++ classes/Config.php | 14 +++++++----- classes/VideoDownload.php | 21 +++++++++++------- controllers/FrontController.php | 26 ++++++++++++++-------- js/cast.js | 39 ++++++++++++++++++++++----------- tests/ConfigTest.php | 4 +++- tests/VideoDownloadTest.php | 4 +++- 7 files changed, 73 insertions(+), 38 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9998185..3dcbf99 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -28,6 +28,9 @@ module.exports = function (grunt) { } }, phpcs: { + options: { + standard: 'PSR2' + }, php: { src: ['*.php', 'classes/*.php', 'controllers/*.php'] }, diff --git a/classes/Config.php b/classes/Config.php index 2e2bf11..0c1aa8c 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -11,7 +11,9 @@ * @link http://rudloff.pro * */ namespace Alltube; + use Symfony\Component\Yaml\Yaml; + /** * Class to manage config parameters * @@ -23,9 +25,9 @@ use Symfony\Component\Yaml\Yaml; * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -Class Config +class Config { - private static $_instance; + private static $instance; public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py'; public $python = '/usr/bin/python'; @@ -43,7 +45,7 @@ Class Config if (is_file($yamlfile)) { $yaml = Yaml::parse(file_get_contents($yamlfile)); if (isset($yaml) && is_array($yaml)) { - foreach ($yaml as $param=>$value) { + foreach ($yaml as $param => $value) { if (isset($this->$param)) { $this->$param = $value; } @@ -62,9 +64,9 @@ Class Config */ public static function getInstance() { - if (is_null(self::$_instance)) { - self::$_instance = new Config(); + if (is_null(self::$instance)) { + self::$instance = new Config(); } - return self::$_instance; + return self::$instance; } } diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index 9e2b435..06a7f48 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -11,6 +11,7 @@ * @link http://rudloff.pro * */ namespace Alltube; + /** * Main class * @@ -22,14 +23,14 @@ namespace Alltube; * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -Class VideoDownload +class VideoDownload { /** * Get the user agent used youtube-dl * * @return string UA * */ - static function getUA() + public static function getUA() { $config = Config::getInstance(); $cmd = escapeshellcmd( @@ -48,7 +49,7 @@ Class VideoDownload * * @return array Extractors * */ - static function listExtractors() + public static function listExtractors() { $config = Config::getInstance(); $cmd = escapeshellcmd( @@ -70,7 +71,7 @@ Class VideoDownload * * @return string Filename * */ - static function getFilename($url, $format=null) + public static function getFilename($url, $format = null) { $config = Config::getInstance(); $cmd = escapeshellcmd( @@ -96,7 +97,7 @@ Class VideoDownload * * @return string JSON * */ - static function getJSON($url, $format=null) + public static function getJSON($url, $format = null) { $config = Config::getInstance(); $cmd = escapeshellcmd( @@ -108,7 +109,9 @@ Class VideoDownload } $cmd .=' --dump-json '.escapeshellarg($url)." 2>&1"; exec( - $cmd, $result, $code + $cmd, + $result, + $code ); if ($code>0) { throw new \Exception(implode(PHP_EOL, $result)); @@ -125,7 +128,7 @@ Class VideoDownload * * @return string URL of video * */ - static function getURL($url, $format=null) + public static function getURL($url, $format = null) { $config = Config::getInstance(); $cmd = escapeshellcmd( @@ -137,7 +140,9 @@ Class VideoDownload } $cmd .=' -g '.escapeshellarg($url)." 2>&1"; exec( - $cmd, $result, $code + $cmd, + $result, + $code ); if ($code>0) { throw new \Exception(implode(PHP_EOL, $result)); diff --git a/controllers/FrontController.php b/controllers/FrontController.php index c4bd33a..06f8188 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -11,8 +11,10 @@ * @link http://rudloff.pro * */ namespace Alltube\Controller; + use Alltube\VideoDownload; use Alltube\Config; + /** * Main controller * @@ -35,7 +37,7 @@ class FrontController * * @return void */ - static function index($request, $response) + public static function index($request, $response) { global $container; $config = Config::getInstance(); @@ -68,7 +70,7 @@ class FrontController * * @return void */ - static function extractors($request, $response) + public static function extractors($request, $response) { global $container; $container->view->render( @@ -98,7 +100,7 @@ class FrontController * * @return void */ - static function video($request, $response) + public static function video($request, $response) { global $container; $config = Config::getInstance(); @@ -122,8 +124,11 @@ class FrontController pathinfo( VideoDownload::getFilename( $video->webpage_url - ), PATHINFO_FILENAME - ).'.mp3', ENT_COMPAT, 'ISO-8859-1' + ), + PATHINFO_FILENAME + ).'.mp3', + ENT_COMPAT, + 'ISO-8859-1' ).'"' ); header("Content-Type: audio/mpeg"); @@ -141,8 +146,11 @@ class FrontController pathinfo( VideoDownload::getFilename( $video->webpage_url - ), PATHINFO_FILENAME - ).'.mp3', ENT_COMPAT, 'ISO-8859-1' + ), + PATHINFO_FILENAME + ).'.mp3', + ENT_COMPAT, + 'ISO-8859-1' ).'"' ); header("Content-Type: audio/mpeg"); @@ -208,7 +216,7 @@ class FrontController * * @return void */ - static function redirect($request, $response) + public static function redirect($request, $response) { global $app; if (isset($_GET["url"])) { @@ -230,7 +238,7 @@ class FrontController * * @return void */ - static function json($request, $response) + public static function json($request, $response) { global $app; if (isset($_GET["url"])) { diff --git a/js/cast.js b/js/cast.js index 57261fe..22d6e7a 100644 --- a/js/cast.js +++ b/js/cast.js @@ -3,12 +3,14 @@ var launchBtn, disabledBtn, stopBtn; var session, currentMedia; -function receiverListener(e) { +function receiverListener(e) +{ 'use strict'; console.log('receiverListener', e); } -function onMediaDiscovered(how, media) { +function onMediaDiscovered(how, media) +{ 'use strict'; console.log('onMediaDiscovered', how); currentMedia = media; @@ -18,7 +20,8 @@ function onMediaDiscovered(how, media) { } } -function sessionListener(e) { +function sessionListener(e) +{ 'use strict'; session = e; session.addMediaListener(onMediaDiscovered.bind(this, 'addMediaListener')); @@ -27,41 +30,48 @@ function sessionListener(e) { } } -function onStopCast() { +function onStopCast() +{ 'use strict'; stopBtn.classList.add('cast_hidden'); launchBtn.classList.remove('cast_hidden'); } -function stopCast() { +function stopCast() +{ 'use strict'; session.stop(onStopCast); } -function onMediaError() { +function onMediaError() +{ 'use strict'; console.log('onMediaError'); stopCast(); } -function onRequestSessionSuccess(e) { +function onRequestSessionSuccess(e) +{ 'use strict'; session = e; var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo); session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError); } -function onLaunchError(e) { +function onLaunchError(e) +{ 'use strict'; console.log('onLaunchError', e.description); } -function launchCast() { +function launchCast() +{ 'use strict'; chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError); } -function onInitSuccess() { +function onInitSuccess() +{ 'use strict'; launchBtn = document.getElementById('cast_btn_launch'); disabledBtn = document.getElementById('cast_disabled'); @@ -74,18 +84,21 @@ function onInitSuccess() { } } -function onError() { +function onError() +{ 'use strict'; console.log('onError'); } -function initializeCastApi() { +function initializeCastApi() +{ 'use strict'; var sessionRequest = new chrome.cast.SessionRequest(chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID), apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener, chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED); chrome.cast.initialize(apiConfig, onInitSuccess, onError); } -function loadCastApi(loaded, errorInfo) { +function loadCastApi(loaded, errorInfo) +{ 'use strict'; if (loaded) { initializeCastApi(); diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 718eb0f..c4fde67 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -10,6 +10,8 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ +namespace Alltube\Test; + use Alltube\Config; /** @@ -23,7 +25,7 @@ use Alltube\Config; * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -class ConfigTest extends PHPUnit_Framework_TestCase +class ConfigTest extends \PHPUnit_Framework_TestCase { /** diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index fc84cf7..9f0c7b4 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -10,6 +10,8 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ +namespace Alltube\Test; + use Alltube\VideoDownload; /** @@ -23,7 +25,7 @@ use Alltube\VideoDownload; * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -class VideoDownloadTest extends PHPUnit_Framework_TestCase +class VideoDownloadTest extends \PHPUnit_Framework_TestCase { /** * Test getUA function