Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
ClassDeletedEvent
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
6 / 6
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getClass
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSelectedClass
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setParentClass
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2021 (original work) Open Assessment Technologies SA;
19 */
20
21declare(strict_types=1);
22
23namespace oat\generis\model\data\event;
24
25use JsonSerializable;
26use oat\oatbox\event\Event;
27use core_kernel_classes_Class;
28
29class ClassDeletedEvent implements Event, JsonSerializable
30{
31    /** @var core_kernel_classes_Class */
32    private $class;
33
34    /** @var core_kernel_classes_Class|null */
35    private $selectedClass;
36
37    /** @var core_kernel_classes_Class|null */
38    private $parentClass;
39
40    public function __construct(core_kernel_classes_Class $class)
41    {
42        $this->class = $class;
43    }
44
45    public function getName(): string
46    {
47        return self::class;
48    }
49
50    public function getClass(): core_kernel_classes_Class
51    {
52        return $this->class;
53    }
54
55    public function setSelectedClass(?core_kernel_classes_Class $class): self
56    {
57        $this->selectedClass = $class;
58
59        return $this;
60    }
61
62    public function setParentClass(?core_kernel_classes_Class $class): self
63    {
64        $this->parentClass = $class;
65
66        return $this;
67    }
68
69    public function jsonSerialize(): array
70    {
71        $data = [
72            'uri' => $this->class->getUri(),
73        ];
74
75        if ($this->selectedClass !== null && $this->selectedClass !== $this->class) {
76            $data['selectedClass'] = [
77                'uri' => $this->selectedClass->getUri(),
78                'label' => $this->selectedClass->getLabel(),
79            ];
80        }
81
82        if ($this->parentClass !== null) {
83            $data['parentClass'] = [
84                'uri' => $this->parentClass->getUri(),
85                'label' => $this->parentClass->getLabel(),
86            ];
87        }
88
89        return $data;
90    }
91}