Issues (12)

src/controllers/HaveIBeenPwnedPageController.php (3 issues)

1
<?php
2
3
namespace Firesphere\HaveIBeenPwned\Controllers;
4
5
use Firesphere\HaveIBeenPwned\Services\HaveIBeenPwnedService;
6
use PageController;
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\Core\Injector\Injector;
9
use SilverStripe\Security\Member;
10
use SilverStripe\Security\Security;
11
12
// This controller should not be initiated if the base Page doesn't exist
13
if (!class_exists('\Page')) {
14
    return;
15
}
16
17
/**
18
 * Class \Firesphere\HaveIBeenPwned\Controllers\HaveIBeenPwnedPageController
19
 *
20
 */
21
class HaveIBeenPwnedPageController extends PageController
22
{
23
    /**
24
     * @var array
25
     */
26
    private static $allowed_actions = [
0 ignored issues
show
The private property $allowed_actions is not used, and could be removed.
Loading history...
27
        'checkEmail',
28
    ];
29
30
    /**
31
     * @var array
32
     */
33
    private static $url_handlers = [
0 ignored issues
show
The private property $url_handlers is not used, and could be removed.
Loading history...
34
        'check-email' => 'checkEmail',
35
    ];
36
37
    /**
38
     * @param null|HTTPRequest $request
39
     * @param array $params
40
     * @return $this
41
     * @throws \GuzzleHttp\Exception\GuzzleException
42
     */
43
    public function checkEmail($request = null, $params = [])
0 ignored issues
show
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

43
    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...
44
    {
45
        /** @var Member|null $user */
46
        $user = Security::getCurrentUser();
47
48
        if ($user !== null) {
49
            /** @var HaveIBeenPwnedService $service */
50
            $service = Injector::inst()->createWithArgs(HaveIBeenPwnedService::class, [$params]);
51
52
            $breachedEmails = $service->checkPwnedEmail($user);
53
54
            $contentText = str_replace("\r\n", '<br />', $breachedEmails);
55
56
57
            $this->data()->Content = trim(
58
                $this->data()->Content . '<p><h3>We found the following breaches for your account:</h3>' .
59
                $contentText .
60
                '</p>'
61
            );
62
        }
63
64
        return $this;
65
    }
66
}
67