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
![]() |
|||
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
|
|||
23 | class PageViewEvent extends BaseEvent |
||
24 | { |
||
25 | private $eventName = 'page_view'; |
||
0 ignored issues
–
show
|
|||
26 | |||
27 | /** |
||
28 | * PageViewEvent constructor. |
||
29 | * @param AbstractParameter[] $paramList |
||
0 ignored issues
–
show
|
|||
30 | */ |
||
31 | public function __construct(array $paramList = []) |
||
32 | { |
||
33 | parent::__construct($this->eventName, $paramList); |
||
34 | } |
||
35 | |||
36 | public function validate() |
||
0 ignored issues
–
show
|
|||
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 |