Passed
Branch master (acb862)
by Simon
03:16
created

HaveIBeenPwnedPageController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkEmail() 0 17 2
1
<?php
2
3
namespace Firesphere\HaveIBeenPwned\Controllers;
4
5
use Firesphere\HaveIBeenPwned\Models\HaveIBeenPwnedPage;
6
use Firesphere\HaveIBeenPwned\Services\HaveIBeenPwnedService;
7
use PageController;
8
use SilverStripe\Control\HTTPRequest;
9
use SilverStripe\Core\Injector\Injector;
10
use SilverStripe\Security\Member;
11
use SilverStripe\Security\Security;
12
13
/**
14
 * Class \Firesphere\HaveIBeenPwned\Controllers\HaveIBeenPwnedPageController
15
 *
16
 */
17
class HaveIBeenPwnedPageController extends PageController
18
{
19
    /**
20
     * @var array
21
     */
22
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
23
        'checkEmail',
24
    ];
25
26
    /**
27
     * @var array
28
     */
29
    private static $url_handlers = [
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
30
        'check-email' => 'checkEmail',
31
    ];
32
33
    /**
34
     * @param HTTPRequest|null $request
35
     * @param array $params
36
     * @return $this
37
     * @throws \GuzzleHttp\Exception\GuzzleException
38
     */
39
    public function checkEmail($request = null, $params = [])
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

39
    public function checkEmail(/** @scrutinizer ignore-unused */ $request = null, $params = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
    {
41
        /** @var Member|null $user */
42
        $user = Security::getCurrentUser();
43
44
        if ($user) {
0 ignored issues
show
introduced by
$user is of type SilverStripe\Security\Member, thus it always evaluated to true.
Loading history...
45
            /** @var HaveIBeenPwnedService $service */
46
            $service = Injector::inst()->createWithArgs(HaveIBeenPwnedService::class, [$params]);
47
48
            $breachedEmails = $service->checkPwndEmail($user);
49
50
            $contentText = str_replace("\r\n", '<br />', $breachedEmails);
51
52
            $this->dataRecord->Content .= '<p>' . $contentText . '</p>';
53
        }
54
55
        return $this;
56
    }
57
}
58