GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 47b153...f845d1 )
by Andreas
04:10
created

AbstractWebhook::validateForCsrf()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 1
b 0
f 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Controller;
7
8
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper;
9
use Magento\Framework\App\Action\Action;
10
use Magento\Framework\App\Action\Context;
11
use Magento\Framework\App\Action\HttpPostActionInterface;
12
use Magento\Framework\App\CsrfAwareActionInterface;
13
use Magento\Framework\App\Request\InvalidRequestException;
14
use Magento\Framework\App\RequestInterface;
15
use Magento\Framework\Controller\Result\RawFactory as RawResultFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Controller\Result\RawFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Magento\Framework\Controller\Result\Raw as RawResult;
17
use Magento\Framework\Phrase;
18
19
/**
20
 * Class AbstractWebhook
21
 */
22
abstract class AbstractWebhook extends Action implements HttpPostActionInterface, CsrfAwareActionInterface
23
{
24
    private const PARAM_TOKEN = 'token';
25
26
    /**
27
     * @var ConfigHelper
28
     */
29
    private $configHelper;
30
31
    /**
32
     * @var RawResultFactory
33
     */
34
    private $rawResultFactory;
35
36
    /**
37
     * @param Context $context
38
     * @param ConfigHelper $configHelper
39
     * @param RawResultFactory $rawResultFactory
40
     */
41
    public function __construct(
42
        Context $context,
43
        ConfigHelper $configHelper,
44
        RawResultFactory $rawResultFactory
45
    ) {
46
        parent::__construct($context);
47
        $this->configHelper = $configHelper;
48
        $this->rawResultFactory = $rawResultFactory;
49
    }
50
51
    /**
52
     * @inheritDoc
53
     */
54
    public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException
55
    {
56
        /** @var RawResult $response */
57
        $response = $this->rawResultFactory->create();
58
        $response->setHttpResponseCode(401);
59
        $response->setContents('');
60
61
        return new InvalidRequestException($response, [new Phrase('Invalid Token.')]);
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67
    public function validateForCsrf(RequestInterface $request): ?bool
68
    {
69
        $token = $request->getParam(self::PARAM_TOKEN);
70
71
        if (!$token || $this->configHelper->getWebhookToken() !== $token) {
72
            return false;
73
        }
74
75
        return true;
76
    }
77
}
78