Skip to content

Commit 6ab7279

Browse files
author
Pacha Cervantes
authored
use Arr and Str helper classes (#97)
1 parent 3552329 commit 6ab7279

29 files changed

+73
-43
lines changed

src/Commands/DomainWhitelistingCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Casperlaitw\LaravelFbMessenger\Commands;
1010

1111
use Casperlaitw\LaravelFbMessenger\Messages\DomainWhitelisting;
12+
use Illuminate\Support\Arr;
1213

1314
/**
1415
* Class DomainWhitelistingCommand
@@ -51,7 +52,7 @@ private function read()
5152
{
5253
$command = new DomainWhitelisting();
5354
$command->setAction(DomainWhitelisting::TYPE_READ)->useGet();
54-
$response = collect(array_get($this->handler->send($command)->getResponse(), 'data.0.whitelisted_domains', []))
55+
$response = collect(Arr::get($this->handler->send($command)->getResponse(), 'data.0.whitelisted_domains', []))
5556
->map(function ($item) {
5657
return [$item];
5758
});

src/Commands/HomeUrlCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Casperlaitw\LaravelFbMessenger\Commands;
55

66
use Casperlaitw\LaravelFbMessenger\Messages\HomeUrl;
7+
use Illuminate\Support\Arr;
78

89
/**
910
* Class HomeUrlCommand
@@ -49,7 +50,7 @@ private function read()
4950
{
5051
$command = new HomeUrl();
5152
$command->setAction(HomeUrl::TYPE_READ)->useGet();
52-
$response = collect(array_get($this->handler->send($command)->getResponse(), 'data.0.home_url', []))
53+
$response = collect(Arr::get($this->handler->send($command)->getResponse(), 'data.0.home_url', []))
5354
->map(function ($item) {
5455
return [$item];
5556
});

src/Commands/MessengerCodeCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Casperlaitw\LaravelFbMessenger\Commands;
44

55
use Casperlaitw\LaravelFbMessenger\Messages\MessengerCode;
6+
use Illuminate\Support\Arr;
67

78
class MessengerCodeCommand extends BaseCommand
89
{
@@ -35,6 +36,6 @@ public function handle()
3536
$message->setRef($ref);
3637
}
3738

38-
$this->comment(array_get($this->handler->send($message), 'uri'));
39+
$this->comment(Arr::get($this->handler->send($message), 'uri'));
3940
}
4041
}

src/Contracts/Debug/Handler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Exception;
1212
use Illuminate\Contracts\Debug\ExceptionHandler;
13+
use Illuminate\Support\Arr;
1314

1415
class Handler implements ExceptionHandler
1516
{
@@ -61,9 +62,9 @@ public function render($request, Exception $e)
6162
'message' => $e->getMessage(),
6263
'trace' => collect($e->getTrace())->map(function ($item) {
6364
return [
64-
'file' => array_get($item, 'file'),
65-
'line' => array_get($item, 'line'),
66-
'method' => array_get($item, 'function'),
65+
'file' => Arr::get($item, 'file'),
66+
'line' => Arr::get($item, 'line'),
67+
'method' => Arr::get($item, 'function'),
6768
];
6869
})->toArray(),
6970
];

src/Contracts/HandleMessageResponse.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Casperlaitw\LaravelFbMessenger\Contracts;
99

10+
use Illuminate\Support\Arr;
11+
1012
/**
1113
* Class HandleMessageResponse
1214
* @package Casperlaitw\LaravelFbMessenger\Contracts
@@ -37,7 +39,7 @@ public function getResponse()
3739
if (!empty($this->response['error'])) {
3840
return $this->handleError($this->response['error']);
3941
}
40-
return array_get($this->response, 'result', $this->response);
42+
return Arr::get($this->response, 'result', $this->response);
4143
}
4244

4345
/**

tests/Collections/ButtonCollectionTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Casperlaitw\LaravelFbMessenger\Exceptions\OnlyUseByItselfException;
44
use Casperlaitw\LaravelFbMessenger\Exceptions\ValidatorStructureException;
55
use Casperlaitw\LaravelFbMessenger\Messages\Button;
6+
use Illuminate\Support\Str;
67
use Faker\Factory;
78
use Mockery as m;
89

@@ -54,7 +55,7 @@ public function test_add_call_button()
5455
{
5556
$fake = Factory::create();
5657
$collection = new ButtonCollection();
57-
$title = str_random();
58+
$title = Str::random();
5859
$phone = $fake->phoneNumber;
5960
$collection->addCallButton($title, $phone);
6061

@@ -73,7 +74,7 @@ public function test_add_share_button()
7374

7475
public function test_add_account_link_button()
7576
{
76-
$url = str_random();
77+
$url = Str::random();
7778
$collection = new ButtonCollection();
7879
$collection->addAccountLinkButton($url);
7980
$expected = new Button(Button::TYPE_ACCOUNT_LINK, null, $url);

tests/Contracts/BotTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Casperlaitw\LaravelFbMessenger\Messages\MessengerCode;
77
use Casperlaitw\LaravelFbMessenger\Messages\User;
88
use Illuminate\Broadcasting\BroadcastException;
9+
use Illuminate\Support\Str;
910
use Illuminate\Events\Dispatcher;
1011
use Mockery as m;
1112

@@ -24,7 +25,7 @@ protected function setUp()
2425

2526
public function test_send_success()
2627
{
27-
$message = new Greeting(['locale' => 'default', 'text' => str_random()]);
28+
$message = new Greeting(['locale' => 'default', 'text' => Str::random()]);
2829
$this->bot->setSecret('test_app_secret');
2930
$this->bot->send($message);
3031
}

tests/Contracts/Debug/HandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Casperlaitw\LaravelFbMessenger\Contracts\Debug\Debug;
55
use Illuminate\Contracts\Debug\ExceptionHandler;
66
use Illuminate\Events\Dispatcher;
7+
use Illuminate\Support\Arr;
78
use Mockery as m;
89
use Symfony\Component\HttpFoundation\Response;
910

@@ -56,6 +57,6 @@ public function test_render()
5657

5758
$actual = $this->getPrivateProperty(Handler::class, 'debug')->getValue($this->handler);
5859
$this->assertEquals(500, $actual->getStatus());
59-
$this->assertEquals('ERROR', array_get($actual->getResponse(), 'message'));
60+
$this->assertEquals('ERROR', Arr::get($actual->getResponse(), 'message'));
6061
}
6162
}

tests/Contracts/Messages/AttachmentTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
use Casperlaitw\LaravelFbMessenger\Contracts\Messages\Attachment;
33
use Casperlaitw\LaravelFbMessenger\Exceptions\InvalidTypeException;
4+
use Illuminate\Support\Str;
45
use Faker\Factory;
56
use Mockery as m;
67

@@ -22,7 +23,7 @@ protected function setUp()
2223
{
2324
parent::setUp();
2425
$this->faker = Factory::create();
25-
$sender = str_random();
26+
$sender = Str::random();
2627
$type = Attachment::TYPE_IMAGE;
2728
$image = $this->faker->url;
2829
$this->attachment = new AttachmentStub($sender, $type, ['url' => $image]);
@@ -57,7 +58,7 @@ public function test_disable_reuse()
5758

5859
public function test_set_attachment_id()
5960
{
60-
$id = str_random();
61+
$id = Str::random();
6162
$this->attachment->setAttachmentId($id);
6263

6364
$this->assertEquals(['attachment_id' => $id], $this->attachment->getPayload());

tests/Contracts/Messages/StructuredTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Casperlaitw\LaravelFbMessenger\Messages\Button;
44
use Casperlaitw\LaravelFbMessenger\Messages\ButtonTemplate;
5+
use Illuminate\Support\Str;
56
use Mockery as m;
67

78
/**
@@ -13,13 +14,13 @@ class StructuredTest extends TestCase
1314
{
1415
public function test_call_method()
1516
{
16-
$button = new ButtonTemplate(str_random(), str_random());
17+
$button = new ButtonTemplate(Str::random(), Str::random());
1718
$this->assertTrue($button->validator($this->getMessageButtonMock()));
1819
}
1920

2021
public function test_non_collection_method()
2122
{
22-
$button = new ButtonTemplate(str_random(), str_random());
23+
$button = new ButtonTemplate(Str::random(), Str::random());
2324
$button->getError();
2425
}
2526

0 commit comments

Comments
 (0)