Completed
Pull Request — master (#60)
by Etienne
01:16
created

HoneypotSetup::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Spatie\Honeypot;
4
5
use Illuminate\Support\Str;
6
use Spatie\Honeypot\EncryptedTime;
7
8
class HoneypotSetup
9
{
10
    /**
11
     * Get an array with values needed for composing the view
12
     * It allows to use it outside a blade component so it
13
     * can be passed to a front-end framework like vue
14
     *
15
     * @return array
16
     */
17
    public static function get()
18
    {
19
20
        $honeypotConfig = config('honeypot');
21
22
        $nameFieldName = $honeypotConfig['name_field_name'];
23
24
        $randomNameFieldName = $honeypotConfig['randomize_name_field_name'];
25
        $enabled = $honeypotConfig['enabled'];
26
        $validFromFieldName = $honeypotConfig['valid_from_field_name'];
27
28
        $validFrom = now()->addSeconds($honeypotConfig['amount_of_seconds']);
29
30
        $encryptedValidFrom = EncryptedTime::create($validFrom);
31
32
        if ($randomNameFieldName) {
33
            $nameFieldName = sprintf('%s_%s', $nameFieldName, Str::random());
34
        }
35
36
        return [
37
            'enabled' => $enabled,
38
            'nameFieldName' => $nameFieldName,
39
            'validFromFieldName' => $validFromFieldName,
40
            'encryptedValidFrom' => strval($encryptedValidFrom)
41
        ];
42
    }
43
}
44