From 7f062d90dd61ea69c6f7d74a98b516e16b7ee346 Mon Sep 17 00:00:00 2001 From: Bartosz Zbislawski Date: Sat, 8 Jul 2017 23:09:33 +0100 Subject: [PATCH] Upgrade to php7 and psr-4 --- .gitignore | 1 + composer.json | 15 ++-- src/Alaouy/Youtube/YoutubeServiceProvider.php | 84 ------------------- src/{Alaouy/Youtube => }/Facades/Youtube.php | 0 src/{Alaouy/Youtube => }/Youtube.php | 0 src/YoutubeServiceProvider.php | 40 +++++++++ src/config/config.php | 8 -- src/config/youtube.php | 18 ++-- tests/YoutubeTest.php | 40 +++------ 9 files changed, 76 insertions(+), 130 deletions(-) delete mode 100644 src/Alaouy/Youtube/YoutubeServiceProvider.php rename src/{Alaouy/Youtube => }/Facades/Youtube.php (100%) rename src/{Alaouy/Youtube => }/Youtube.php (100%) create mode 100644 src/YoutubeServiceProvider.php delete mode 100644 src/config/config.php diff --git a/.gitignore b/.gitignore index 5826402..9c10d38 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.phar composer.lock .DS_Store +.idea diff --git a/composer.json b/composer.json index 5a5d06e..bcba5ec 100644 --- a/composer.json +++ b/composer.json @@ -10,14 +10,19 @@ } ], "require": { - "php": ">=5.3.0" + "php": "^7.0" }, - "require-dev":{ - "phpunit/phpunit": "3.7.*@stable" + "require-dev": { + "phpunit/phpunit": "^6.1" }, "autoload": { - "psr-0": { - "Alaouy\\Youtube\\": "src/" + "psr-4": { + "Alaouy\\Youtube\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Alaouy\\Youtube\\Tests\\": "tests" } }, "minimum-stability": "dev" diff --git a/src/Alaouy/Youtube/YoutubeServiceProvider.php b/src/Alaouy/Youtube/YoutubeServiceProvider.php deleted file mode 100644 index c78747c..0000000 --- a/src/Alaouy/Youtube/YoutubeServiceProvider.php +++ /dev/null @@ -1,84 +0,0 @@ -isLegacyLaravel() || $this->isOldLaravel()) { - $this->package('alaouy/youtube', 'alaouy/youtube'); - } - - $loader = \Illuminate\Foundation\AliasLoader::getInstance(); - $loader->alias('Youtube', 'Alaouy\Youtube\Facades\Youtube'); - $this->publishes(array(__DIR__ . '/../../config/youtube.php' => config_path('youtube.php'))); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - if ($this->isLegacyLaravel() || $this->isOldLaravel()) { - $this->app['youtube'] = $this->app->share(function ($app) { - $key = \Config::get('alaouy/youtube::KEY'); - return new Youtube($key); - }); - - return; - } - - if (floatval(Application::VERSION) >= 5.4) { - $this->app->bind("youtube", function(){ - return new Youtube(config('youtube.KEY')); - }); - } elseif(floatval(Application::VERSION) >= 5.1) { //Laravel 5.1+ fix - $this->app->bind("youtube", function(){ - return $this->app->make('Alaouy\Youtube\Youtube', [config('youtube.KEY')]); - }); - }else{ - $this->app->bindShared('youtube', function () { - return $this->app->make('Alaouy\Youtube\Youtube', [config('youtube.KEY')]); - }); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array('youtube'); - } - - public function isLegacyLaravel() - { - return Str::startsWith(Application::VERSION, array('4.1.', '4.2.')); - } - - public function isOldLaravel() - { - return Str::startsWith(Application::VERSION, '4.0.'); - } -} diff --git a/src/Alaouy/Youtube/Facades/Youtube.php b/src/Facades/Youtube.php similarity index 100% rename from src/Alaouy/Youtube/Facades/Youtube.php rename to src/Facades/Youtube.php diff --git a/src/Alaouy/Youtube/Youtube.php b/src/Youtube.php similarity index 100% rename from src/Alaouy/Youtube/Youtube.php rename to src/Youtube.php diff --git a/src/YoutubeServiceProvider.php b/src/YoutubeServiceProvider.php new file mode 100644 index 0000000..2fc9cc6 --- /dev/null +++ b/src/YoutubeServiceProvider.php @@ -0,0 +1,40 @@ +publishes(array(__DIR__ . '/config/youtube.php' => config_path('youtube.php'))); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->app->bind('youtube', function () { + return new Youtube(config('youtube.key')); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [Youtube::class]; + } +} diff --git a/src/config/config.php b/src/config/config.php deleted file mode 100644 index e4bd94f..0000000 --- a/src/config/config.php +++ /dev/null @@ -1,8 +0,0 @@ - 'YOUR API KEY' -); \ No newline at end of file diff --git a/src/config/youtube.php b/src/config/youtube.php index e4bd94f..84c15a9 100644 --- a/src/config/youtube.php +++ b/src/config/youtube.php @@ -1,8 +1,14 @@ - 'YOUR API KEY' -); \ No newline at end of file +return [ + 'key' => 'YOUR_API_KEY' +]; diff --git a/tests/YoutubeTest.php b/tests/YoutubeTest.php index f4a5708..2df3d7f 100644 --- a/tests/YoutubeTest.php +++ b/tests/YoutubeTest.php @@ -1,24 +1,20 @@ youtube = new Youtube($TEST_API_KEY); + $this->youtube = new Youtube(self::TEST_API_KEY); } public function tearDown() @@ -26,17 +22,15 @@ public function tearDown() $this->youtube = null; } - public function MalFormURLProvider() + public function urlProvider() { - return array( - array('https://'), - array('http://www.yuotube.com'), - ); + return [ + ['https://'], + ['http://www.yuotube.com'], + ]; } /** - * - * * @expectedException \Exception */ public function testConstructorFail() @@ -45,8 +39,6 @@ public function testConstructorFail() } /** - * - * * @expectedException \Exception */ public function testConstructorFail2() @@ -55,8 +47,6 @@ public function testConstructorFail2() } /** - * - * * @expectedException \Exception */ public function testInvalidApiKey() @@ -244,9 +234,7 @@ public function testParseVIdFromEmbedURL() } /** - * - * - * @dataProvider MalFormURLProvider + * @dataProvider urlProvider * @expectedException \Exception */ public function testParseVIdFromURLException($url) @@ -255,8 +243,6 @@ public function testParseVIdFromURLException($url) } /** - * - * * @expectedException \Exception */ public function testParseVIdException()