Issues (30)

src/Traits/CreateKeypairTrait.php (2 issues)

1
<?php
2
3
namespace Vrajroham\LaravelBitpay\Traits;
4
5
use Vrajroham\LaravelBitpay\Exceptions\InvalidConfigurationException;
6
7
trait CreateKeypairTrait
8
{
9
    public function validateAndLoadConfig()
10
    {
11
        $config = config('laravel-bitpay');
0 ignored issues
show
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

11
        $config = /** @scrutinizer ignore-call */ config('laravel-bitpay');
Loading history...
12
13
        if ('livenet' != $config['network'] && 'testnet' != $config['network']) {
14
            throw InvalidConfigurationException::invalidNetworkName();
15
        }
16
17
        if (!class_exists($config['key_storage'])) {
18
            throw InvalidConfigurationException::invalidStorageClass();
19
        }
20
21
        if ('' === trim($config['key_storage_password'])) {
22
            throw InvalidConfigurationException::invalidOrEmptyPassword();
23
        }
24
25
        $this->config = $config;
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
    }
27
28
    protected function writeNewEnvironmentFileWith()
29
    {
30
        file_put_contents($this->laravel->environmentFilePath(), preg_replace(
31
            $this->keyReplacementPattern(),
32
            'BITPAY_TOKEN='.$this->token,
33
            file_get_contents($this->laravel->environmentFilePath())
34
        ));
35
    }
36
37
    protected function keyReplacementPattern()
38
    {
39
        $escaped = preg_quote('='.$this->laravel['config']['laravel-bitpay.token'], '/');
40
41
        return "/^BITPAY_TOKEN{$escaped}/m";
42
    }
43
}
44