Completed
Pull Request — stable9 (#442)
by Joas
09:41
created

Template::getHTMLName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Bjoern Schiessle <[email protected]>
4
 * @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
5
 *
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OCA\Theming;
24
25
use OCP\IConfig;
26
use OCP\IL10N;
27
use OCP\IURLGenerator;
28
29
/**
30
 * Class Template
31
 *
32
 * Handle all the values which can be modified by this app
33
 *
34
 * @package OCA\Theming
35
 */
36
class Template extends \OC_Defaults {
37
	/** @var IConfig */
38
	private $config;
39
	/** @var  IL10N */
40
	private $l;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
41
	/** @var IURLGenerator */
42
	private $urlGenerator;
43
	/** @var string */
44
	private $name;
45
	/** @var string */
46
	private $url;
47
	/** @var string */
48
	private $slogan;
49
	/** @var string */
50
	private $color;
51
52
	/**
53
	 * Template constructor.
54
	 *
55
	 * @param IConfig $config
56
	 * @param IL10N $l
57
	 * @param IURLGenerator $urlGenerator
58
	 * @param \OC_Defaults $defaults
59
	 */
60
	public function __construct(IConfig $config,
61
								IL10N $l,
62
								IURLGenerator $urlGenerator,
63
								\OC_Defaults $defaults
64
	) {
65
		parent::__construct();
66
		$this->config = $config;
67
		$this->l = $l;
68
		$this->urlGenerator = $urlGenerator;
69
70
		$this->name = $defaults->getName();
71
		$this->url = $defaults->getBaseUrl();
72
		$this->slogan = $defaults->getSlogan();
0 ignored issues
show
Documentation Bug introduced by
It seems like $defaults->getSlogan() can also be of type object<OC_L10N_String>. However, the property $slogan is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
73
		$this->color = $defaults->getMailHeaderColor();
74
	}
75
76
	public function getName() {
77
		return $this->config->getAppValue('theming', 'name', $this->name);
78
	}
79
80
	public function getHTMLName() {
81
		return $this->config->getAppValue('theming', 'name', $this->name);
82
	}
83
84
	public function getTitle() {
85
		return $this->config->getAppValue('theming', 'name', $this->name);
86
	}
87
88
	public function getEntity() {
89
		return $this->config->getAppValue('theming', 'name', $this->name);
90
	}
91
	
92
	public function getBaseUrl() {
93
		return $this->config->getAppValue('theming', 'url', $this->url);
94
	}
95
96
	public function getSlogan() {
97
		return $this->config->getAppValue('theming', 'slogan', $this->slogan);
98
	}
99
100
	public function getShortFooter() {
101
		$slogan = $this->getSlogan();
102
		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
103
			' rel="noreferrer">' .$this->getEntity() . '</a>'.
104
			($slogan !== '' ? ' – ' . $slogan : '');
105
106
		return $footer;
107
	}
108
109
	/**
110
	 * Color that is used for the header as well as for mail headers
111
	 *
112
	 * @return string
113
	 */
114
	public function getMailHeaderColor() {
115
		return $this->config->getAppValue('theming', 'color', $this->color);
116
	}
117
118
	/**
119
	 * Increases the cache buster key
120
	 */
121
	private function increaseCacheBuster() {
122
		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
123
		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
124
	}
125
126
	/**
127
	 * Update setting in the database
128
	 *
129
	 * @param string $setting
130
	 * @param string $value
131
	 */
132
	public function set($setting, $value) {
133
		$this->config->setAppValue('theming', $setting, $value);
134
		$this->increaseCacheBuster();
135
	}
136
137
	/**
138
	 * Revert settings to the default value
139
	 *
140
	 * @param string $setting setting which should be reverted
141
	 * @return string default value
142
	 */
143
	public function undo($setting) {
144
		$this->config->deleteAppValue('theming', $setting);
145
		$this->increaseCacheBuster();
146
147
		switch ($setting) {
148
			case 'name':
149
				$returnValue = $this->getEntity();
150
				break;
151
			case 'url':
152
				$returnValue = $this->getBaseUrl();
153
				break;
154
			case 'slogan':
155
				$returnValue = $this->getSlogan();
156
				break;
157
			case 'color':
158
				$returnValue = $this->getMailHeaderColor();
159
				break;
160
			default:
161
				$returnValue = '';
162
				break;
163
		}
164
165
		return $returnValue;
166
	}
167
}
168