Skip to content

Commit

Permalink
Upgrade CS-Fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Jan 15, 2022
1 parent 9b64c1e commit 012c661
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/composer.lock
/vendor
/.idea
/.php_cs.cache
/.php-cs-fixer.cache
/.phpunit.result.cache
/phpunit.xml
18 changes: 13 additions & 5 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$finder = PhpCsFixer\Finder::create()
$finder = (new PhpCsFixer\Finder())
->notPath('config')
->notPath('vendor')
->in(__DIR__)
Expand All @@ -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,
Expand Down Expand Up @@ -46,6 +49,7 @@
'concat_space' => [
'spacing' => 'one',
],
'declare_strict_types' => false,
'dir_constant' => true,
'function_to_constant' => true,
'function_typehint_space' => true,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'],
],
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/TwilioClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Notifications/Channels/TwilioChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Providers/TwilioProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
12 changes: 9 additions & 3 deletions tests/ConnectionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -136,8 +137,13 @@ protected function getEnvironmentSetUp($app)
);
}

protected function getPackageProviders($app)
/**
* @return class-string<ServiceProvider>
*/
protected function getPackageProviders($app): array
{
return [TwilioProvider::class];
return [
TwilioProvider::class,
];
}
}
13 changes: 10 additions & 3 deletions tests/Facades/TwilioClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -134,14 +135,20 @@ protected function getEnvironmentSetUp($app)
);
}

protected function getPackageProviders($app)
/**
* @return class-string<ServiceProvider>
*/
protected function getPackageProviders($app): array
{
return [
TwilioProvider::class,
];
}

protected function getPackageAliases($app)
/**
* @return array<string, class-string<ServiceProvider>>
*/
protected function getPackageAliases($app): array
{
return [
'TwilioClient' => TwilioClientFacade::class,
Expand Down
31 changes: 12 additions & 19 deletions tests/Notifications/Channels/TwilioChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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';
Expand All @@ -48,28 +46,26 @@ 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)
{
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';
Expand All @@ -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)
Expand All @@ -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;
}
};

Expand Down
11 changes: 8 additions & 3 deletions tests/Providers/TwilioProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -41,8 +41,13 @@ protected function getEnvironmentSetUp($app)
);
}

protected function getPackageProviders($app)
/**
* @return class-string<ServiceProvider>
*/
protected function getPackageProviders($app): array
{
return [TwilioProvider::class];
return [
TwilioProvider::class,
];
}
}
4 changes: 2 additions & 2 deletions tests/Twilio/Http/LaravelHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand Down Expand Up @@ -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');
},
]
Expand Down
20 changes: 10 additions & 10 deletions tests/TwilioClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;

Expand All @@ -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
Expand All @@ -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')
Expand All @@ -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;

Expand All @@ -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')
Expand All @@ -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;

Expand Down

0 comments on commit 012c661

Please sign in to comment.