Passed
Pull Request — master (#51)
by
unknown
03:16
created

ContactFormSubmissionQuery::attachments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace rias\contactformextensions\elements\db;
4
5
use craft\elements\db\ElementQuery;
6
use craft\helpers\Db;
7
8
class ContactFormSubmissionQuery extends ElementQuery
9
{
10
    public $form;
11
    public $subject;
12
    public $fromName;
13
    public $fromEmail;
14
    public $attachments;
15
    public $message;
16
17
    public function form($value)
18
    {
19
        $this->form = $value;
20
21
        return $this;
22
    }
23
24
    public function subject($value)
25
    {
26
        $this->subject = $value;
27
28
        return $this;
29
    }
30
31
    public function fromName($value)
32
    {
33
        $this->fromName = $value;
34
35
        return $this;
36
    }
37
38
    public function fromEmail($value)
39
    {
40
        $this->fromEmail = $value;
41
42
        return $this;
43
    }
44
45
46
    public function attachments($value)
47
    {
48
        $this->attachments = $value;
49
50
        return $this;
51
    }
52
53
    public function message($value)
54
    {
55
        $this->message = $value;
56
57
        return $this;
58
    }
59
60
    protected function beforePrepare(): bool
61
    {
62
        // join in the products table
63
        $this->joinElementTable('contactform_submissions');
64
65
        // select the columns
66
        $this->query->select([
0 ignored issues
show
Bug introduced by
The method select() does not exist on null. ( Ignorable by Annotation )

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

66
        $this->query->/** @scrutinizer ignore-call */ 
67
                      select([

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...
67
            'contactform_submissions.form',
68
            'contactform_submissions.subject',
69
            'contactform_submissions.fromName',
70
            'contactform_submissions.fromEmail',
71
            'contactform_submissions.attachments',
72
            'contactform_submissions.message',
73
        ]);
74
75
        if ($this->form) {
76
            $this->subQuery->andWhere(Db::parseParam('contactform_submissions.form', $this->form));
0 ignored issues
show
Bug introduced by
The method andWhere() does not exist on null. ( Ignorable by Annotation )

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

76
            $this->subQuery->/** @scrutinizer ignore-call */ 
77
                             andWhere(Db::parseParam('contactform_submissions.form', $this->form));

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...
77
        }
78
79
        if ($this->subject) {
80
            $this->subQuery->andWhere(Db::parseParam('contactform_submissions.subject', $this->subject));
81
        }
82
83
        if ($this->fromName) {
84
            $this->subQuery->andWhere(Db::parseParam('contactform_submissions.fromName', $this->fromName));
85
        }
86
87
        if ($this->fromEmail) {
88
            $this->subQuery->andWhere(Db::parseParam('contactform_submissions.fromEmail', $this->fromEmail));
89
        }
90
91
        if ($this->attachments) {
92
            $this->subQuery->andWhere(Db::parseParam('contactform_submissions.attachments', $this->attachments));
93
        }
94
95
        if ($this->message) {
96
            $this->subQuery->andWhere(Db::parseParam('contactform_submissions.message', $this->message));
97
        }
98
99
        return parent::beforePrepare();
100
    }
101
}
102