Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
olivernybroe committed Oct 28, 2022
1 parent 09f3e63 commit 93832e0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
34 changes: 25 additions & 9 deletions src/Illuminate/Console/CacheCommandMutex.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

namespace Illuminate\Console;

use Carbon\CarbonInterval;
Expand Down Expand Up @@ -33,6 +31,12 @@ public function __construct(Cache $cache)
$this->cache = $cache;
}

/**
* Attempt to obtain a command mutex for the given command.
*
* @param \Illuminate\Console\Command $command
* @return bool
*/
public function create($command)
{
return $this->cache->store($this->store)->add(
Expand All @@ -42,25 +46,37 @@ public function create($command)
);
}

public function exists($command)
/**
* Release the mutex for the given command.
*
* @param \Illuminate\Console\Command $command
* @return bool
*/
public function release($command)
{
return $this->cache->store($this->store)->has(
return $this->cache->store($this->store)->forget(
$this->commandMutexName($command)
);
}

public function release($command)
/**
* Determine if a command mutex exists for the given command.
*
* @param \Illuminate\Console\Command $command
* @return bool
*/
public function exists($command)
{
return $this->cache->store($this->store)->forget(
return $this->cache->store($this->store)->has(
$this->commandMutexName($command)
);
}

/**
* @param Command $command
* @param \Illuminate\Console\Command $command
* @return string
*/
protected function commandMutexName($command): string
protected function commandMutexName($command)
{
return 'framework'.DIRECTORY_SEPARATOR.'command-'.$command->getName();
}
Expand All @@ -71,7 +87,7 @@ protected function commandMutexName($command): string
* @param string|null $store
* @return $this
*/
public function useStore($store): static
public function useStore($store)
{
$this->store = $store;

Expand Down
8 changes: 3 additions & 5 deletions src/Illuminate/Console/CommandMutex.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
<?php

declare(strict_types=1);

namespace Illuminate\Console;

interface CommandMutex
{
/**
* Attempt to obtain a command mutex for the given command.
*
* @param Command $command
* @param \Illuminate\Console\Command $command
* @return bool
*/
public function create($command);

/**
* Release the mutex for the given command.
*
* @param Command $command
* @param \Illuminate\Console\Command $command
* @return bool
*/
public function release($command);

/**
* Determine if a command mutex exists for the given command.
*
* @param Command $command
* @param \Illuminate\Console\Command $command
* @return bool
*/
public function exists($command);
Expand Down
2 changes: 0 additions & 2 deletions src/Illuminate/Contracts/Console/Isolated.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

namespace Illuminate\Contracts\Console;

interface Isolated
Expand Down
10 changes: 5 additions & 5 deletions tests/Console/CacheCommandMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
class CacheCommandMutexTest extends TestCase
{
/**
* @var CacheCommandMutex
* @var \Illuminate\Console\CacheCommandMutex
*/
protected $mutex;

/**
* @var Command
* @var \Illuminate\Console\Command
*/
protected $command;

/**
* @var Factory
* @var \Illuminate\Contracts\Cache\Factory
*/
protected $cacheFactory;

/**
* @var Repository
* @var \Illuminate\Contracts\Cache\Repository
*/
protected Repository $cacheRepository;
protected $cacheRepository;

protected function setUp(): void
{
Expand Down
1 change: 0 additions & 1 deletion tests/Console/CommandMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function testCanRunCommandAgainAfterOtherCommandFinished()
$this->assertEquals(2, $this->command->ran);
}


protected function runCommand()
{
$input = new ArrayInput([]);
Expand Down

0 comments on commit 93832e0

Please sign in to comment.