ContactFormSubmissionQuery   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A message() 0 5 1
A fromEmail() 0 5 1
A form() 0 5 1
A subject() 0 5 1
A fromName() 0 5 1
A beforePrepare() 0 35 6
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 $message;
15
16
    public function form($value)
17
    {
18
        $this->form = $value;
19
20
        return $this;
21
    }
22
23
    public function subject($value)
24
    {
25
        $this->subject = $value;
26
27
        return $this;
28
    }
29
30
    public function fromName($value)
31
    {
32
        $this->fromName = $value;
33
34
        return $this;
35
    }
36
37
    public function fromEmail($value)
38
    {
39
        $this->fromEmail = $value;
40
41
        return $this;
42
    }
43
44
    public function message($value)
45
    {
46
        $this->message = $value;
47
48
        return $this;
49
    }
50
51
    protected function beforePrepare(): bool
52
    {
53
        // join in the products table
54
        $this->joinElementTable('contactform_submissions');
55
56
        // select the columns
57
        $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

57
        $this->query->/** @scrutinizer ignore-call */ 
58
                      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...
58
            'contactform_submissions.form',
59
            'contactform_submissions.subject',
60
            'contactform_submissions.fromName',
61
            'contactform_submissions.fromEmail',
62
            'contactform_submissions.message',
63
        ]);
64
65
        if ($this->form) {
66
            $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

66
            $this->subQuery->/** @scrutinizer ignore-call */ 
67
                             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...
67
        }
68
69
        if ($this->subject) {
70
            $this->subQuery->andWhere(Db::parseParam('contactform_submissions.subject', $this->subject));
71
        }
72
73
        if ($this->fromName) {
74
            $this->subQuery->andWhere(Db::parseParam('contactform_submissions.fromName', $this->fromName));
75
        }
76
77
        if ($this->fromEmail) {
78
            $this->subQuery->andWhere(Db::parseParam('contactform_submissions.fromEmail', $this->fromEmail));
79
        }
80
81
        if ($this->message) {
82
            $this->subQuery->andWhere(Db::parseParam('contactform_submissions.message', $this->message));
83
        }
84
85
        return parent::beforePrepare();
86
    }
87
}
88