diff --git a/lib/AppConfig.php b/lib/AppConfig.php index 33681fe40..4c0757517 100644 --- a/lib/AppConfig.php +++ b/lib/AppConfig.php @@ -28,8 +28,8 @@ namespace OCA\Officeonline; -use \OCP\IConfig; use OCA\Officeonline\AppInfo\Application; +use OCP\IConfig; class AppConfig { private $defaults = [ diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index 7efd08af8..e548afd33 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -11,20 +11,17 @@ namespace OCA\Officeonline\Controller; -use \OCA\Officeonline\AppConfig; -use \OCA\Officeonline\Helper; -use \OCP\AppFramework\Controller; -use \OCP\AppFramework\Http\ContentSecurityPolicy; -use \OCP\AppFramework\Http\TemplateResponse; -use \OCP\IConfig; -use \OCP\IL10N; -use \OCP\IRequest; use OC\Files\Type\TemplateManager; +use OCA\Officeonline\AppConfig; +use OCA\Officeonline\Helper; use OCA\Officeonline\Service\FederationService; use OCA\Officeonline\TokenManager; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\RedirectResponse; +use OCP\AppFramework\Http\TemplateResponse; use OCP\Constants; use OCP\Files\File; use OCP\Files\Folder; @@ -33,6 +30,9 @@ use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; +use OCP\IConfig; +use OCP\IL10N; +use OCP\IRequest; use OCP\ISession; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; @@ -255,7 +255,7 @@ public function index($fileId, $path = null) { if ($encryptionManager->isEnabled()) { // Update the current file to be accessible with system public shared key $owner = $item->getOwner()->getUID(); - $absPath = '/' . $owner . '/' . $item->getInternalPath(); + $absPath = '/' . $owner . '/' . $item->getInternalPath(); $accessList = \OC::$server->getEncryptionFilesHelper()->getAccessList($absPath); $accessList['public'] = true; $encryptionManager->getEncryptionModule()->update($absPath, $owner, $accessList); diff --git a/lib/Controller/FederationController.php b/lib/Controller/FederationController.php index 72a525979..da4c88449 100755 --- a/lib/Controller/FederationController.php +++ b/lib/Controller/FederationController.php @@ -22,11 +22,11 @@ */ namespace OCA\Officeonline\Controller; -use \OCP\AppFramework\OCSController; use OCA\Officeonline\Db\WopiMapper; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCSController; use OCP\IConfig; use OCP\IRequest; use OCP\Share\IManager; diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 15c3adcbc..ec17cb9aa 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -11,15 +11,15 @@ namespace OCA\Officeonline\Controller; -use \OCP\AppFramework\Controller; -use \OCP\IL10N; -use \OCP\IRequest; use Exception; use OCA\Officeonline\AppConfig; use OCA\Officeonline\WOPI\DiscoveryManager; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; +use OCP\IL10N; +use OCP\IRequest; use Psr\Log\LoggerInterface; class SettingsController extends Controller { @@ -28,7 +28,7 @@ class SettingsController extends Controller { private $l10n; /** @var AppConfig */ private $appConfig; - /** @var DiscoveryManager */ + /** @var DiscoveryManager */ private $discoveryManager; /** @var LoggerInterface */ private $logger; diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index 816ed7c06..5108fcd7e 100755 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -349,12 +349,12 @@ private function fallbackLock($fileId, $access_token) { } $lck = $this->request->getHeader('X-WOPI-Lock'); $wover = $this->request->getHeader('X-WOPI-Override'); - if (strlen($lck) === 0 && $wover !== "GET_LOCK" && strpos($wover, "LOCK") !== false) { + if (strlen($lck) === 0 && $wover !== 'GET_LOCK' && strpos($wover, 'LOCK') !== false) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } $result = new DataResponse([], Http::STATUS_NOT_IMPLEMENTED); switch ($wover) { - case "LOCK": + case 'LOCK': $oldLck = $this->request->getHeader('X-WOPI-OldLock'); if (strlen($oldLck) > 0) { $fLock = $this->lockMapper->find($fileId); @@ -392,12 +392,12 @@ private function fallbackLock($fileId, $access_token) { $result->setStatus(Http::STATUS_OK); } break; - case "GET_LOCK": + case 'GET_LOCK': $fLock = $this->lockMapper->find($fileId); $result->setStatus(Http::STATUS_OK); $result->addHeader('X-WOPI-Lock', empty($fLock) ? '' : $fLock->getValue()); break; - case "REFRESH_LOCK": + case 'REFRESH_LOCK': $fLock = $this->lockMapper->find($fileId); if (!empty($fLock)) { if ($fLock->getValue() !== $lck) { @@ -414,7 +414,7 @@ private function fallbackLock($fileId, $access_token) { $result->addHeader('X-WOPI-Lock', ''); } break; - case "UNLOCK": + case 'UNLOCK': $fLock = $this->lockMapper->find($fileId); if (!empty($fLock)) { if ($fLock->getValue() !== $lck) { @@ -664,7 +664,7 @@ public function postFile($fileId, $access_token) { return new JSONResponse([], Http::STATUS_UNAUTHORIZED); } - if ((int) $fileId !== $wopi->getFileid()) { + if ((int)$fileId !== $wopi->getFileid()) { return new JSONResponse([], Http::STATUS_FORBIDDEN); } diff --git a/lib/Db/DirectMapper.php b/lib/Db/DirectMapper.php index 59ff82034..801783e47 100644 --- a/lib/Db/DirectMapper.php +++ b/lib/Db/DirectMapper.php @@ -37,7 +37,7 @@ class DirectMapper extends QBMapper { /** @var ISecureRandom */ protected $random; - /**@var ITimeFactory */ + /** @var ITimeFactory */ protected $timeFactory; public function __construct(IDBConnection $db, diff --git a/lib/Helper.php b/lib/Helper.php index e021c055f..520b607a8 100755 --- a/lib/Helper.php +++ b/lib/Helper.php @@ -11,8 +11,8 @@ namespace OCA\Officeonline; -use \DateTime; -use \DateTimeZone; +use DateTime; +use DateTimeZone; use OCP\Files\Folder; class Helper { diff --git a/lib/Middleware/WOPIMiddleware.php b/lib/Middleware/WOPIMiddleware.php index 7977a0bd4..b63b0acf4 100644 --- a/lib/Middleware/WOPIMiddleware.php +++ b/lib/Middleware/WOPIMiddleware.php @@ -114,7 +114,7 @@ public function isWOPIAllowed(): bool { * @copyright (IPv6) MW. https://stackoverflow.com/questions/7951061/matching-ipv6-address-to-a-cidr-subnet via */ private function matchCidr(string $ip, string $range): bool { - list($subnet, $bits) = array_pad(explode('/', $range), 2, null); + [$subnet, $bits] = array_pad(explode('/', $range), 2, null); if ($bits === null) { $bits = 32; } @@ -133,23 +133,23 @@ private function matchCidr(string $ip, string $range): bool { $subnet = inet_pton($subnet); $ip = inet_pton($ip); - $binMask = str_repeat("f", $bits / 4); + $binMask = str_repeat('f', $bits / 4); switch ($bits % 4) { case 0: break; case 1: - $binMask .= "8"; + $binMask .= '8'; break; case 2: - $binMask .= "c"; + $binMask .= 'c'; break; case 3: - $binMask .= "e"; + $binMask .= 'e'; break; } $binMask = str_pad($binMask, 32, '0'); - $binMask = pack("H*", $binMask); + $binMask = pack('H*', $binMask); if (($ip & $binMask) === $subnet) { return true; diff --git a/lib/Preview/Office.php b/lib/Preview/Office.php index a8fd5a278..6a0eb8777 100644 --- a/lib/Preview/Office.php +++ b/lib/Preview/Office.php @@ -87,7 +87,7 @@ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $options['multipart'] = [['name' => $path, 'contents' => $stream]]; try { - $response = $client->post($this->getWopiURL(). '/lool/convert-to/png', $options); + $response = $client->post($this->getWopiURL() . '/lool/convert-to/png', $options); } catch (\Exception $e) { $this->logger->info('Failed to convert file to preview', [ 'exception' => $e, diff --git a/lib/Service/FederationService.php b/lib/Service/FederationService.php index 1367a9cdf..dd4820657 100644 --- a/lib/Service/FederationService.php +++ b/lib/Service/FederationService.php @@ -41,7 +41,7 @@ class FederationService { private $cache; /** @var IClientService */ private $clientService; - /** @var LoggerInterface */ + /** @var LoggerInterface */ private $logger; /** @var TrustedServers */ private $trustedServers; diff --git a/lib/Service/UserScopeService.php b/lib/Service/UserScopeService.php index c13811b2b..3849eeadd 100644 --- a/lib/Service/UserScopeService.php +++ b/lib/Service/UserScopeService.php @@ -39,7 +39,7 @@ public function __construct(IUserSession $userSession, IUserManager $userManager * @param $uid * @throws \InvalidArgumentException */ - public function setUserScope(string $uid = null) { + public function setUserScope(?string $uid = null) { if ($uid === null) { return; } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 7b2a12f54..f28d728e7 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -76,8 +76,8 @@ public function getSection() { } /** * @return int whether the form should be rather on the top or bottom of - * the admin section. The forms are arranged in ascending order of the - * priority values. It is required to return a value between 0 and 100. + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. * * keep the server setting at the top, right after "server settings" */ diff --git a/lib/WOPI/DiscoveryManager.php b/lib/WOPI/DiscoveryManager.php index 7b19d4b78..06b8cf476 100644 --- a/lib/WOPI/DiscoveryManager.php +++ b/lib/WOPI/DiscoveryManager.php @@ -68,7 +68,7 @@ public function get() { try { $file = $this->appData->getFile('discovery.xml'); $decodedFile = json_decode($file->getContent(), true); - if ($decodedFile['timestamp'] + 3600 > $this->timeFactory->getTime()) { + if ($this->timeFactory->getTime() < $decodedFile['timestamp'] + 3600) { return $decodedFile['data']; } } catch (NotFoundException $e) { diff --git a/lib/WOPI/Parser.php b/lib/WOPI/Parser.php index fb066218a..181829482 100755 --- a/lib/WOPI/Parser.php +++ b/lib/WOPI/Parser.php @@ -182,8 +182,8 @@ public function getUrlSrcForFile(File $file, bool $edit): string { 'internal-' . $fallbackProtocol, ]; - $userAgent = $_SERVER["HTTP_USER_AGENT"]; - if (preg_match("/(android|mobile)/i", $userAgent)) { + $userAgent = $_SERVER['HTTP_USER_AGENT']; + if (preg_match('/(android|mobile)/i', $userAgent)) { $edit = false; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index da579ff7a..10c2acd3f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,7 +4,7 @@ define('PHPUNIT_RUN', 1); } -require_once __DIR__.'/../../../lib/base.php'; +require_once __DIR__ . '/../../../lib/base.php'; if (!class_exists('\PHPUnit\Framework\TestCase')) { require_once('PHPUnit/Autoload.php'); diff --git a/tests/features/bootstrap/FeatureContext.php b/tests/features/bootstrap/FeatureContext.php index cb2d4a277..f10655e35 100644 --- a/tests/features/bootstrap/FeatureContext.php +++ b/tests/features/bootstrap/FeatureContext.php @@ -42,7 +42,7 @@ public function userOpens($user, $file) { preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0); $result = []; foreach ($matches as $match) { - $result[$match[1]] = str_replace("'", "", $match[2]); + $result[$match[1]] = str_replace("'", '', $match[2]); } $this->fileId = $result['fileId']; @@ -69,7 +69,7 @@ public function aGuestOpensTheShareLink() { preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0); $result = []; foreach ($matches as $match) { - $result[$match[1]] = str_replace("'", "", $match[2]); + $result[$match[1]] = str_replace("'", '', $match[2]); } $this->fileId = $result['fileId']; @@ -101,7 +101,7 @@ public function aGuestOpensTheShareLinkAs($user) { preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0); $result = []; foreach ($matches as $match) { - $result[$match[1]] = str_replace("'", "", $match[2]); + $result[$match[1]] = str_replace("'", '', $match[2]); } $this->fileId = $result['fileId'];