From 012c661ed25e2ef3c6b42013d9afda8662880ab7 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 15 Jan 2022 12:46:41 -0600 Subject: [PATCH] Upgrade CS-Fixer --- .gitattributes | 2 +- .gitignore | 2 +- .php_cs => .php-cs-fixer.php | 18 ++++++++--- src/Facades/TwilioClient.php | 2 +- src/Notifications/Channels/TwilioChannel.php | 2 +- src/Providers/TwilioProvider.php | 4 +-- tests/ConnectionManagerTest.php | 12 +++++-- tests/Facades/TwilioClientTest.php | 13 ++++++-- .../Channels/TwilioChannelTest.php | 31 +++++++------------ tests/Providers/TwilioProviderTest.php | 11 +++++-- tests/Twilio/Http/LaravelHttpClientTest.php | 4 +-- tests/TwilioClientTest.php | 20 ++++++------ 12 files changed, 70 insertions(+), 51 deletions(-) rename .php_cs => .php-cs-fixer.php (90%) diff --git a/.gitattributes b/.gitattributes index 799fedc..525249a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,7 +3,7 @@ /tests export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/.php_cs export-ignore +/.php-cs-fixer.php export-ignore /CHANGELOG.md export-ignore /README.md export-ignore /phpunit.xml.dist export-ignore diff --git a/.gitignore b/.gitignore index 897ae32..abff542 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /composer.lock /vendor /.idea -/.php_cs.cache +/.php-cs-fixer.cache /.phpunit.result.cache /phpunit.xml diff --git a/.php_cs b/.php-cs-fixer.php similarity index 90% rename from .php_cs rename to .php-cs-fixer.php index dfe791a..2f3ce41 100644 --- a/.php_cs +++ b/.php-cs-fixer.php @@ -1,6 +1,6 @@ notPath('config') ->notPath('vendor') ->in(__DIR__) @@ -9,10 +9,13 @@ ->ignoreDotFiles(true) ->ignoreVCS(true); -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) ->setRules( [ - 'psr0' => false, + '@PHP71Migration' => true, + '@PHP71Migration:risky' => true, + '@PHPUnit84Migration:risky' => true, + '@PSR12' => true, '@PSR2' => true, 'align_multiline_comment' => true, 'array_indentation' => true, @@ -46,6 +49,7 @@ 'concat_space' => [ 'spacing' => 'one', ], + 'declare_strict_types' => false, 'dir_constant' => true, 'function_to_constant' => true, 'function_typehint_space' => true, @@ -78,7 +82,6 @@ 'no_multiline_whitespace_around_double_arrow' => true, 'no_null_property_initialization' => true, 'no_short_bool_cast' => true, - 'no_short_echo_tag' => true, 'no_spaces_after_function_name' => true, 'no_spaces_inside_parenthesis' => true, 'no_superfluous_elseif' => true, @@ -106,7 +109,12 @@ 'switch_case_semicolon_to_colon' => true, 'switch_case_space' => true, 'ternary_to_null_coalescing' => true, - 'trailing_comma_in_multiline_array' => true, + 'trailing_comma_in_multiline' => [ + 'after_heredoc' => true, + 'elements' => [ + 'arrays', + ], + ], 'visibility_required' => [ 'elements' => ['property', 'method', 'const'], ], diff --git a/src/Facades/TwilioClient.php b/src/Facades/TwilioClient.php index ce214d2..1737bec 100644 --- a/src/Facades/TwilioClient.php +++ b/src/Facades/TwilioClient.php @@ -2,8 +2,8 @@ namespace BabDev\Twilio\Facades; -use BabDev\Twilio\Contracts\TwilioClient as TwilioClientContract; use BabDev\Twilio\ConnectionManager; +use BabDev\Twilio\Contracts\TwilioClient as TwilioClientContract; use Illuminate\Support\Facades\Facade; use Twilio\Rest\Api\V2010\Account\CallInstance; use Twilio\Rest\Api\V2010\Account\MessageInstance; diff --git a/src/Notifications/Channels/TwilioChannel.php b/src/Notifications/Channels/TwilioChannel.php index 81fb2a8..18ac3b9 100644 --- a/src/Notifications/Channels/TwilioChannel.php +++ b/src/Notifications/Channels/TwilioChannel.php @@ -27,7 +27,7 @@ public function __construct(TwilioClient $twilio) /** * Send the given notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @param Notification $notification * * @return MessageInstance|null diff --git a/src/Providers/TwilioProvider.php b/src/Providers/TwilioProvider.php index 431b7b2..30656a1 100644 --- a/src/Providers/TwilioProvider.php +++ b/src/Providers/TwilioProvider.php @@ -92,9 +92,9 @@ private function registerHttpClient(): void TwilioHttpClient::class, static function (Application $app): TwilioHttpClient { // If Guzzle is installed, then we will either use Laravel's native client or Guzzle directly - if (\class_exists(Guzzle::class)) { + if (class_exists(Guzzle::class)) { // Use Laravel's HTTP client if able - if (\class_exists(Factory::class)) { + if (class_exists(Factory::class)) { return new LaravelHttpClient($app->make(Factory::class)); } diff --git a/tests/ConnectionManagerTest.php b/tests/ConnectionManagerTest.php index 877c18e..b2cf4fa 100644 --- a/tests/ConnectionManagerTest.php +++ b/tests/ConnectionManagerTest.php @@ -7,6 +7,7 @@ use BabDev\Twilio\Providers\TwilioProvider; use BabDev\Twilio\TwilioClient; use Illuminate\Contracts\Container\Container; +use Illuminate\Support\ServiceProvider; use Orchestra\Testbench\TestCase; use Twilio\Rest\Api\V2010\Account\CallInstance; use Twilio\Rest\Api\V2010\Account\MessageInstance; @@ -107,7 +108,7 @@ function (Container $container) use ($client): TwilioClientContract { $this->assertSame($message, $manager->message('me', 'Hello!', [])); } - protected function getEnvironmentSetUp($app) + protected function getEnvironmentSetUp($app): void { // Setup connections configuration $app['config']->set( @@ -136,8 +137,13 @@ protected function getEnvironmentSetUp($app) ); } - protected function getPackageProviders($app) + /** + * @return class-string + */ + protected function getPackageProviders($app): array { - return [TwilioProvider::class]; + return [ + TwilioProvider::class, + ]; } } diff --git a/tests/Facades/TwilioClientTest.php b/tests/Facades/TwilioClientTest.php index 3ec0f85..3f60477 100644 --- a/tests/Facades/TwilioClientTest.php +++ b/tests/Facades/TwilioClientTest.php @@ -8,6 +8,7 @@ use BabDev\Twilio\Providers\TwilioProvider; use BabDev\Twilio\TwilioClient; use Illuminate\Contracts\Container\Container; +use Illuminate\Support\ServiceProvider; use Orchestra\Testbench\TestCase; use Twilio\Rest\Api\V2010\Account\CallInstance; use Twilio\Rest\Api\V2010\Account\MessageInstance; @@ -105,7 +106,7 @@ function (Container $container) use ($client): TwilioClientContract { $this->assertSame($message, \TwilioClient::message('me', 'Hello!', [])); } - protected function getEnvironmentSetUp($app) + protected function getEnvironmentSetUp($app): void { // Setup connections configuration $app['config']->set( @@ -134,14 +135,20 @@ protected function getEnvironmentSetUp($app) ); } - protected function getPackageProviders($app) + /** + * @return class-string + */ + protected function getPackageProviders($app): array { return [ TwilioProvider::class, ]; } - protected function getPackageAliases($app) + /** + * @return array> + */ + protected function getPackageAliases($app): array { return [ 'TwilioClient' => TwilioClientFacade::class, diff --git a/tests/Notifications/Channels/TwilioChannelTest.php b/tests/Notifications/Channels/TwilioChannelTest.php index ccf60b6..987a259 100644 --- a/tests/Notifications/Channels/TwilioChannelTest.php +++ b/tests/Notifications/Channels/TwilioChannelTest.php @@ -14,14 +14,13 @@ final class TwilioChannelTest extends TestCase { public function testANotificationIsSent(): void { - /** @var TwilioClient|MockObject $twilio */ + /** @var MockObject&TwilioClient $twilio */ $twilio = $this->createMock(TwilioClient::class); $twilio->expects($this->once()) ->method('message') ->willReturn($this->createMock(MessageInstance::class)); - $notifiable = new class() - { + $notifiable = new class() { use Notifiable; public function via($notifiable) @@ -35,8 +34,7 @@ public function routeNotificationForTwilio($notification) } }; - $notification = new class() extends Notification - { + $notification = new class() extends Notification { public function toTwilio($notifiable) { return 'This is a test'; @@ -48,13 +46,12 @@ public function toTwilio($notifiable) public function testANotificationIsNotSentWhenTheNotifiableDoesNotProvideARecipient(): void { - /** @var TwilioClient|MockObject $twilio */ + /** @var MockObject&TwilioClient $twilio */ $twilio = $this->createMock(TwilioClient::class); $twilio->expects($this->never()) ->method('message'); - $notifiable = new class() - { + $notifiable = new class() { use Notifiable; public function via($notifiable) @@ -62,14 +59,13 @@ public function via($notifiable) return ['twilio']; } - public function routeNotificationForTwilio($notification) + public function routeNotificationForTwilio($notification): void { - return null; + } }; - $notification = new class() extends Notification - { + $notification = new class() extends Notification { public function toTwilio($notifiable) { return 'This is a test'; @@ -81,13 +77,12 @@ public function toTwilio($notifiable) public function testANotificationIsNotSentWhenTheNotificationDoesNotProvideAMessage(): void { - /** @var TwilioClient|MockObject $twilio */ + /** @var MockObject&TwilioClient $twilio */ $twilio = $this->createMock(TwilioClient::class); $twilio->expects($this->never()) ->method('message'); - $notifiable = new class() - { + $notifiable = new class() { use Notifiable; public function via($notifiable) @@ -101,11 +96,9 @@ public function routeNotificationForTwilio($notification) } }; - $notification = new class() extends Notification - { - public function toTwilio($notifiable) + $notification = new class() extends Notification { + public function toTwilio($notifiable): void { - return null; } }; diff --git a/tests/Providers/TwilioProviderTest.php b/tests/Providers/TwilioProviderTest.php index f53a77d..7dc168e 100644 --- a/tests/Providers/TwilioProviderTest.php +++ b/tests/Providers/TwilioProviderTest.php @@ -28,7 +28,7 @@ public function testServicesAreRegistered(): void $this->assertInstanceOf(TwilioChannel::class, $this->app->get(ChannelManager::class)->driver('twilio')); } - protected function getEnvironmentSetUp($app) + protected function getEnvironmentSetUp($app): void { // Setup connections configuration $app['config']->set( @@ -41,8 +41,13 @@ protected function getEnvironmentSetUp($app) ); } - protected function getPackageProviders($app) + /** + * @return class-string + */ + protected function getPackageProviders($app): array { - return [TwilioProvider::class]; + return [ + TwilioProvider::class, + ]; } } diff --git a/tests/Twilio/Http/LaravelHttpClientTest.php b/tests/Twilio/Http/LaravelHttpClientTest.php index 2e17a17..145ae81 100644 --- a/tests/Twilio/Http/LaravelHttpClientTest.php +++ b/tests/Twilio/Http/LaravelHttpClientTest.php @@ -13,7 +13,7 @@ final class LaravelHttpClientTest extends TestCase { public static function setUpBeforeClass(): void { - if (!\class_exists(Factory::class)) { + if (!class_exists(Factory::class)) { self::markTestSkipped('Test only applies to Laravel 7 or newer.'); } @@ -104,7 +104,7 @@ public function testAnExceptionIsThrownWhenThereIsAnErrorPerformingTheRequest(): $factory = $this->app->make(Factory::class); $factory->fake( [ - $url => static function () { + $url => static function (): void { throw new \RuntimeException('Testing'); }, ] diff --git a/tests/TwilioClientTest.php b/tests/TwilioClientTest.php index ef43341..1523295 100644 --- a/tests/TwilioClientTest.php +++ b/tests/TwilioClientTest.php @@ -17,7 +17,7 @@ public function testTheSdkInstanceCanBeRetrieved(): void { $defaultFrom = '+19418675309'; - /** @var Client|MockObject $twilio */ + /** @var MockObject&Client $twilio */ $twilio = $this->createMock(Client::class); $this->assertSame($twilio, (new TwilioClient($twilio, $defaultFrom))->twilio()); @@ -31,14 +31,14 @@ public function testACallCanBeCreated(): void 'url' => 'https://www.babdev.com', ]; - /** @var CallList|MockObject $calls */ + /** @var MockObject&CallList $calls */ $calls = $this->createMock(CallList::class); $calls->expects($this->once()) ->method('create') ->with($to, $defaultFrom, $params) ->willReturn($this->createMock(CallInstance::class)); - /** @var Client|MockObject $twilio */ + /** @var MockObject&Client $twilio */ $twilio = $this->createMock(Client::class); $twilio->calls = $calls; @@ -54,18 +54,18 @@ public function testACallCanBeCreatedWithACustomFromNumber(): void 'url' => 'https://www.babdev.com', ]; - /** @var CallList|MockObject $calls */ + /** @var MockObject&CallList $calls */ $calls = $this->createMock(CallList::class); $calls->expects($this->once()) ->method('create') ->with($to, $customFrom, $params) ->willReturn($this->createMock(CallInstance::class)); - /** @var Client|MockObject $twilio */ + /** @var MockObject&Client $twilio */ $twilio = $this->createMock(Client::class); $twilio->calls = $calls; - $this->assertInstanceOf(CallInstance::class, (new TwilioClient($twilio, $defaultFrom))->call($to, \array_merge($params, ['from' => $customFrom]))); + $this->assertInstanceOf(CallInstance::class, (new TwilioClient($twilio, $defaultFrom))->call($to, array_merge($params, ['from' => $customFrom]))); } public function testAMessageCanBeSent(): void @@ -74,7 +74,7 @@ public function testAMessageCanBeSent(): void $defaultFrom = '+19418675309'; $message = 'Test Message'; - /** @var MessageList|MockObject $messages */ + /** @var MockObject&MessageList $messages */ $messages = $this->createMock(MessageList::class); $messages->expects($this->once()) ->method('create') @@ -87,7 +87,7 @@ public function testAMessageCanBeSent(): void ) ->willReturn($this->createMock(MessageInstance::class)); - /** @var Client|MockObject $twilio */ + /** @var MockObject&Client $twilio */ $twilio = $this->createMock(Client::class); $twilio->messages = $messages; @@ -101,7 +101,7 @@ public function testAMessageCanBeSentWithACustomFromNumber(): void $customFrom = '+16518675309'; $message = 'Test Message'; - /** @var MessageList|MockObject $messages */ + /** @var MockObject&MessageList $messages */ $messages = $this->createMock(MessageList::class); $messages->expects($this->once()) ->method('create') @@ -114,7 +114,7 @@ public function testAMessageCanBeSentWithACustomFromNumber(): void ) ->willReturn($this->createMock(MessageInstance::class)); - /** @var Client|MockObject $twilio */ + /** @var MockObject&Client $twilio */ $twilio = $this->createMock(Client::class); $twilio->messages = $messages;