Skip to content

Commit cde1c5d

Browse files
committed
various fixes and formatting
1 parent e872e54 commit cde1c5d

1 file changed

Lines changed: 14 additions & 36 deletions

File tree

src/Illuminate/Foundation/Console/EventListCommand.php

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class EventListCommand extends Command
1313
*
1414
* @var string
1515
*/
16-
protected $signature = 'event:list {--event= : The event name}';
16+
protected $signature = 'event:list {--event= : Filter the events by name}';
1717

1818
/**
1919
* The console command description.
@@ -22,13 +22,6 @@ class EventListCommand extends Command
2222
*/
2323
protected $description = "List the application's events and listeners";
2424

25-
/**
26-
* The table headers for the command.
27-
*
28-
* @var array
29-
*/
30-
protected $headers = ['Event', 'Listeners'];
31-
3225
/**
3326
* Execute the console command.
3427
*
@@ -39,14 +32,10 @@ public function handle()
3932
$events = $this->getEvents();
4033

4134
if (empty($events)) {
42-
if ($this->isSearching()) {
43-
return $this->error('Your application doesn\'t have any events matching the given criteria.');
44-
}
45-
46-
return $this->error('Your application doesn\'t has any events, listeners.');
35+
return $this->error("Your application doesn't have any events matching the given criteria.");
4736
}
4837

49-
$this->displayEvents($events);
38+
$this->table(['Event', 'Listeners'], $events);
5039
}
5140

5241
/**
@@ -64,7 +53,7 @@ protected function getEvents()
6453
$events = array_merge_recursive($events, $providerEvents);
6554
}
6655

67-
if ($this->isSearching()) {
56+
if ($this->filteringByEvent()) {
6857
$events = $this->filterEvents($events);
6958
}
7059

@@ -74,40 +63,29 @@ protected function getEvents()
7463
}
7564

7665
/**
77-
* Determine whether the user is searching event.
78-
*
79-
* @return bool
80-
*/
81-
protected function isSearching()
82-
{
83-
return $this->input->hasParameterOption('--event');
84-
}
85-
86-
/**
87-
* Filter the given events.
66+
* Filter the given events using the provided event name filter.
8867
*
8968
* @param array $events
9069
* @return array
9170
*/
9271
protected function filterEvents(array $events)
9372
{
94-
return collect($events)->filter(function ($listeners, $event) {
95-
if ($this->option('event')) {
96-
return Str::contains($event, $this->option('event'));
97-
}
73+
if (! $eventName = $this->option('event')) {
74+
return $events;
75+
}
9876

99-
return true;
77+
return collect($events)->filter(function ($listeners, $event) use ($eventName) {
78+
return Str::contains($event, $eventName);
10079
})->toArray();
10180
}
10281

10382
/**
104-
* Display the event listeners information on the console.
83+
* Determine whether the user is filtering by an event name.
10584
*
106-
* @param array $events
107-
* @return void
85+
* @return bool
10886
*/
109-
protected function displayEvents(array $events)
87+
protected function filteringByEvent()
11088
{
111-
$this->table($this->headers, $events);
89+
return ! empty($this->option('event'));
11290
}
11391
}

0 commit comments

Comments
 (0)