Test Failed
Pull Request — master (#236)
by
unknown
04:56
created

Widget::castWidget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
/**
4
 * Copyright (c) 2018 Justin Kuenzel (jukusoft.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
20
/**
21
 * Project: RocketCMS
22
 * License: Apache 2.0 license
23
 * User: Justin
24
 * Date: 23.08.2018
25
 * Time: 21:49
26
 */
27
28
abstract class Widget {
29
30
	protected $row = null;
31
32
	public function __construct() {
33
		//
34
	}
35
36
	public function load ($row) {
37
		if (!is_array($row)) {
38
			throw new IllegalArgumentException("row has to be an array (table row).");
39
		}
40
41
		$this->row = $row;
42
	}
43
44
	public function getId () : int {
45
		return $this->row['id'];
46
	}
47
48
	public function getTitle () : string {
49
		return $this->row['title'];
50
	}
51
52
	protected function getContent () : string {
53
		return $this->row['content'];
54
	}
55
56
	protected function getClassName () : string {
57
		return $this->row['class_name'];
58
	}
59
60
	protected function getWidgetParams () : array {
61
		return unserialize($this->row['widget_params']);
62
	}
63
64
	public function getCSSId () : string {
65
		return $this->row['css_id'];
66
	}
67
68
	public function getCSSClass () : string {
69
		return $this->row['css_class'];
70
	}
71
72
	public function getRow () : array {
73
		return $this->row;
74
	}
75
76
	public function useTemplate () {
77
		return true;
78
	}
79
80
	/**
81
	 * get html code which is shown on website
82
	 */
83
	public abstract function getCode ();
84
85
	/**
86
	 * get formular html code which is shown in admin area if user edits the widget
87
	 */
88
	public abstract function getAdminForm ();
89
90
	/**
91
	 * save widget data when new settings are saved in the admin area
92
	 */
93
	public abstract function save ();
94
95
	public static function castWidget (Widget $widget) : Widget {
96
		return $widget;
97
	}
98
99
}
100
101
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
102