HoneypotViewComposer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A compose() 0 25 2
1
<?php
2
3
namespace Spatie\Honeypot;
4
5
use Illuminate\Support\Str;
6
use Illuminate\View\View;
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
        $randomNameFieldName = $honeypotConfig['randomize_name_field_name'];
17
        $enabled = $honeypotConfig['enabled'];
18
        $validFromFieldName = $honeypotConfig['valid_from_field_name'];
19
20
        $validFrom = now()->addSeconds($honeypotConfig['amount_of_seconds']);
21
22
        $encryptedValidFrom = EncryptedTime::create($validFrom);
23
24
        if ($randomNameFieldName) {
25
            $nameFieldName = sprintf('%s_%s', $nameFieldName, Str::random());
26
        }
27
28
        $view->with(compact(
29
            'enabled',
30
            'nameFieldName',
31
            'validFromFieldName',
32
            'encryptedValidFrom'
33
        ));
34
    }
35
}
36