Completed
Push — master ( c94bc9...f32b07 )
by Yaro
10:06
created

OtpSecret::shouldSkip()   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 1
1
<?php
2
3
namespace Yaro\Jarboe\Etc\CustomFields;
4
5
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
6
use BaconQrCode\Renderer\ImageRenderer;
7
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
8
use BaconQrCode\Writer;
9
use Illuminate\Http\Request;
10
use PragmaRX\Google2FA\Google2FA;
11
use Yaro\Jarboe\Table\Fields\AbstractField;
12
use Yaro\Jarboe\Table\Fields\Traits\Placeholder;
13
use Yaro\Jarboe\Table\Fields\Traits\Tooltip;
14
15
class OtpSecret extends AbstractField
16
{
17
    use Tooltip;
18
    use Placeholder;
19
20
    public function value(Request $request)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
21
    {
22
        return app(Google2FA::class)->generateSecretKey();
23
    }
24
25
    public function shouldSkip(Request $request)
26
    {
27
        return (bool) parent::value($request);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (value() instead of shouldSkip()). Are you sure this is correct? If so, you might want to change this to $this->value().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
28
    }
29
30
    public function getListView($model)
31
    {
32
        return view('jarboe::custom_fields.otp_secret.list');
33
    }
34
35
    public function getEditFormView($model)
36
    {
37
        return view('jarboe::custom_fields.otp_secret.edit', [
38
            'field' => $this,
39
            'model' => $model,
40
        ]);
41
    }
42
43
    public function getCreateFormView()
44
    {
45
        return view('jarboe::custom_fields.otp_secret.create', [
46
            'field' => $this,
47
        ]);
48
    }
49
50
    public function qrSvg($model): string
51
    {
52
        $url = app(Google2FA::class)->getQRCodeUrl(
53
            config('jarboe.admin_panel.two_factor_auth.company_name', config('app.name')),
54
            $model->email,
55
            $model->{$this->name()}
56
        );
57
58
        $writer = new Writer(new ImageRenderer(
59
            new RendererStyle(180),
60
            new SvgImageBackEnd()
61
        ));
62
63
        return $writer->writeString($url);
64
    }
65
}
66