Skip to content

Commit

Permalink
Don't use constructor injection in console commands, and inject into …
Browse files Browse the repository at this point in the history
…handle() instead. (#1327)
  • Loading branch information
mad-briller authored Mar 17, 2023
1 parent ec8a10a commit 88ca4cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 46 deletions.
27 changes: 4 additions & 23 deletions src/Console/PauseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,16 @@ class PauseCommand extends Command
*/
protected $description = 'Pause all Telescope watchers';

/**
* The cache repository implementation.
*
* @var \Illuminate\Contracts\Cache\Repository
*/
protected $cache;

/**
* Create a new command instance.
*
* @param \Illuminate\Contracts\Cache\Repository $cache
* @return void
*/
public function __construct(CacheRepository $cache)
{
parent::__construct();

$this->cache = $cache;
}

/**
* Execute the console command.
*
* @param \Illuminate\Contracts\Cache\Repository $cache
* @return void
*/
public function handle()
public function handle(CacheRepository $cache)
{
if (! $this->cache->get('telescope:pause-recording')) {
$this->cache->put('telescope:pause-recording', true, now()->addDays(30));
if (! $cache->get('telescope:pause-recording')) {
$cache->put('telescope:pause-recording', true, now()->addDays(30));
}

$this->info('Telescope watchers paused successfully.');
Expand Down
27 changes: 4 additions & 23 deletions src/Console/ResumeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,16 @@ class ResumeCommand extends Command
*/
protected $description = 'Unpause all Telescope watchers';

/**
* The cache repository implementation.
*
* @var \Illuminate\Contracts\Cache\Repository
*/
protected $cache;

/**
* Create a new command instance.
*
* @param \Illuminate\Contracts\Cache\Repository $cache
* @return void
*/
public function __construct(CacheRepository $cache)
{
parent::__construct();

$this->cache = $cache;
}

/**
* Execute the console command.
*
* @param \Illuminate\Contracts\Cache\Repository $cache
* @return void
*/
public function handle()
public function handle(CacheRepository $cache)
{
if ($this->cache->get('telescope:pause-recording')) {
$this->cache->forget('telescope:pause-recording');
if ($cache->get('telescope:pause-recording')) {
$cache->forget('telescope:pause-recording');
}

$this->info('Telescope watchers resumed successfully.');
Expand Down

0 comments on commit 88ca4cb

Please sign in to comment.