GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 906caa...b7c8cc )
by Vincent
07:21
created

Installer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0
1
<?php
2
3
namespace Roots\Bedrock;
4
5
use Composer\Script\Event;
6
7
class Installer {
8
  public static $KEYS = array(
9
    'AUTH_KEY',
10
    'SECURE_AUTH_KEY',
11
    'LOGGED_IN_KEY',
12
    'NONCE_KEY',
13
    'AUTH_SALT',
14
    'SECURE_AUTH_SALT',
15
    'LOGGED_IN_SALT',
16
    'NONCE_SALT'
17
  );
18
19
  public static function addSalts(Event $event) {
20
    $root = dirname(dirname(dirname(__DIR__)));
21
    $composer = $event->getComposer();
22
    $io = $event->getIO();
23
24
    if (!$io->isInteractive()) {
25
      $generate_salts = $composer->getConfig()->get('generate-salts');
26
    } else {
27
      $generate_salts = $io->askConfirmation('<info>Generate salts and append to .env file?</info> [<comment>Y,n</comment>]? ', true);
28
    }
29
30
    if (!$generate_salts) {
31
      return 1;
32
    }
33
34
    $salts = array_map(function ($key) {
35
      return sprintf("%s='%s'", $key, Installer::generateSalt());
36
    }, self::$KEYS);
37
38
    $env_file = "{$root}/.env";
39
40
    if (copy("{$root}/.env.example", $env_file)) {
41
      file_put_contents($env_file, implode($salts, "\n"), FILE_APPEND | LOCK_EX);
42
    } else {
43
      $io->write("<error>An error occured while copying your .env file</error>");
44
      return 1;
45
    }
46
  }
47
48
  /**
49
   * Slightly modified/simpler version of wp_generate_password
50
   * https://github.com/WordPress/WordPress/blob/cd8cedc40d768e9e1d5a5f5a08f1bd677c804cb9/wp-includes/pluggable.php#L1575
51
   */
52
  public static function generateSalt($length = 64) {
53
    $chars  = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
54
    $chars .= '!@#$%^&*()';
55
    $chars .= '-_ []{}<>~`+=,.;:/?|';
56
57
    $salt = '';
58
    for ($i = 0; $i < $length; $i++) {
59
      $salt .= substr($chars, rand(0, strlen($chars) - 1), 1);
60
    }
61
62
    return $salt;
63
  }
64
}
65