Completed
Push — master ( 850169...6f6518 )
by Lukas
43:58 queued 29:47
created

API::addRegularTask()   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 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bernhard Posselt <[email protected]>
6
 * @author Lukas Reschke <[email protected]>
7
 * @author Morris Jobke <[email protected]>
8
 * @author Robin Appelman <[email protected]>
9
 * @author Robin McCorkell <[email protected]>
10
 * @author Thomas Müller <[email protected]>
11
 *
12
 * @license AGPL-3.0
13
 *
14
 * This code is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License, version 3,
16
 * as published by the Free Software Foundation.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License, version 3,
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
25
 *
26
 */
27
28
29
namespace OC\AppFramework\Core;
30
use OCP\AppFramework\IApi;
31
32
33
/**
34
 * This is used to wrap the owncloud static api calls into an object to make the
35
 * code better abstractable for use in the dependency injection container
36
 *
37
 * Should you find yourself in need for more methods, simply inherit from this
38
 * class and add your methods
39
 * @deprecated
40
 */
41
class API implements IApi{
0 ignored issues
show
Deprecated Code introduced by
The interface OCP\AppFramework\IApi has been deprecated with message: 8.0.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
42
43
	private $appName;
44
45
	/**
46
	 * constructor
47
	 * @param string $appName the name of your application
48
	 */
49
	public function __construct($appName){
50
		$this->appName = $appName;
51
	}
52
53
54
	/**
55
	 * Gets the userid of the current user
56
	 * @return string the user id of the current user
57
	 * @deprecated Use \OC::$server->getUserSession()->getUser()->getUID()
58
	 */
59
	public function getUserId(){
60
		return \OCP\User::getUser();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return \OCP\User::getUser(); (object|integer|double|string|array|boolean) is incompatible with the return type declared by the interface OCP\AppFramework\IApi::getUserId of type string.

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...
Deprecated Code introduced by
The method OCP\User::getUser() has been deprecated with message: 8.0.0 Use \OC::$server->getUserSession()->getUser()->getUID()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
61
	}
62
63
64
	/**
65
	 * Adds a new javascript file
66
	 * @deprecated include javascript and css in template files
67
	 * @param string $scriptName the name of the javascript in js/ without the suffix
68
	 * @param string $appName the name of the app, defaults to the current one
69
	 */
70
	public function addScript($scriptName, $appName=null){
71
		if($appName === null){
72
			$appName = $this->appName;
73
		}
74
		\OCP\Util::addScript($appName, $scriptName);
75
	}
76
77
78
	/**
79
	 * Adds a new css file
80
	 * @deprecated include javascript and css in template files
81
	 * @param string $styleName the name of the css file in css/without the suffix
82
	 * @param string $appName the name of the app, defaults to the current one
83
	 */
84
	public function addStyle($styleName, $appName=null){
85
		if($appName === null){
86
			$appName = $this->appName;
87
		}
88
		\OCP\Util::addStyle($appName, $styleName);
89
	}
90
91
92
	/**
93
	 * @deprecated include javascript and css in template files
94
	 * shorthand for addScript for files in the 3rdparty directory
95
	 * @param string $name the name of the file without the suffix
96
	 */
97
	public function add3rdPartyScript($name){
98
		\OCP\Util::addScript($this->appName . '/3rdparty', $name);
99
	}
100
101
102
	/**
103
	 * @deprecated include javascript and css in template files
104
	 * shorthand for addStyle for files in the 3rdparty directory
105
	 * @param string $name the name of the file without the suffix
106
	 */
107
	public function add3rdPartyStyle($name){
108
		\OCP\Util::addStyle($this->appName . '/3rdparty', $name);
109
	}
110
111
112
	/**
113
	 * @deprecated communication between apps should happen over built in
114
	 * callbacks or interfaces (check the contacts and calendar managers)
115
	 * Checks if an app is enabled
116
	 * also use \OC::$server->getAppManager()->isEnabledForUser($appName)
117
	 * @param string $appName the name of an app
118
	 * @return bool true if app is enabled
119
	 */
120
	public function isAppEnabled($appName){
121
		return \OCP\App::isEnabled($appName);
122
	}
123
124
125
	/**
126
	 * used to return and open a new event source
127
	 * @return \OCP\IEventSource a new open EventSource class
128
	 * @deprecated Use \OC::$server->createEventSource();
129
	 */
130
	public function openEventSource(){
131
		return \OC::$server->createEventSource();
132
	}
133
134
	/**
135
	 * @deprecated register hooks directly for class that build in hook interfaces
136
	 * connects a function to a hook
137
	 * @param string $signalClass class name of emitter
138
	 * @param string $signalName name of signal
139
	 * @param string $slotClass class name of slot
140
	 * @param string $slotName name of slot, in another word, this is the
141
	 *               name of the method that will be called when registered
142
	 *               signal is emitted.
143
	 * @return bool always true
144
	 */
145
	public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
146
		return \OCP\Util::connectHook($signalClass, $signalName, $slotClass, $slotName);
147
	}
148
149
	/**
150
	 * @deprecated implement the emitter interface instead
151
	 * Emits a signal. To get data from the slot use references!
152
	 * @param string $signalClass class name of emitter
153
	 * @param string $signalName name of signal
154
	 * @param array $params default: array() array with additional data
155
	 * @return bool true if slots exists or false if not
156
	 */
157
	public function emitHook($signalClass, $signalName, $params = array()) {
158
		return  \OCP\Util::emitHook($signalClass, $signalName, $params);
159
	}
160
161
	/**
162
	 * clear hooks
163
	 * @deprecated clear hooks directly for class that build in hook interfaces
164
	 * @param string $signalClass
165
	 * @param string $signalName
166
	 */
167
	public function clearHook($signalClass=false, $signalName=false) {
168
		if ($signalClass) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $signalClass of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
169
			\OC_Hook::clear($signalClass, $signalName);
0 ignored issues
show
Bug introduced by
It seems like $signalName defined by parameter $signalName on line 167 can also be of type false; however, OC_Hook::clear() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
170
		}
171
	}
172
173
	/**
174
	 * Tells ownCloud to include a template in the admin overview
175
	 * @param string $mainPath the path to the main php file without the php
176
	 * suffix, relative to your apps directory! not the template directory
177
	 * @param string $appName the name of the app, defaults to the current one
178
	 */
179
	public function registerAdmin($mainPath, $appName=null) {
180
		if($appName === null){
181
			$appName = $this->appName;
182
		}
183
184
		\OCP\App::registerAdmin($appName, $mainPath);
185
	}
186
187
188
}
189