Skip to content

Commit

Permalink
chore: Add parameter type hints to parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Sep 18, 2024
1 parent 063d4df commit fe23079
Show file tree
Hide file tree
Showing 36 changed files with 112 additions and 127 deletions.
4 changes: 1 addition & 3 deletions lib/public/Accounts/PropertyDoesNotExistException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
*/
class PropertyDoesNotExistException extends \Exception {
/**
* Constructor
* @param string $msg the error message
* @since 15.0.0
*/
public function __construct($property) {
public function __construct(string $property) {
parent::__construct('Property ' . $property . ' does not exist.');
}
}
2 changes: 1 addition & 1 deletion lib/public/Activity/IEventMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ interface IEventMerger {
* @return IEvent
* @since 11.0
*/
public function mergeEvents($mergeParameter, IEvent $event, ?IEvent $previousEvent = null);
public function mergeEvents(string $mergeParameter, IEvent $event, ?IEvent $previousEvent = null);
}
2 changes: 1 addition & 1 deletion lib/public/Activity/IProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ interface IProvider {
* when they did not handle the event. Throwing \InvalidArgumentException directly is deprecated and will
* be logged as an error in Nextcloud 39.
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null);
public function parse(string $language, IEvent $event, ?IEvent $previousEvent = null);
}
18 changes: 8 additions & 10 deletions lib/public/App/IAppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ interface IAppManager {
/**
* Returns the app information from "appinfo/info.xml".
*
* @param string|null $lang
* @return array|null
* @since 14.0.0
*/
public function getAppInfo(string $appId, bool $path = false, $lang = null);
public function getAppInfo(string $appId, bool $path = false, ?string $lang = null);

/**
* Returns the app information from "appinfo/info.xml".
Expand All @@ -56,12 +55,11 @@ public function getAppIcon(string $appId, bool $dark = false): string|null;
/**
* Check if an app is enabled for user
*
* @param string $appId
* @param \OCP\IUser|null $user (optional) if not defined, the currently loggedin user will be used
* @param IUser|null $user (optional) if not defined, the currently loggedin user will be used
* @return bool
* @since 8.0.0
*/
public function isEnabledForUser($appId, $user = null);
public function isEnabledForUser(string $appId, ?IUser $user = null);

/**
* Check if an app is enabled in the instance
Expand All @@ -72,7 +70,7 @@ public function isEnabledForUser($appId, $user = null);
* @return bool
* @since 8.0.0
*/
public function isInstalled($appId);
public function isInstalled(string $appId);

/**
* Check if an app should be enabled by default
Expand Down Expand Up @@ -116,7 +114,7 @@ public function enableApp(string $appId, bool $forceEnable = false): void;
* @return bool
* @since 12.0.0
*/
public function hasProtectedAppType($types);
public function hasProtectedAppType(array $types);

/**
* Enable an app only for specific groups
Expand All @@ -136,7 +134,7 @@ public function enableAppForGroups(string $appId, array $groups, bool $forceEnab
* @param bool $automaticDisabled
* @since 8.0.0
*/
public function disableApp($appId, $automaticDisabled = false);
public function disableApp(string $appId, bool $automaticDisabled = false);

/**
* Get the directory for the given app.
Expand All @@ -159,7 +157,7 @@ public function getAppWebPath(string $appId): string;
/**
* List all apps enabled for a user
*
* @param \OCP\IUser $user
* @param IUser $user
* @return string[]
* @since 8.1.0
*/
Expand All @@ -184,7 +182,7 @@ public function clearAppsCache();
* @return boolean
* @since 9.0.0
*/
public function isShipped($appId);
public function isShipped(string $appId);

/**
* Loads all apps
Expand Down
4 changes: 1 addition & 3 deletions lib/public/App/ManagerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ class ManagerEvent extends Event {
/**
* DispatcherEvent constructor.
*
* @param string $event
* @param $appID
* @param \OCP\IGroup[]|null $groups
* @since 9.0.0
*/
public function __construct($event, $appID, ?array $groups = null) {
public function __construct(string $event, string $appID, ?array $groups = null) {
$this->event = $event;
$this->appID = $appID;
$this->groups = $groups;
Expand Down
10 changes: 6 additions & 4 deletions lib/public/AppFramework/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ abstract class ApiController extends Controller {
* request should be cached, defaults to 1728000 seconds
* @since 7.0.0
*/
public function __construct($appName,
public function __construct(
string $appName,
IRequest $request,
$corsMethods = 'PUT, POST, GET, DELETE, PATCH',
$corsAllowedHeaders = 'Authorization, Content-Type, Accept',
$corsMaxAge = 1728000) {
string $corsMethods = 'PUT, POST, GET, DELETE, PATCH',
string $corsAllowedHeaders = 'Authorization, Content-Type, Accept',
int $corsMaxAge = 1728000,
) {
parent::__construct($appName, $request);
$this->corsMethods = $corsMethods;
$this->corsAllowedHeaders = $corsAllowedHeaders;
Expand Down
6 changes: 4 additions & 2 deletions lib/public/AppFramework/AuthPublicShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ abstract class AuthPublicShareController extends PublicShareController {
/**
* @since 14.0.0
*/
public function __construct(string $appName,
public function __construct(
string $appName,
IRequest $request,
ISession $session,
IURLGenerator $urlGenerator) {
IURLGenerator $urlGenerator,
) {
parent::__construct($appName, $request, $session);

$this->urlGenerator = $urlGenerator;
Expand Down
2 changes: 1 addition & 1 deletion lib/public/AppFramework/Bootstrap/IRegistrationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function registerServiceAlias(string $alias, string $target): void;
*
* @since 20.0.0
*/
public function registerParameter(string $name, $value): void;
public function registerParameter(string $name, mixed $value): void;

/**
* Register a service listener
Expand Down
12 changes: 7 additions & 5 deletions lib/public/AppFramework/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ abstract class Controller {
* @param IRequest $request an instance of the request
* @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0
*/
public function __construct($appName,
IRequest $request) {
public function __construct(
string $appName,
IRequest $request,
) {
$this->appName = $appName;
$this->request = $request;

Expand Down Expand Up @@ -90,7 +92,7 @@ public function __construct($appName,
* @since 7.0.0
* @since 9.1.0 Added default parameter
*/
public function getResponderByHTTPHeader($acceptHeader, $default = 'json') {
public function getResponderByHTTPHeader(string $acceptHeader, string $default = 'json') {
$headers = explode(',', $acceptHeader);

// return the first matching responder
Expand All @@ -115,7 +117,7 @@ public function getResponderByHTTPHeader($acceptHeader, $default = 'json') {
* @param \Closure $responder
* @since 7.0.0
*/
protected function registerResponder($format, \Closure $responder) {
protected function registerResponder(string $format, \Closure $responder) {
$this->responders[$format] = $responder;
}

Expand All @@ -129,7 +131,7 @@ protected function registerResponder($format, \Closure $responder) {
* @return Response
* @since 7.0.0
*/
public function buildResponse($response, $format = 'json') {
public function buildResponse($response, string $format = 'json') {
if (array_key_exists($format, $this->responders)) {
$responder = $this->responders[$format];

Expand Down
4 changes: 1 addition & 3 deletions lib/public/AppFramework/Db/DoesNotExistException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
*/
class DoesNotExistException extends \Exception implements IMapperException {
/**
* Constructor
* @param string $msg the error message
* @since 7.0.0
*/
public function __construct($msg) {
public function __construct(string $msg) {
parent::__construct($msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
*/
class MultipleObjectsReturnedException extends \Exception implements IMapperException {
/**
* Constructor
* @param string $msg the error message
* @since 7.0.0
*/
public function __construct($msg) {
public function __construct(string $msg) {
parent::__construct($msg);
}
}
2 changes: 1 addition & 1 deletion lib/public/AppFramework/Http/DataDownloadResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(string $data, string $filename, string $contentType,
* @param string $data
* @since 8.0.0
*/
public function setData($data) {
public function setData(string $data) {
$this->data = $data;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/public/AppFramework/Http/DataResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(mixed $data = [], int $statusCode = Http::STATUS_OK,
* @return DataResponse Reference to this object
* @since 8.0.0
*/
public function setData($data) {
public function setData(mixed $data) {
$this->data = $data;

return $this;
Expand Down
Loading

0 comments on commit fe23079

Please sign in to comment.