Completed
Pull Request — master (#31552)
by Victor
12:38
created

Legal::getPriority()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 3
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 3
loc 3
rs 10
1
<?php
2
/**
3
 * @author Viktar Dubiniuk <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2018, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OC\Settings\Panels\Admin;
23
24
use OCP\IConfig;
25
use OCP\Settings\ISettings;
26
use OCP\Template;
27
28 View Code Duplication
class Legal implements ISettings {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
30
	/**
31
	 * @var IConfig
32
	 */
33
	protected $config;
34
35
	public function __construct(IConfig $config) {
36
		$this->config = $config;
37
	}
38
39
	public function getPriority() {
40
		return 5;
41
	}
42
43
	public function getPanel() {
44
		$template = new Template('settings', 'panels/admin/legal');
45
		$template->assign('read-only', $this->config->isSystemConfigReadOnly());
46
		$template->assign(
47
			'legal_imprint',
48
			$this->config->getAppValue('core', 'legal.imprint_url', '')
49
		);
50
		$template->assign(
51
			'legal_privacy_policy',
52
			$this->config->getAppValue('core', 'legal.privacy_policy_url', '')
53
		);
54
		return $template;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $template; (OCP\Template) is incompatible with the return type declared by the interface OCP\Settings\ISettings::getPanel of type OCP\AppFramework\Http\TemplateResponse.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
55
	}
56
57
	public function getSectionID() {
58
		return 'general';
59
	}
60
}
61