• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aphiria / app / 16244033904

25 May 2025 04:20PM UTC coverage: 82.353% (+0.7%) from 81.667%
16244033904

push

github

web-flow
Fixed Psalm errors (#51)

* Fixed Psalm errors

* Removed unnecessary import

0 of 3 new or added lines in 1 file covered. (0.0%)

294 of 357 relevant lines covered (82.35%)

9.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Users/Console/DefaultCredentialGeneratorCommandHandler.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Users\Console;
6

7
use Aphiria\Console\Commands\Attributes\Command;
8
use Aphiria\Console\Commands\Attributes\Option;
9
use Aphiria\Console\Commands\ICommandHandler;
10
use Aphiria\Console\Input\Input;
11
use Aphiria\Console\Input\OptionType;
12
use Aphiria\Console\Output\IOutput;
13
use Aphiria\Console\Output\Prompts\Confirmation;
14
use Aphiria\Console\Output\Prompts\Prompt;
15
use RuntimeException;
16

17
/**
18
 * Defines the default credential generator command handler
19
 */
20
#[Command('user:generate-default-credentials', description: 'Generates the default user credentials and updates the .env file with them')]
21
#[Option('show-password', OptionType::NoValue, 's', 'Show the generated password', false)]
22
final class DefaultCredentialGeneratorCommandHandler implements ICommandHandler
23
{
24
    /** @const The length of the default user password */
25
    private const int DEFAULT_USER_PASSWORD_LENGTH = 32;
26

27
    /**
28
     * @inheritdoc
29
     */
30
    public function handle(Input $input, IOutput $output): void
31
    {
32
        $prompt = new Prompt();
×
33

34
        if (!$prompt->ask(new Confirmation('Would you like to update the default user credentials in your .env file? [Y/N] '), $output)) {
×
35
            $output->writeln('<comment>For security, remember to update these credentials before deploying to production</comment>');
×
36

37
            return;
×
38
        }
39

40
        $output->writeln('<info>Generating default user credentials...</info>');
×
41
        $defaultUserEmail = '';
×
42

43
        while (\strlen(\trim($defaultUserEmail)) === 0) {
×
44
            $output->write('Enter the email address of the default admin user: ');
×
45
            $defaultUserEmail = $output->readLine();
×
46
        }
47

48
        $defaultUserPassword = \bin2hex(\random_bytes(self::DEFAULT_USER_PASSWORD_LENGTH));
×
49
        $dotEnvFilePath = __DIR__ . '/../../../../.env';
×
50

51
        if (!\file_exists($dotEnvFilePath)) {
×
52
            throw new RuntimeException("No .env file found at $dotEnvFilePath");
×
53
        }
54

55
        $dotEnvContents = \file_get_contents($dotEnvFilePath);
×
56

NEW
57
        if (!\is_string($dotEnvContents)) {
×
NEW
58
            throw new RuntimeException("Failed to read .env file at $dotEnvFilePath");
×
59
        }
60

NEW
61
        $dotEnvContents = \preg_replace('/^USER_DEFAULT_EMAIL=.*$/m', "USER_DEFAULT_EMAIL=$defaultUserEmail", $dotEnvContents) ?? throw new RuntimeException('Failed to update .env file');
×
62
        $dotEnvContents = \preg_replace('/^USER_DEFAULT_PASSWORD=.*$/m', "USER_DEFAULT_PASSWORD=$defaultUserPassword", $dotEnvContents) ?? throw new RuntimeException('Failed to update .env file');
63
        \file_put_contents($dotEnvFilePath, $dotEnvContents);
64

65
        $output->writeln('<success>.env file updated</success>');
66

67
        if (\array_key_exists('show-password', $input->options)) {
68
            $output->writeln("<info>Password:</info> $defaultUserPassword");
69
        }
70
    }
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc