1 | <?php |
||
9 | class SyncSitesCommand extends Command |
||
10 | { |
||
11 | /** @var \OhDear\ForgeSync\ForgeSync */ |
||
12 | protected $sync; |
||
13 | |||
14 | /** @var \Illuminate\Support\Collection */ |
||
15 | protected $availableTeams; |
||
16 | |||
17 | /** @var \Illuminate\Support\Collection */ |
||
18 | protected $syncableSites; |
||
19 | |||
20 | protected $signature = 'ohdear:forge-sync {--ohDearKey=} {--forgeKey=} {--dry-run}'; |
||
21 | |||
22 | protected $description = 'Sync existing Laravel Forge Sites to Oh Dear!'; |
||
23 | |||
24 | public function handle() |
||
25 | { |
||
26 | $ohDearTeamId = $this->askOhDearTeamId(); |
||
27 | |||
28 | $this->info('Scan your Forge sites... (this could need a little bit of time).'); |
||
29 | |||
30 | $this->sync = new ForgeSync($ohDearTeamId, $this->option('ohDearKey'), $this->option('forgeKey')); |
||
31 | |||
32 | $this->syncableSites = $this->sync->sites(); |
||
33 | |||
34 | if ($this->syncableSites->count() === 0) { |
||
35 | $this->warn("You don't have any sites that can be synced!"); |
||
36 | |||
37 | return; |
||
38 | } |
||
39 | |||
40 | if ($this->option('dry-run') == true) { |
||
41 | $this->warn("Dry-Run Mode: We don't create any Site at Oh Dear."); |
||
42 | } |
||
43 | |||
44 | $choice = $this->choice('Which Forge sites should be synced with Oh Dear?', $this->siteChoices()); |
||
45 | |||
46 | $this->syncSites($choice); |
||
47 | |||
48 | $this->info('All done'); |
||
49 | } |
||
50 | |||
51 | protected function askOhDearTeamId(): int |
||
52 | { |
||
53 | $choice = $this->choice( |
||
54 | 'Please select the Oh Dear! team that should be synced with your forge account.', |
||
55 | $this->teamChoices() |
||
56 | ); |
||
57 | |||
58 | return $this->availableTeams->filter(function ($team) use ($choice) { |
||
59 | return "<comment>{$team['name']}</comment>" == $choice; |
||
60 | })->first()['id']; |
||
61 | } |
||
62 | |||
63 | protected function syncSites(string $siteChoice) |
||
91 | |||
92 | protected function teamChoices(): array |
||
93 | { |
||
101 | |||
102 | protected function siteChoices(): array |
||
108 | } |
||
109 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.