Completed
Push — master ( 33d925...cc7944 )
by Thomas
09:52
created

Admin::getSectionID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace OCA\Files\Panels;
4
5
use OC\Settings\Panels\Helper;
6
use OCP\Settings\ISettings;
7
use OCP\Template;
8
use OCP\IURLGenerator;
9
10
class Admin implements ISettings {
11
12
	/** @var IURLGenerator */
13
	protected $urlGenerator;
14
	/** @var Helper */
15
	protected $helper;
16
17
	public function __construct(IURLGenerator $urlGenerator,
18
								Helper $helper) {
19
		$this->urlGenerator = $urlGenerator;
20
		$this->helper = $helper;
21
	}
22
23
	public function getSectionID() {
24
		return 'storage';
25
	}
26
27
	public function getPriority() {
28
		return 0;
29
	}
30
31
	public function getPanel() {
32
		$htaccessWorking=(getenv('htaccessWorking')=='true');
33
		$upload_max_filesize = \OC::$server->getIniWrapper()->getBytes('upload_max_filesize');
34
		$post_max_size = \OC::$server->getIniWrapper()->getBytes('post_max_size');
35
		$maxUploadFilesize = \OCP\Util::humanFileSize(min($upload_max_filesize, $post_max_size));
36
		$htaccessWritable=is_writable(\OC::$SERVERROOT.'/.htaccess');
37
		$userIniWritable=is_writable(\OC::$SERVERROOT.'/.user.ini');
38
		$tmpl = new Template( 'files', 'admin' );
39
		$tmpl->assign('urlGenerator', $this->urlGenerator);
0 ignored issues
show
Documentation introduced by
$this->urlGenerator is of type object<OCP\IURLGenerator>, but the function expects a array|boolean|integer|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
40
		$tmpl->assign( 'uploadChangeable', ($htaccessWorking and $htaccessWritable) or $userIniWritable );
41
		$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
42
		// max possible makes only sense on a 32 bit system
43
		$tmpl->assign( 'displayMaxPossibleUploadSize', PHP_INT_SIZE===4);
44
		$tmpl->assign( 'maxPossibleUploadSize', \OCP\Util::humanFileSize(PHP_INT_MAX));
45
		return $tmpl;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $tmpl; (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...
46
		}
47
48
}
49