Skip to content

Commit ad9e1c5

Browse files
Confirm before proceeding with the action when using ConfirmableTrait, such as migrate command.
Co-authored-by: 李铭昕 <[email protected]>
1 parent 2331f7b commit ad9e1c5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/ConfirmableTrait.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ trait ConfirmableTrait
1919
* Confirm before proceeding with the action.
2020
*
2121
* This method only asks for confirmation in production.
22-
*
23-
* @param string $warning
24-
* @param null|bool|\Closure $callback
25-
* @return bool
2622
*/
27-
public function confirmToProceed($warning = 'Application In Production!', $callback = false)
23+
public function confirmToProceed(string $warning = 'Application In Production!', null|bool|Closure $callback = null): bool
2824
{
29-
$shouldConfirm = $callback instanceof Closure ? call_user_func($callback) : $callback;
25+
$callback ??= $this->isShouldConfirm();
26+
27+
$shouldConfirm = value($callback);
3028

3129
if ($shouldConfirm) {
3230
if ($this->input->getOption('force')) {
@@ -46,4 +44,10 @@ public function confirmToProceed($warning = 'Application In Production!', $callb
4644

4745
return true;
4846
}
47+
48+
protected function isShouldConfirm(): bool
49+
{
50+
return is_callable(['Composer\InstalledVersions', 'getRootPackage'])
51+
&& \Composer\InstalledVersions::getRootPackage()['dev'] === false;
52+
}
4953
}

0 commit comments

Comments
 (0)