From bd46db8741729d5a82a820b85f4244c64fc469af Mon Sep 17 00:00:00 2001 From: Matthew Kilgore Date: Sat, 25 Jul 2020 21:17:43 -0400 Subject: [PATCH] Replace depreciated functions with classfull verions --- .../src/Api/Controller/CreateTagController.php | 3 ++- .../src/Api/Controller/DeleteTagController.php | 3 ++- .../src/Api/Controller/OrderTagsController.php | 5 +++-- .../src/Api/Controller/UpdateTagController.php | 5 +++-- extensions/tags/src/Command/CreateTagHandler.php | 15 ++++++++------- extensions/tags/src/Command/EditTagHandler.php | 3 ++- .../src/Listener/CreatePostWhenTagsAreChanged.php | 3 ++- .../tags/src/Listener/FilterPostsQueryByTag.php | 3 ++- .../tags/src/Listener/UpdateTagMetadata.php | 3 ++- 9 files changed, 26 insertions(+), 17 deletions(-) diff --git a/extensions/tags/src/Api/Controller/CreateTagController.php b/extensions/tags/src/Api/Controller/CreateTagController.php index e6a64bcc6..fb1b7f9d5 100644 --- a/extensions/tags/src/Api/Controller/CreateTagController.php +++ b/extensions/tags/src/Api/Controller/CreateTagController.php @@ -13,6 +13,7 @@ use Flarum\Api\Controller\AbstractCreateController; use Flarum\Tags\Api\Serializer\TagSerializer; use Flarum\Tags\Command\CreateTag; use Illuminate\Contracts\Bus\Dispatcher; +use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -47,7 +48,7 @@ class CreateTagController extends AbstractCreateController protected function data(ServerRequestInterface $request, Document $document) { return $this->bus->dispatch( - new CreateTag($request->getAttribute('actor'), array_get($request->getParsedBody(), 'data', [])) + new CreateTag($request->getAttribute('actor'), Arr::get($request->getParsedBody(), 'data', [])) ); } } diff --git a/extensions/tags/src/Api/Controller/DeleteTagController.php b/extensions/tags/src/Api/Controller/DeleteTagController.php index 2e88440ce..971ce4feb 100644 --- a/extensions/tags/src/Api/Controller/DeleteTagController.php +++ b/extensions/tags/src/Api/Controller/DeleteTagController.php @@ -12,6 +12,7 @@ namespace Flarum\Tags\Api\Controller; use Flarum\Api\Controller\AbstractDeleteController; use Flarum\Tags\Command\DeleteTag; use Illuminate\Contracts\Bus\Dispatcher; +use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; class DeleteTagController extends AbstractDeleteController @@ -35,7 +36,7 @@ class DeleteTagController extends AbstractDeleteController protected function delete(ServerRequestInterface $request) { $this->bus->dispatch( - new DeleteTag(array_get($request->getQueryParams(), 'id'), $request->getAttribute('actor')) + new DeleteTag(Arr::get($request->getQueryParams(), 'id'), $request->getAttribute('actor')) ); } } diff --git a/extensions/tags/src/Api/Controller/OrderTagsController.php b/extensions/tags/src/Api/Controller/OrderTagsController.php index ac4397823..b1441ad37 100644 --- a/extensions/tags/src/Api/Controller/OrderTagsController.php +++ b/extensions/tags/src/Api/Controller/OrderTagsController.php @@ -10,6 +10,7 @@ namespace Flarum\Tags\Api\Controller; use Flarum\Tags\Tag; +use Illuminate\Support\Arr; use Laminas\Diactoros\Response\EmptyResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -24,7 +25,7 @@ class OrderTagsController implements RequestHandlerInterface { $request->getAttribute('actor')->assertAdmin(); - $order = array_get($request->getParsedBody(), 'order'); + $order = Arr::get($request->getParsedBody(), 'order'); if ($order === null) { return new EmptyResponse(422); @@ -36,7 +37,7 @@ class OrderTagsController implements RequestHandlerInterface ]); foreach ($order as $i => $parent) { - $parentId = array_get($parent, 'id'); + $parentId = Arr::get($parent, 'id'); Tag::where('id', $parentId)->update(['position' => $i]); diff --git a/extensions/tags/src/Api/Controller/UpdateTagController.php b/extensions/tags/src/Api/Controller/UpdateTagController.php index c79efb73f..845ff4de0 100644 --- a/extensions/tags/src/Api/Controller/UpdateTagController.php +++ b/extensions/tags/src/Api/Controller/UpdateTagController.php @@ -13,6 +13,7 @@ use Flarum\Api\Controller\AbstractShowController; use Flarum\Tags\Api\Serializer\TagSerializer; use Flarum\Tags\Command\EditTag; use Illuminate\Contracts\Bus\Dispatcher; +use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -41,9 +42,9 @@ class UpdateTagController extends AbstractShowController */ protected function data(ServerRequestInterface $request, Document $document) { - $id = array_get($request->getQueryParams(), 'id'); + $id = Arr::get($request->getQueryParams(), 'id'); $actor = $request->getAttribute('actor'); - $data = array_get($request->getParsedBody(), 'data', []); + $data = Arr::get($request->getParsedBody(), 'data', []); return $this->bus->dispatch( new EditTag($id, $actor, $data) diff --git a/extensions/tags/src/Command/CreateTagHandler.php b/extensions/tags/src/Command/CreateTagHandler.php index cc3cc5757..08680531e 100644 --- a/extensions/tags/src/Command/CreateTagHandler.php +++ b/extensions/tags/src/Command/CreateTagHandler.php @@ -12,6 +12,7 @@ namespace Flarum\Tags\Command; use Flarum\Tags\Event\Creating; use Flarum\Tags\Tag; use Flarum\Tags\TagValidator; +use Illuminate\Support\Arr; class CreateTagHandler { @@ -40,15 +41,15 @@ class CreateTagHandler $actor->assertCan('createTag'); $tag = Tag::build( - array_get($data, 'attributes.name'), - array_get($data, 'attributes.slug'), - array_get($data, 'attributes.description'), - array_get($data, 'attributes.color'), - array_get($data, 'attributes.icon'), - array_get($data, 'attributes.isHidden') + Arr::get($data, 'attributes.name'), + Arr::get($data, 'attributes.slug'), + Arr::get($data, 'attributes.description'), + Arr::get($data, 'attributes.color'), + Arr::get($data, 'attributes.icon'), + Arr::get($data, 'attributes.isHidden') ); - $parentId = array_get($data, 'relationships.parent.data.id'); + $parentId = Arr::get($data, 'relationships.parent.data.id'); if ($parentId !== null) { $rootTags = Tag::whereNull('parent_id')->whereNotNull('position'); diff --git a/extensions/tags/src/Command/EditTagHandler.php b/extensions/tags/src/Command/EditTagHandler.php index 6ee2d09f3..452f6e4d4 100644 --- a/extensions/tags/src/Command/EditTagHandler.php +++ b/extensions/tags/src/Command/EditTagHandler.php @@ -12,6 +12,7 @@ namespace Flarum\Tags\Command; use Flarum\Tags\Event\TagWillBeSaved; use Flarum\Tags\TagRepository; use Flarum\Tags\TagValidator; +use Illuminate\Support\Arr; class EditTagHandler { @@ -49,7 +50,7 @@ class EditTagHandler $actor->assertCan('edit', $tag); - $attributes = array_get($data, 'attributes', []); + $attributes = Arr::get($data, 'attributes', []); if (isset($attributes['name'])) { $tag->name = $attributes['name']; diff --git a/extensions/tags/src/Listener/CreatePostWhenTagsAreChanged.php b/extensions/tags/src/Listener/CreatePostWhenTagsAreChanged.php index 1cab56677..151d2bd3f 100755 --- a/extensions/tags/src/Listener/CreatePostWhenTagsAreChanged.php +++ b/extensions/tags/src/Listener/CreatePostWhenTagsAreChanged.php @@ -13,6 +13,7 @@ use Flarum\Event\ConfigurePostTypes; use Flarum\Tags\Event\DiscussionWasTagged; use Flarum\Tags\Post\DiscussionTaggedPost; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Support\Arr; class CreatePostWhenTagsAreChanged { @@ -41,7 +42,7 @@ class CreatePostWhenTagsAreChanged $post = DiscussionTaggedPost::reply( $event->discussion->id, $event->actor->id, - array_pluck($event->oldTags, 'id'), + Arr::pluck($event->oldTags, 'id'), $event->discussion->tags()->pluck('id')->all() ); diff --git a/extensions/tags/src/Listener/FilterPostsQueryByTag.php b/extensions/tags/src/Listener/FilterPostsQueryByTag.php index cd443f872..c95fb69ab 100644 --- a/extensions/tags/src/Listener/FilterPostsQueryByTag.php +++ b/extensions/tags/src/Listener/FilterPostsQueryByTag.php @@ -11,6 +11,7 @@ namespace Flarum\Tags\Listener; use Flarum\Event\ConfigurePostsQuery; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Support\Arr; class FilterPostsQueryByTag { @@ -27,7 +28,7 @@ class FilterPostsQueryByTag */ public function filterQuery(ConfigurePostsQuery $event) { - if ($tagId = array_get($event->filter, 'tag')) { + if ($tagId = Arr::get($event->filter, 'tag')) { $event->query ->join('discussion_tag', 'discussion_tag.discussion_id', '=', 'posts.discussion_id') ->where('discussion_tag.tag_id', $tagId); diff --git a/extensions/tags/src/Listener/UpdateTagMetadata.php b/extensions/tags/src/Listener/UpdateTagMetadata.php index 4ced8bc1a..23066d2cb 100755 --- a/extensions/tags/src/Listener/UpdateTagMetadata.php +++ b/extensions/tags/src/Listener/UpdateTagMetadata.php @@ -21,6 +21,7 @@ use Flarum\Post\Event\Restored as PostRestored; use Flarum\Tags\Event\DiscussionWasTagged; use Flarum\Tags\Tag; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Support\Arr; class UpdateTagMetadata { @@ -54,7 +55,7 @@ class UpdateTagMetadata */ public function whenDiscussionWasTagged(DiscussionWasTagged $event) { - $oldTags = Tag::whereIn('id', array_pluck($event->oldTags, 'id'))->get(); + $oldTags = Tag::whereIn('id', Arr::pluck($event->oldTags, 'id'))->get(); $this->updateTags($event->discussion, -1, $oldTags); $this->updateTags($event->discussion, 1);