Passed
Pull Request — master (#51)
by
unknown
05:50
created

SubmissionsController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actionShowSubmission() 0 20 1
A sanitizeUrl() 0 5 1
1
<?php
2
3
namespace rias\contactformextensions\controllers;
4
5
use Craft;
6
use craft\web\Controller;
7
use rias\contactformextensions\ContactFormExtensions;
8
use rias\contactformextensions\elements\ContactFormSubmission;
9
use rias\contactformextensions\elements\db\ContactFormSubmissionQuery;
10
use rias\contactformextensions\models\Settings;
11
12
class SubmissionsController extends Controller
13
{
14
    /**
15
     * @param string|null $submissionId
16
     * @param string|null $siteHandle
17
     * @property  Settings $settings
18
     *
19
     * @return \yii\web\Response
20
     */
21
    public function actionShowSubmission(string $submissionId = null, string $siteHandle = null)
22
    {
23
        $query = new ContactFormSubmissionQuery(ContactFormSubmission::class);
24
        $query->id = $submissionId;
25
26
        /* @var ContactFormSubmission $submission */
27
        $submission = $query->one();
28
29
        $volume = Craft::$app->getVolumes()->getVolumeByHandle(ContactFormExtensions::$plugin->settings->attachmentVolumeHandle);
30
        $messageObject = ContactFormExtensions::$plugin->contactFormExtensionsService->utf8AllTheThings((array) json_decode($submission->message));
31
        $attachments = explode(", ", $submission->attachments);
32
        $variables = [
33
            'submission'    => $submission,
34
            'siteHandle'    => $siteHandle,
35
            'messageObject' => $messageObject,
36
            'attachments'   => $attachments,
37
            'volumeRoot'    => $this->sanitizeUrl($volume->getRootPath())
0 ignored issues
show
Bug introduced by
The method getRootPath() does not exist on craft\base\VolumeInterface. Did you maybe mean getRootUrl()? ( Ignorable by Annotation )

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

37
            'volumeRoot'    => $this->sanitizeUrl($volume->/** @scrutinizer ignore-call */ getRootPath())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
        ];
39
40
        return $this->renderTemplate('contact-form-extensions/submissions/_show', $variables);
41
    }
42
43
44
    public function sanitizeUrl($url){
45
        $url = str_replace(Craft::getAlias('@webroot'), '',$url);
46
        $url = str_replace(Craft::getAlias('@root'), '',$url);
47
        $url = str_replace(Craft::getAlias('@web'), '',$url);
48
        return $url;
49
    }
50
}
51