Completed
Push — stable9 ( 980d90...450926 )
by Morris
08:37
created

Template::getTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
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 getTitle() {
81
		return $this->config->getAppValue('theming', 'name', $this->name);
82
	}
83
84
	public function getEntity() {
85
		return $this->config->getAppValue('theming', 'name', $this->name);
86
	}
87
	
88
	public function getBaseUrl() {
89
		return $this->config->getAppValue('theming', 'url', $this->url);
90
	}
91
92
	public function getSlogan() {
93
		return $this->config->getAppValue('theming', 'slogan', $this->slogan);
94
	}
95
96
	/**
97
	 * Color that is used for the header as well as for mail headers
98
	 *
99
	 * @return string
100
	 */
101
	public function getMailHeaderColor() {
102
		return $this->config->getAppValue('theming', 'color', $this->color);
103
	}
104
105
	/**
106
	 * Increases the cache buster key
107
	 */
108
	private function increaseCacheBuster() {
109
		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
110
		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
111
	}
112
113
	/**
114
	 * Update setting in the database
115
	 *
116
	 * @param string $setting
117
	 * @param string $value
118
	 */
119
	public function set($setting, $value) {
120
		$this->config->setAppValue('theming', $setting, $value);
121
		$this->increaseCacheBuster();
122
	}
123
124
	/**
125
	 * Revert settings to the default value
126
	 *
127
	 * @param string $setting setting which should be reverted
128
	 * @return string default value
129
	 */
130
	public function undo($setting) {
131
		$this->config->deleteAppValue('theming', $setting);
132
		$this->increaseCacheBuster();
133
134
		switch ($setting) {
135
			case 'name':
136
				$returnValue = $this->getEntity();
137
				break;
138
			case 'url':
139
				$returnValue = $this->getBaseUrl();
140
				break;
141
			case 'slogan':
142
				$returnValue = $this->getSlogan();
143
				break;
144
			case 'color':
145
				$returnValue = $this->getMailHeaderColor();
146
				break;
147
			default:
148
				$returnValue = '';
149
				break;
150
		}
151
152
		return $returnValue;
153
	}
154
}
155