Completed
Pull Request — master (#7)
by Lars
01:08
created

HoneypotViewComposer::generateRandomString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Honeypot;
4
5
use Illuminate\View\View;
6
use Illuminate\Support\Str;
7
8
class HoneypotViewComposer
9
{
10
    public function compose(View $view)
11
    {
12
        $honeypotConfig = config('honeypot');
13
14
        $nameFieldName = $honeypotConfig['name_field_name'];
15
16
        if ($honeypotConfig['random_name_field_name']) {
17
            $randomString = Str::random();
18
            session(['name_field_name' => $randomString]);
19
            $nameFieldName = $randomString;
20
        }
21
22
        $enabled = $honeypotConfig['enabled'];
23
        $validFromFieldName = $honeypotConfig['valid_from_field_name'];
24
25
        $validFrom = now()->addSeconds($honeypotConfig['amount_of_seconds']);
26
27
        $encryptedValidFrom = EncryptedTime::create($validFrom);
28
29
        $view->with(compact(
30
            'enabled',
31
            'nameFieldName',
32
            'validFromFieldName',
33
            'encryptedValidFrom'
34
        ));
35
    }
36
37
    protected function generateRandomString(): String
38
    {
39
        return Str::random();
40
    }
41
}
42