Issues (653)

src/ga4/events/PageViewEvent.php (15 issues)

1
<?php
2
/**
3
 * User: Damian Zamojski (br33f)
4
 * Date: 25.06.2021
5
 * Time: 13:33
6
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
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
Missing @category tag in class comment
Loading history...
Missing @package tag in class comment
Loading history...
Missing @author tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
23
class PageViewEvent extends BaseEvent
24
{
25
    private $eventName = 'page_view';
0 ignored issues
show
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
There must be exactly one blank line before the tags in a doc comment
Loading history...
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
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