aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/App/CodeChecker/DatabaseSchemaChecker.php30
-rw-r--r--lib/private/AppFramework/DependencyInjection/DIContainer.php4
-rw-r--r--lib/private/CapabilitiesManager.php8
-rw-r--r--lib/private/Search.php11
-rw-r--r--lib/private/Security/RateLimiting/Backend/IBackend.php13
-rw-r--r--lib/private/Security/RateLimiting/Backend/MemoryCache.php28
-rw-r--r--lib/private/Security/RateLimiting/Exception/RateLimitExceededException.php1
-rw-r--r--lib/private/Security/RateLimiting/Limiter.php27
-rw-r--r--lib/private/Security/SecureRandom.php7
9 files changed, 65 insertions, 64 deletions
diff --git a/lib/private/App/CodeChecker/DatabaseSchemaChecker.php b/lib/private/App/CodeChecker/DatabaseSchemaChecker.php
index 1255dec25c1..e407430e974 100644
--- a/lib/private/App/CodeChecker/DatabaseSchemaChecker.php
+++ b/lib/private/App/CodeChecker/DatabaseSchemaChecker.php
@@ -49,37 +49,37 @@ class DatabaseSchemaChecker {
foreach ($xml->table as $table) {
// Table names
- if (strpos($table->name, '*dbprefix*') !== 0) {
- $errors[] = 'Database schema error: name of table ' . $table->name . ' does not start with *dbprefix*';
+ if (strpos((string)$table->name, '*dbprefix*') !== 0) {
+ $errors[] = 'Database schema error: name of table ' . (string)$table->name . ' does not start with *dbprefix*';
}
- $tableName = substr($table->name, strlen('*dbprefix*'));
+ $tableName = substr((string)$table->name, strlen('*dbprefix*'));
if (strpos($tableName, '*dbprefix*') !== false) {
- $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table ' . $table->name;
+ $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table ' . (string)$table->name;
}
if (strlen($tableName) > 27) {
- $errors[] = 'Database schema error: Name of table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed';
+ $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed';
}
$hasAutoIncrement = false;
// Column names
foreach ($table->declaration->field as $column) {
- if (strpos($column->name, '*dbprefix*') !== false) {
- $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column ' . $column->name . ' on table ' . $table->name;
+ if (strpos((string)$column->name, '*dbprefix*') !== false) {
+ $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column ' . (string)$column->name . ' on table ' . (string)$table->name;
}
- if (strlen($column->name) > 30) {
- $errors[] = 'Database schema error: Name of column ' . $column->name . ' on table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 30 characters allowed';
+ if (strlen((string)$column->name) > 30) {
+ $errors[] = 'Database schema error: Name of column ' . (string)$column->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 30 characters allowed';
}
if ($column->autoincrement) {
if ($hasAutoIncrement) {
- $errors[] = 'Database schema error: Table ' . $table->name . ' has multiple autoincrement columns';
+ $errors[] = 'Database schema error: Table ' . (string)$table->name . ' has multiple autoincrement columns';
}
if (strlen($tableName) > 21) {
- $errors[] = 'Database schema error: Name of table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed';
+ $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed';
}
$hasAutoIncrement = true;
@@ -88,14 +88,14 @@ class DatabaseSchemaChecker {
// Index names
foreach ($table->declaration->index as $index) {
- $hasPrefix = strpos($index->name, '*dbprefix*');
+ $hasPrefix = strpos((string)$index->name, '*dbprefix*');
if ($hasPrefix !== false && $hasPrefix !== 0) {
- $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index ' . $index->name . ' on table ' . $table->name;
+ $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index ' . (string)$index->name . ' on table ' . (string)$table->name;
}
- $indexName = $hasPrefix === 0 ? substr($index->name, strlen('*dbprefix*')) : $index->name;
+ $indexName = $hasPrefix === 0 ? substr((string)$index->name, strlen('*dbprefix*')) : (string)$index->name;
if (strlen($indexName) > 27) {
- $errors[] = 'Database schema error: Name of index ' . $index->name . ' on table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters + *dbprefix* allowed';
+ $errors[] = 'Database schema error: Name of index ' . (string)$index->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters + *dbprefix* allowed';
}
}
}
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php
index 612728d1356..47566e0381c 100644
--- a/lib/private/AppFramework/DependencyInjection/DIContainer.php
+++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php
@@ -229,8 +229,8 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$server->getURLGenerator(),
$server->getLogger(),
$c['AppName'],
- $app->isLoggedIn(),
- $app->isAdminUser(),
+ $server->getUserSession()->isLoggedIn(),
+ $server->getGroupManager()->isAdmin($this->getUserId()),
$server->getContentSecurityPolicyManager(),
$server->getCsrfTokenManager(),
$server->getContentSecurityPolicyNonceManager(),
diff --git a/lib/private/CapabilitiesManager.php b/lib/private/CapabilitiesManager.php
index b3db9231972..5b114bffac2 100644
--- a/lib/private/CapabilitiesManager.php
+++ b/lib/private/CapabilitiesManager.php
@@ -20,8 +20,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
-namespace OC;
+declare(strict_types=1);
+
+namespace OC;
use OCP\AppFramework\QueryException;
use OCP\Capabilities\ICapability;
@@ -47,7 +49,7 @@ class CapabilitiesManager {
* @throws \InvalidArgumentException
* @return array
*/
- public function getCapabilities($public = false) {
+ public function getCapabilities(bool $public = false) : array {
$capabilities = [];
foreach($this->capabilities as $capability) {
try {
@@ -78,6 +80,6 @@ class CapabilitiesManager {
* @param \Closure $callable
*/
public function registerCapability(\Closure $callable) {
- array_push($this->capabilities, $callable);
+ $this->capabilities[] = $callable;
}
}
diff --git a/lib/private/Search.php b/lib/private/Search.php
index 17958c8e08e..0cfdf24ac97 100644
--- a/lib/private/Search.php
+++ b/lib/private/Search.php
@@ -41,17 +41,6 @@ class Search implements ISearch {
* Search all providers for $query
* @param string $query
* @param string[] $inApps optionally limit results to the given apps
- * @return array An array of OC\Search\Result's
- */
- public function search($query, array $inApps = array()) {
- // old apps might assume they get all results, so we set size 0
- return $this->searchPaged($query, $inApps, 1, 0);
- }
-
- /**
- * Search all providers for $query
- * @param string $query
- * @param string[] $inApps optionally limit results to the given apps
* @param int $page pages start at page 1
* @param int $size, 0 = all
* @return array An array of OC\Search\Result's
diff --git a/lib/private/Security/RateLimiting/Backend/IBackend.php b/lib/private/Security/RateLimiting/Backend/IBackend.php
index b20d27af42b..88c10fbbc8d 100644
--- a/lib/private/Security/RateLimiting/Backend/IBackend.php
+++ b/lib/private/Security/RateLimiting/Backend/IBackend.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
*
@@ -39,9 +40,9 @@ interface IBackend {
* @param int $seconds Seconds to look back at
* @return int
*/
- public function getAttempts($methodIdentifier,
- $userIdentifier,
- $seconds);
+ public function getAttempts(string $methodIdentifier,
+ string $userIdentifier,
+ int $seconds): int;
/**
* Registers an attempt
@@ -50,7 +51,7 @@ interface IBackend {
* @param string $userIdentifier Identifier for the user
* @param int $period Period in seconds how long this attempt should be stored
*/
- public function registerAttempt($methodIdentifier,
- $userIdentifier,
- $period);
+ public function registerAttempt(string $methodIdentifier,
+ string $userIdentifier,
+ int $period);
}
diff --git a/lib/private/Security/RateLimiting/Backend/MemoryCache.php b/lib/private/Security/RateLimiting/Backend/MemoryCache.php
index 700fa624ed4..a8fb7b87d10 100644
--- a/lib/private/Security/RateLimiting/Backend/MemoryCache.php
+++ b/lib/private/Security/RateLimiting/Backend/MemoryCache.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
*
@@ -54,8 +55,8 @@ class MemoryCache implements IBackend {
* @param string $userIdentifier
* @return string
*/
- private function hash($methodIdentifier,
- $userIdentifier) {
+ private function hash(string $methodIdentifier,
+ string $userIdentifier): string {
return hash('sha512', $methodIdentifier . $userIdentifier);
}
@@ -63,9 +64,14 @@ class MemoryCache implements IBackend {
* @param string $identifier
* @return array
*/
- private function getExistingAttempts($identifier) {
- $cachedAttempts = json_decode($this->cache->get($identifier), true);
- if(is_array($cachedAttempts)) {
+ private function getExistingAttempts(string $identifier): array {
+ $cachedAttempts = $this->cache->get($identifier);
+ if ($cachedAttempts === null) {
+ return [];
+ }
+
+ $cachedAttempts = json_decode($cachedAttempts, true);
+ if(\is_array($cachedAttempts)) {
return $cachedAttempts;
}
@@ -75,9 +81,9 @@ class MemoryCache implements IBackend {
/**
* {@inheritDoc}
*/
- public function getAttempts($methodIdentifier,
- $userIdentifier,
- $seconds) {
+ public function getAttempts(string $methodIdentifier,
+ string $userIdentifier,
+ int $seconds): int {
$identifier = $this->hash($methodIdentifier, $userIdentifier);
$existingAttempts = $this->getExistingAttempts($identifier);
@@ -96,9 +102,9 @@ class MemoryCache implements IBackend {
/**
* {@inheritDoc}
*/
- public function registerAttempt($methodIdentifier,
- $userIdentifier,
- $period) {
+ public function registerAttempt(string $methodIdentifier,
+ string $userIdentifier,
+ int $period) {
$identifier = $this->hash($methodIdentifier, $userIdentifier);
$existingAttempts = $this->getExistingAttempts($identifier);
$currentTime = $this->timeFactory->getTime();
diff --git a/lib/private/Security/RateLimiting/Exception/RateLimitExceededException.php b/lib/private/Security/RateLimiting/Exception/RateLimitExceededException.php
index ffe9b534fed..ae4fa1d6c26 100644
--- a/lib/private/Security/RateLimiting/Exception/RateLimitExceededException.php
+++ b/lib/private/Security/RateLimiting/Exception/RateLimitExceededException.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
*
diff --git a/lib/private/Security/RateLimiting/Limiter.php b/lib/private/Security/RateLimiting/Limiter.php
index 6a4176a0d50..5267497f86f 100644
--- a/lib/private/Security/RateLimiting/Limiter.php
+++ b/lib/private/Security/RateLimiting/Limiter.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
*
@@ -58,12 +59,12 @@ class Limiter {
* @param int $limit
* @throws RateLimitExceededException
*/
- private function register($methodIdentifier,
- $userIdentifier,
- $period,
- $limit) {
- $existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier, (int)$period);
- if ($existingAttempts >= (int)$limit) {
+ private function register(string $methodIdentifier,
+ string $userIdentifier,
+ int $period,
+ int $limit) {
+ $existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier, $period);
+ if ($existingAttempts >= $limit) {
throw new RateLimitExceededException();
}
@@ -79,10 +80,10 @@ class Limiter {
* @param string $ip
* @throws RateLimitExceededException
*/
- public function registerAnonRequest($identifier,
- $anonLimit,
- $anonPeriod,
- $ip) {
+ public function registerAnonRequest(string $identifier,
+ int $anonLimit,
+ int $anonPeriod,
+ string $ip) {
$ipSubnet = (new IpAddress($ip))->getSubnet();
$anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet);
@@ -98,9 +99,9 @@ class Limiter {
* @param IUser $user
* @throws RateLimitExceededException
*/
- public function registerUserRequest($identifier,
- $userLimit,
- $userPeriod,
+ public function registerUserRequest(string $identifier,
+ int $userLimit,
+ int $userPeriod,
IUser $user) {
$userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID());
$this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit);
diff --git a/lib/private/Security/SecureRandom.php b/lib/private/Security/SecureRandom.php
index 5bd909ea002..75d9d02a1d3 100644
--- a/lib/private/Security/SecureRandom.php
+++ b/lib/private/Security/SecureRandom.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -70,9 +71,9 @@ class SecureRandom implements ISecureRandom {
* specified all valid base64 characters are used.
* @return string
*/
- public function generate($length,
- $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/') {
- $maxCharIndex = strlen($characters) - 1;
+ public function generate(int $length,
+ string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'): string {
+ $maxCharIndex = \strlen($characters) - 1;
$randomString = '';
while($length > 0) {