Skip to content

Commit fe90ca7

Browse files
committed
LCO: Logic moved to preventer.
1 parent e054ddb commit fe90ca7

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/Overlapping/Preventer.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@
22

33
namespace Illuminated\Console\Overlapping;
44

5+
use Illuminate\Console\Command;
6+
57
class Preventer
68
{
9+
private $command;
710
private $strategy;
811

9-
public function __construct($strategy)
12+
public function __construct(Command $command)
13+
{
14+
$this->command = $command;
15+
$this->strategy = $this->strategy();
16+
}
17+
18+
private function strategy()
1019
{
11-
switch ($strategy) {
20+
if (!empty($this->strategy)) {
21+
return $this->strategy;
22+
}
23+
24+
switch ($this->command->getOverlappingStrategy()) {
1225
case 'database':
13-
$this->strategy = new DatabaseStrategy();
14-
break;
26+
return new DatabaseStrategy();
1527

1628
case 'file':
1729
default:
18-
$this->strategy = new FileStrategy();
19-
break;
30+
return new FileStrategy();
2031
}
2132
}
2233
}

src/WithoutOverlapping.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ trait WithoutOverlapping
1010
{
1111
protected function execute(InputInterface $input, OutputInterface $output)
1212
{
13-
$strategy = $this->getOverlappingStrategy();
14-
$preventer = new Preventer($strategy);
13+
$preventer = new Preventer($this);
1514

1615
return parent::execute($input, $output);
1716
}

0 commit comments

Comments
 (0)