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

HoneypotSetup::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

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