PageViewEvent::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 13
rs 10
1
<?php
2
/**
3
 * User: Damian Zamojski (br33f)
4
 * Date: 25.06.2021
5
 * Time: 13:33
6
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
7
8
namespace nystudio107\instantanalyticsGa4\ga4\events;
9
10
use Br33f\Ga4\MeasurementProtocol\Dto\Event\BaseEvent;
11
use Br33f\Ga4\MeasurementProtocol\Dto\Parameter\AbstractParameter;
12
use Br33f\Ga4\MeasurementProtocol\Enum\ErrorCode;
13
use Br33f\Ga4\MeasurementProtocol\Exception\ValidationException;
14
15
/**
16
 * Class PageViewEvent
17
 *
18
 * @method string getPageTitle()
19
 * @method string getPageLocation()
20
 * @method PageViewEvent setPageTitle(string $title)
21
 * @method PageViewEvent setPageLocation(string $url)
22
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
23
class PageViewEvent extends BaseEvent
24
{
25
    private $eventName = 'page_view';
0 ignored issues
show
Coding Style introduced by
Private member variable "eventName" must be prefixed with an underscore
Loading history...
26
27
    /**
28
     * PageViewEvent constructor.
29
     * @param AbstractParameter[] $paramList
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
30
     */
31
    public function __construct(array $paramList = [])
32
    {
33
        parent::__construct($this->eventName, $paramList);
34
    }
35
36
    public function validate()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function validate()
Loading history...
37
    {
38
        parent::validate();
39
40
        if (empty($this->getPageTitle())) {
41
            throw new ValidationException('Field "page_title" is required.', ErrorCode::VALIDATION_FIELD_REQUIRED, 'page_title');
42
        }
43
44
        if (empty($this->getPageLocation())) {
45
            throw new ValidationException('Field "page_location" is required if "value" is set', ErrorCode::VALIDATION_FIELD_REQUIRED, 'page_location');
46
        }
47
48
        return true;
49
    }
50
}
51