Passed
Push — master ( 6156a4...5d03b5 )
by Blizzz
14:08 queued 10s
created
lib/private/Encryption/File.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
 		// always add owner to the list of users with access to the file
74 74
 		$userIds = [$owner];
75 75
 
76
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
76
+		if (!$this->util->isFile($owner.'/'.$ownerPath)) {
77 77
 			return ['users' => $userIds, 'public' => false];
78 78
 		}
79 79
 
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -34,94 +34,94 @@
 block discarded – undo
34 34
 
35 35
 class File implements \OCP\Encryption\IFile {
36 36
 
37
-	/** @var Util */
38
-	protected $util;
39
-
40
-	/** @var IRootFolder */
41
-	private $rootFolder;
42
-
43
-	/** @var IManager */
44
-	private $shareManager;
45
-
46
-	/**
47
-	 * cache results of already checked folders
48
-	 *
49
-	 * @var array
50
-	 */
51
-	protected $cache;
52
-
53
-	public function __construct(Util $util,
54
-								IRootFolder $rootFolder,
55
-								IManager $shareManager) {
56
-		$this->util = $util;
57
-		$this->cache = new CappedMemoryCache();
58
-		$this->rootFolder = $rootFolder;
59
-		$this->shareManager = $shareManager;
60
-	}
61
-
62
-
63
-	/**
64
-	 * get list of users with access to the file
65
-	 *
66
-	 * @param string $path to the file
67
-	 * @return array  ['users' => $uniqueUserIds, 'public' => $public]
68
-	 */
69
-	public function getAccessList($path) {
70
-
71
-		// Make sure that a share key is generated for the owner too
72
-		list($owner, $ownerPath) = $this->util->getUidAndFilename($path);
73
-
74
-		// always add owner to the list of users with access to the file
75
-		$userIds = [$owner];
76
-
77
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
78
-			return ['users' => $userIds, 'public' => false];
79
-		}
80
-
81
-		$ownerPath = substr($ownerPath, strlen('/files'));
82
-		$userFolder = $this->rootFolder->getUserFolder($owner);
83
-		try {
84
-			$file = $userFolder->get($ownerPath);
85
-		} catch (NotFoundException $e) {
86
-			$file = null;
87
-		}
88
-		$ownerPath = $this->util->stripPartialFileExtension($ownerPath);
89
-
90
-		// first get the shares for the parent and cache the result so that we don't
91
-		// need to check all parents for every file
92
-		$parent = dirname($ownerPath);
93
-		$parentNode = $userFolder->get($parent);
94
-		if (isset($this->cache[$parent])) {
95
-			$resultForParents = $this->cache[$parent];
96
-		} else {
97
-			$resultForParents = $this->shareManager->getAccessList($parentNode);
98
-			$this->cache[$parent] = $resultForParents;
99
-		}
100
-		$userIds = array_merge($userIds, $resultForParents['users']);
101
-		$public = $resultForParents['public'] || $resultForParents['remote'];
102
-
103
-
104
-		// Find out who, if anyone, is sharing the file
105
-		if ($file !== null) {
106
-			$resultForFile = $this->shareManager->getAccessList($file, false);
107
-			$userIds = array_merge($userIds, $resultForFile['users']);
108
-			$public = $resultForFile['public'] || $resultForFile['remote'] || $public;
109
-		}
110
-
111
-		// check if it is a group mount
112
-		if (\OCP\App::isEnabled("files_external")) {
113
-			$mounts = \OCA\Files_External\MountConfig::getSystemMountPoints();
114
-			foreach ($mounts as $mount) {
115
-				if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
116
-					$mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
117
-					$userIds = array_merge($userIds, $mountedFor);
118
-				}
119
-			}
120
-		}
121
-
122
-		// Remove duplicate UIDs
123
-		$uniqueUserIds = array_unique($userIds);
124
-
125
-		return ['users' => $uniqueUserIds, 'public' => $public];
126
-	}
37
+    /** @var Util */
38
+    protected $util;
39
+
40
+    /** @var IRootFolder */
41
+    private $rootFolder;
42
+
43
+    /** @var IManager */
44
+    private $shareManager;
45
+
46
+    /**
47
+     * cache results of already checked folders
48
+     *
49
+     * @var array
50
+     */
51
+    protected $cache;
52
+
53
+    public function __construct(Util $util,
54
+                                IRootFolder $rootFolder,
55
+                                IManager $shareManager) {
56
+        $this->util = $util;
57
+        $this->cache = new CappedMemoryCache();
58
+        $this->rootFolder = $rootFolder;
59
+        $this->shareManager = $shareManager;
60
+    }
61
+
62
+
63
+    /**
64
+     * get list of users with access to the file
65
+     *
66
+     * @param string $path to the file
67
+     * @return array  ['users' => $uniqueUserIds, 'public' => $public]
68
+     */
69
+    public function getAccessList($path) {
70
+
71
+        // Make sure that a share key is generated for the owner too
72
+        list($owner, $ownerPath) = $this->util->getUidAndFilename($path);
73
+
74
+        // always add owner to the list of users with access to the file
75
+        $userIds = [$owner];
76
+
77
+        if (!$this->util->isFile($owner . '/' . $ownerPath)) {
78
+            return ['users' => $userIds, 'public' => false];
79
+        }
80
+
81
+        $ownerPath = substr($ownerPath, strlen('/files'));
82
+        $userFolder = $this->rootFolder->getUserFolder($owner);
83
+        try {
84
+            $file = $userFolder->get($ownerPath);
85
+        } catch (NotFoundException $e) {
86
+            $file = null;
87
+        }
88
+        $ownerPath = $this->util->stripPartialFileExtension($ownerPath);
89
+
90
+        // first get the shares for the parent and cache the result so that we don't
91
+        // need to check all parents for every file
92
+        $parent = dirname($ownerPath);
93
+        $parentNode = $userFolder->get($parent);
94
+        if (isset($this->cache[$parent])) {
95
+            $resultForParents = $this->cache[$parent];
96
+        } else {
97
+            $resultForParents = $this->shareManager->getAccessList($parentNode);
98
+            $this->cache[$parent] = $resultForParents;
99
+        }
100
+        $userIds = array_merge($userIds, $resultForParents['users']);
101
+        $public = $resultForParents['public'] || $resultForParents['remote'];
102
+
103
+
104
+        // Find out who, if anyone, is sharing the file
105
+        if ($file !== null) {
106
+            $resultForFile = $this->shareManager->getAccessList($file, false);
107
+            $userIds = array_merge($userIds, $resultForFile['users']);
108
+            $public = $resultForFile['public'] || $resultForFile['remote'] || $public;
109
+        }
110
+
111
+        // check if it is a group mount
112
+        if (\OCP\App::isEnabled("files_external")) {
113
+            $mounts = \OCA\Files_External\MountConfig::getSystemMountPoints();
114
+            foreach ($mounts as $mount) {
115
+                if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
116
+                    $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
117
+                    $userIds = array_merge($userIds, $mountedFor);
118
+                }
119
+            }
120
+        }
121
+
122
+        // Remove duplicate UIDs
123
+        $uniqueUserIds = array_unique($userIds);
124
+
125
+        return ['users' => $uniqueUserIds, 'public' => $public];
126
+    }
127 127
 }
Please login to merge, or discard this patch.
lib/private/Encryption/Update.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -33,159 +33,159 @@
 block discarded – undo
33 33
  */
34 34
 class Update {
35 35
 
36
-	/** @var \OC\Files\View */
37
-	protected $view;
38
-
39
-	/** @var \OC\Encryption\Util */
40
-	protected $util;
41
-
42
-	/** @var \OC\Files\Mount\Manager */
43
-	protected $mountManager;
44
-
45
-	/** @var \OC\Encryption\Manager */
46
-	protected $encryptionManager;
47
-
48
-	/** @var string */
49
-	protected $uid;
50
-
51
-	/** @var \OC\Encryption\File */
52
-	protected $file;
53
-
54
-	/**
55
-	 *
56
-	 * @param \OC\Files\View $view
57
-	 * @param \OC\Encryption\Util $util
58
-	 * @param \OC\Files\Mount\Manager $mountManager
59
-	 * @param \OC\Encryption\Manager $encryptionManager
60
-	 * @param \OC\Encryption\File $file
61
-	 * @param string $uid
62
-	 */
63
-	public function __construct(
64
-			View $view,
65
-			Util $util,
66
-			Mount\Manager $mountManager,
67
-			Manager $encryptionManager,
68
-			File $file,
69
-			$uid
70
-		) {
71
-		$this->view = $view;
72
-		$this->util = $util;
73
-		$this->mountManager = $mountManager;
74
-		$this->encryptionManager = $encryptionManager;
75
-		$this->file = $file;
76
-		$this->uid = $uid;
77
-	}
78
-
79
-	/**
80
-	 * hook after file was shared
81
-	 *
82
-	 * @param array $params
83
-	 */
84
-	public function postShared($params) {
85
-		if ($this->encryptionManager->isEnabled()) {
86
-			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
87
-				$path = Filesystem::getPath($params['fileSource']);
88
-				list($owner, $ownerPath) = $this->getOwnerPath($path);
89
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
90
-				$this->update($absPath);
91
-			}
92
-		}
93
-	}
94
-
95
-	/**
96
-	 * hook after file was unshared
97
-	 *
98
-	 * @param array $params
99
-	 */
100
-	public function postUnshared($params) {
101
-		if ($this->encryptionManager->isEnabled()) {
102
-			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
103
-				$path = Filesystem::getPath($params['fileSource']);
104
-				list($owner, $ownerPath) = $this->getOwnerPath($path);
105
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
106
-				$this->update($absPath);
107
-			}
108
-		}
109
-	}
110
-
111
-	/**
112
-	 * inform encryption module that a file was restored from the trash bin,
113
-	 * e.g. to update the encryption keys
114
-	 *
115
-	 * @param array $params
116
-	 */
117
-	public function postRestore($params) {
118
-		if ($this->encryptionManager->isEnabled()) {
119
-			$path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
120
-			$this->update($path);
121
-		}
122
-	}
123
-
124
-	/**
125
-	 * inform encryption module that a file was renamed,
126
-	 * e.g. to update the encryption keys
127
-	 *
128
-	 * @param array $params
129
-	 */
130
-	public function postRename($params) {
131
-		$source = $params['oldpath'];
132
-		$target = $params['newpath'];
133
-		if (
134
-			$this->encryptionManager->isEnabled() &&
135
-			dirname($source) !== dirname($target)
136
-		) {
137
-			list($owner, $ownerPath) = $this->getOwnerPath($target);
138
-			$absPath = '/' . $owner . '/files/' . $ownerPath;
139
-			$this->update($absPath);
140
-		}
141
-	}
142
-
143
-	/**
144
-	 * get owner and path relative to data/<owner>/files
145
-	 *
146
-	 * @param string $path path to file for current user
147
-	 * @return array ['owner' => $owner, 'path' => $path]
148
-	 * @throw \InvalidArgumentException
149
-	 */
150
-	protected function getOwnerPath($path) {
151
-		$info = Filesystem::getFileInfo($path);
152
-		$owner = Filesystem::getOwner($path);
153
-		$view = new View('/' . $owner . '/files');
154
-		$path = $view->getPath($info->getId());
155
-		if ($path === null) {
156
-			throw new \InvalidArgumentException('No file found for ' . $info->getId());
157
-		}
158
-
159
-		return [$owner, $path];
160
-	}
161
-
162
-	/**
163
-	 * notify encryption module about added/removed users from a file/folder
164
-	 *
165
-	 * @param string $path relative to data/
166
-	 * @throws Exceptions\ModuleDoesNotExistsException
167
-	 */
168
-	public function update($path) {
169
-		$encryptionModule = $this->encryptionManager->getEncryptionModule();
170
-
171
-		// if the encryption module doesn't encrypt the files on a per-user basis
172
-		// we have nothing to do here.
173
-		if ($encryptionModule->needDetailedAccessList() === false) {
174
-			return;
175
-		}
176
-
177
-		// if a folder was shared, get a list of all (sub-)folders
178
-		if ($this->view->is_dir($path)) {
179
-			$allFiles = $this->util->getAllFiles($path);
180
-		} else {
181
-			$allFiles = [$path];
182
-		}
183
-
184
-
185
-
186
-		foreach ($allFiles as $file) {
187
-			$usersSharing = $this->file->getAccessList($file);
188
-			$encryptionModule->update($file, $this->uid, $usersSharing);
189
-		}
190
-	}
36
+    /** @var \OC\Files\View */
37
+    protected $view;
38
+
39
+    /** @var \OC\Encryption\Util */
40
+    protected $util;
41
+
42
+    /** @var \OC\Files\Mount\Manager */
43
+    protected $mountManager;
44
+
45
+    /** @var \OC\Encryption\Manager */
46
+    protected $encryptionManager;
47
+
48
+    /** @var string */
49
+    protected $uid;
50
+
51
+    /** @var \OC\Encryption\File */
52
+    protected $file;
53
+
54
+    /**
55
+     *
56
+     * @param \OC\Files\View $view
57
+     * @param \OC\Encryption\Util $util
58
+     * @param \OC\Files\Mount\Manager $mountManager
59
+     * @param \OC\Encryption\Manager $encryptionManager
60
+     * @param \OC\Encryption\File $file
61
+     * @param string $uid
62
+     */
63
+    public function __construct(
64
+            View $view,
65
+            Util $util,
66
+            Mount\Manager $mountManager,
67
+            Manager $encryptionManager,
68
+            File $file,
69
+            $uid
70
+        ) {
71
+        $this->view = $view;
72
+        $this->util = $util;
73
+        $this->mountManager = $mountManager;
74
+        $this->encryptionManager = $encryptionManager;
75
+        $this->file = $file;
76
+        $this->uid = $uid;
77
+    }
78
+
79
+    /**
80
+     * hook after file was shared
81
+     *
82
+     * @param array $params
83
+     */
84
+    public function postShared($params) {
85
+        if ($this->encryptionManager->isEnabled()) {
86
+            if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
87
+                $path = Filesystem::getPath($params['fileSource']);
88
+                list($owner, $ownerPath) = $this->getOwnerPath($path);
89
+                $absPath = '/' . $owner . '/files/' . $ownerPath;
90
+                $this->update($absPath);
91
+            }
92
+        }
93
+    }
94
+
95
+    /**
96
+     * hook after file was unshared
97
+     *
98
+     * @param array $params
99
+     */
100
+    public function postUnshared($params) {
101
+        if ($this->encryptionManager->isEnabled()) {
102
+            if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
103
+                $path = Filesystem::getPath($params['fileSource']);
104
+                list($owner, $ownerPath) = $this->getOwnerPath($path);
105
+                $absPath = '/' . $owner . '/files/' . $ownerPath;
106
+                $this->update($absPath);
107
+            }
108
+        }
109
+    }
110
+
111
+    /**
112
+     * inform encryption module that a file was restored from the trash bin,
113
+     * e.g. to update the encryption keys
114
+     *
115
+     * @param array $params
116
+     */
117
+    public function postRestore($params) {
118
+        if ($this->encryptionManager->isEnabled()) {
119
+            $path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
120
+            $this->update($path);
121
+        }
122
+    }
123
+
124
+    /**
125
+     * inform encryption module that a file was renamed,
126
+     * e.g. to update the encryption keys
127
+     *
128
+     * @param array $params
129
+     */
130
+    public function postRename($params) {
131
+        $source = $params['oldpath'];
132
+        $target = $params['newpath'];
133
+        if (
134
+            $this->encryptionManager->isEnabled() &&
135
+            dirname($source) !== dirname($target)
136
+        ) {
137
+            list($owner, $ownerPath) = $this->getOwnerPath($target);
138
+            $absPath = '/' . $owner . '/files/' . $ownerPath;
139
+            $this->update($absPath);
140
+        }
141
+    }
142
+
143
+    /**
144
+     * get owner and path relative to data/<owner>/files
145
+     *
146
+     * @param string $path path to file for current user
147
+     * @return array ['owner' => $owner, 'path' => $path]
148
+     * @throw \InvalidArgumentException
149
+     */
150
+    protected function getOwnerPath($path) {
151
+        $info = Filesystem::getFileInfo($path);
152
+        $owner = Filesystem::getOwner($path);
153
+        $view = new View('/' . $owner . '/files');
154
+        $path = $view->getPath($info->getId());
155
+        if ($path === null) {
156
+            throw new \InvalidArgumentException('No file found for ' . $info->getId());
157
+        }
158
+
159
+        return [$owner, $path];
160
+    }
161
+
162
+    /**
163
+     * notify encryption module about added/removed users from a file/folder
164
+     *
165
+     * @param string $path relative to data/
166
+     * @throws Exceptions\ModuleDoesNotExistsException
167
+     */
168
+    public function update($path) {
169
+        $encryptionModule = $this->encryptionManager->getEncryptionModule();
170
+
171
+        // if the encryption module doesn't encrypt the files on a per-user basis
172
+        // we have nothing to do here.
173
+        if ($encryptionModule->needDetailedAccessList() === false) {
174
+            return;
175
+        }
176
+
177
+        // if a folder was shared, get a list of all (sub-)folders
178
+        if ($this->view->is_dir($path)) {
179
+            $allFiles = $this->util->getAllFiles($path);
180
+        } else {
181
+            $allFiles = [$path];
182
+        }
183
+
184
+
185
+
186
+        foreach ($allFiles as $file) {
187
+            $usersSharing = $this->file->getAccessList($file);
188
+            $encryptionModule->update($file, $this->uid, $usersSharing);
189
+        }
190
+    }
191 191
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
87 87
 				$path = Filesystem::getPath($params['fileSource']);
88 88
 				list($owner, $ownerPath) = $this->getOwnerPath($path);
89
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
89
+				$absPath = '/'.$owner.'/files/'.$ownerPath;
90 90
 				$this->update($absPath);
91 91
 			}
92 92
 		}
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
103 103
 				$path = Filesystem::getPath($params['fileSource']);
104 104
 				list($owner, $ownerPath) = $this->getOwnerPath($path);
105
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
105
+				$absPath = '/'.$owner.'/files/'.$ownerPath;
106 106
 				$this->update($absPath);
107 107
 			}
108 108
 		}
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 */
117 117
 	public function postRestore($params) {
118 118
 		if ($this->encryptionManager->isEnabled()) {
119
-			$path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
119
+			$path = Filesystem::normalizePath('/'.$this->uid.'/files/'.$params['filePath']);
120 120
 			$this->update($path);
121 121
 		}
122 122
 	}
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 			dirname($source) !== dirname($target)
136 136
 		) {
137 137
 			list($owner, $ownerPath) = $this->getOwnerPath($target);
138
-			$absPath = '/' . $owner . '/files/' . $ownerPath;
138
+			$absPath = '/'.$owner.'/files/'.$ownerPath;
139 139
 			$this->update($absPath);
140 140
 		}
141 141
 	}
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
 	protected function getOwnerPath($path) {
151 151
 		$info = Filesystem::getFileInfo($path);
152 152
 		$owner = Filesystem::getOwner($path);
153
-		$view = new View('/' . $owner . '/files');
153
+		$view = new View('/'.$owner.'/files');
154 154
 		$path = $view->getPath($info->getId());
155 155
 		if ($path === null) {
156
-			throw new \InvalidArgumentException('No file found for ' . $info->getId());
156
+			throw new \InvalidArgumentException('No file found for '.$info->getId());
157 157
 		}
158 158
 
159 159
 		return [$owner, $path];
Please login to merge, or discard this patch.
lib/private/TempManager.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
68 68
 		if ($postFix !== '') {
69
-			$postFix = '.' . ltrim($postFix, '.');
69
+			$postFix = '.'.ltrim($postFix, '.');
70 70
 			$postFix = str_replace(['\\', '/'], '', $postFix);
71 71
 			$absolutePath .= '-';
72 72
 		}
73 73
 
74
-		return $absolutePath . $postFix;
74
+		return $absolutePath.$postFix;
75 75
 	}
76 76
 
77 77
 	/**
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
 			$this->current[] = $uniqueFileName;
128 128
 
129 129
 			// Build a name without postfix
130
-			$path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
130
+			$path = $this->buildFileNameWithSuffix($uniqueFileName.'-folder', $postFix);
131 131
 			mkdir($path, 0700);
132 132
 			$this->current[] = $path;
133 133
 
134
-			return $path . '/';
134
+			return $path.'/';
135 135
 		} else {
136 136
 			$this->log->warning(
137 137
 				'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		if ($dh) {
191 191
 			while (($file = readdir($dh)) !== false) {
192 192
 				if (substr($file, 0, 7) === self::TMP_PREFIX) {
193
-					$path = $this->tmpBaseDir . '/' . $file;
193
+					$path = $this->tmpBaseDir.'/'.$file;
194 194
 					$mtime = filemtime($path);
195 195
 					if ($mtime < $cutOfTime) {
196 196
 						$files[] = $path;
Please login to merge, or discard this patch.
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -37,244 +37,244 @@
 block discarded – undo
37 37
 use Psr\Log\LoggerInterface;
38 38
 
39 39
 class TempManager implements ITempManager {
40
-	/** @var string[] Current temporary files and folders, used for cleanup */
41
-	protected $current = [];
42
-	/** @var string i.e. /tmp on linux systems */
43
-	protected $tmpBaseDir;
44
-	/** @var LoggerInterface */
45
-	protected $log;
46
-	/** @var IConfig */
47
-	protected $config;
48
-	/** @var IniGetWrapper */
49
-	protected $iniGetWrapper;
40
+    /** @var string[] Current temporary files and folders, used for cleanup */
41
+    protected $current = [];
42
+    /** @var string i.e. /tmp on linux systems */
43
+    protected $tmpBaseDir;
44
+    /** @var LoggerInterface */
45
+    protected $log;
46
+    /** @var IConfig */
47
+    protected $config;
48
+    /** @var IniGetWrapper */
49
+    protected $iniGetWrapper;
50 50
 
51
-	/** Prefix */
52
-	public const TMP_PREFIX = 'oc_tmp_';
51
+    /** Prefix */
52
+    public const TMP_PREFIX = 'oc_tmp_';
53 53
 
54
-	public function __construct(LoggerInterface $logger, IConfig $config, IniGetWrapper $iniGetWrapper) {
55
-		$this->log = $logger;
56
-		$this->config = $config;
57
-		$this->iniGetWrapper = $iniGetWrapper;
58
-		$this->tmpBaseDir = $this->getTempBaseDir();
59
-	}
54
+    public function __construct(LoggerInterface $logger, IConfig $config, IniGetWrapper $iniGetWrapper) {
55
+        $this->log = $logger;
56
+        $this->config = $config;
57
+        $this->iniGetWrapper = $iniGetWrapper;
58
+        $this->tmpBaseDir = $this->getTempBaseDir();
59
+    }
60 60
 
61
-	/**
62
-	 * Builds the filename with suffix and removes potential dangerous characters
63
-	 * such as directory separators.
64
-	 *
65
-	 * @param string $absolutePath Absolute path to the file / folder
66
-	 * @param string $postFix Postfix appended to the temporary file name, may be user controlled
67
-	 * @return string
68
-	 */
69
-	private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
70
-		if ($postFix !== '') {
71
-			$postFix = '.' . ltrim($postFix, '.');
72
-			$postFix = str_replace(['\\', '/'], '', $postFix);
73
-			$absolutePath .= '-';
74
-		}
61
+    /**
62
+     * Builds the filename with suffix and removes potential dangerous characters
63
+     * such as directory separators.
64
+     *
65
+     * @param string $absolutePath Absolute path to the file / folder
66
+     * @param string $postFix Postfix appended to the temporary file name, may be user controlled
67
+     * @return string
68
+     */
69
+    private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
70
+        if ($postFix !== '') {
71
+            $postFix = '.' . ltrim($postFix, '.');
72
+            $postFix = str_replace(['\\', '/'], '', $postFix);
73
+            $absolutePath .= '-';
74
+        }
75 75
 
76
-		return $absolutePath . $postFix;
77
-	}
76
+        return $absolutePath . $postFix;
77
+    }
78 78
 
79
-	/**
80
-	 * Create a temporary file and return the path
81
-	 *
82
-	 * @param string $postFix Postfix appended to the temporary file name
83
-	 * @return string
84
-	 */
85
-	public function getTemporaryFile($postFix = '') {
86
-		if (is_writable($this->tmpBaseDir)) {
87
-			// To create an unique file and prevent the risk of race conditions
88
-			// or duplicated temporary files by other means such as collisions
89
-			// we need to create the file using `tempnam` and append a possible
90
-			// postfix to it later
91
-			$file = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
92
-			$this->current[] = $file;
79
+    /**
80
+     * Create a temporary file and return the path
81
+     *
82
+     * @param string $postFix Postfix appended to the temporary file name
83
+     * @return string
84
+     */
85
+    public function getTemporaryFile($postFix = '') {
86
+        if (is_writable($this->tmpBaseDir)) {
87
+            // To create an unique file and prevent the risk of race conditions
88
+            // or duplicated temporary files by other means such as collisions
89
+            // we need to create the file using `tempnam` and append a possible
90
+            // postfix to it later
91
+            $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
92
+            $this->current[] = $file;
93 93
 
94
-			// If a postfix got specified sanitize it and create a postfixed
95
-			// temporary file
96
-			if ($postFix !== '') {
97
-				$fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix);
98
-				touch($fileNameWithPostfix);
99
-				chmod($fileNameWithPostfix, 0600);
100
-				$this->current[] = $fileNameWithPostfix;
101
-				return $fileNameWithPostfix;
102
-			}
94
+            // If a postfix got specified sanitize it and create a postfixed
95
+            // temporary file
96
+            if ($postFix !== '') {
97
+                $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix);
98
+                touch($fileNameWithPostfix);
99
+                chmod($fileNameWithPostfix, 0600);
100
+                $this->current[] = $fileNameWithPostfix;
101
+                return $fileNameWithPostfix;
102
+            }
103 103
 
104
-			return $file;
105
-		} else {
106
-			$this->log->warning(
107
-				'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions',
108
-				[
109
-					'dir' => $this->tmpBaseDir,
110
-				]
111
-			);
112
-			return false;
113
-		}
114
-	}
104
+            return $file;
105
+        } else {
106
+            $this->log->warning(
107
+                'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions',
108
+                [
109
+                    'dir' => $this->tmpBaseDir,
110
+                ]
111
+            );
112
+            return false;
113
+        }
114
+    }
115 115
 
116
-	/**
117
-	 * Create a temporary folder and return the path
118
-	 *
119
-	 * @param string $postFix Postfix appended to the temporary folder name
120
-	 * @return string
121
-	 */
122
-	public function getTemporaryFolder($postFix = '') {
123
-		if (is_writable($this->tmpBaseDir)) {
124
-			// To create an unique directory and prevent the risk of race conditions
125
-			// or duplicated temporary files by other means such as collisions
126
-			// we need to create the file using `tempnam` and append a possible
127
-			// postfix to it later
128
-			$uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
129
-			$this->current[] = $uniqueFileName;
116
+    /**
117
+     * Create a temporary folder and return the path
118
+     *
119
+     * @param string $postFix Postfix appended to the temporary folder name
120
+     * @return string
121
+     */
122
+    public function getTemporaryFolder($postFix = '') {
123
+        if (is_writable($this->tmpBaseDir)) {
124
+            // To create an unique directory and prevent the risk of race conditions
125
+            // or duplicated temporary files by other means such as collisions
126
+            // we need to create the file using `tempnam` and append a possible
127
+            // postfix to it later
128
+            $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
129
+            $this->current[] = $uniqueFileName;
130 130
 
131
-			// Build a name without postfix
132
-			$path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
133
-			mkdir($path, 0700);
134
-			$this->current[] = $path;
131
+            // Build a name without postfix
132
+            $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
133
+            mkdir($path, 0700);
134
+            $this->current[] = $path;
135 135
 
136
-			return $path . '/';
137
-		} else {
138
-			$this->log->warning(
139
-				'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
140
-				[
141
-					'dir' => $this->tmpBaseDir,
142
-				]
143
-			);
144
-			return false;
145
-		}
146
-	}
136
+            return $path . '/';
137
+        } else {
138
+            $this->log->warning(
139
+                'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
140
+                [
141
+                    'dir' => $this->tmpBaseDir,
142
+                ]
143
+            );
144
+            return false;
145
+        }
146
+    }
147 147
 
148
-	/**
149
-	 * Remove the temporary files and folders generated during this request
150
-	 */
151
-	public function clean() {
152
-		$this->cleanFiles($this->current);
153
-	}
148
+    /**
149
+     * Remove the temporary files and folders generated during this request
150
+     */
151
+    public function clean() {
152
+        $this->cleanFiles($this->current);
153
+    }
154 154
 
155
-	/**
156
-	 * @param string[] $files
157
-	 */
158
-	protected function cleanFiles($files) {
159
-		foreach ($files as $file) {
160
-			if (file_exists($file)) {
161
-				try {
162
-					\OC_Helper::rmdirr($file);
163
-				} catch (\UnexpectedValueException $ex) {
164
-					$this->log->warning(
165
-						"Error deleting temporary file/folder: {file} - Reason: {error}",
166
-						[
167
-							'file' => $file,
168
-							'error' => $ex->getMessage(),
169
-						]
170
-					);
171
-				}
172
-			}
173
-		}
174
-	}
155
+    /**
156
+     * @param string[] $files
157
+     */
158
+    protected function cleanFiles($files) {
159
+        foreach ($files as $file) {
160
+            if (file_exists($file)) {
161
+                try {
162
+                    \OC_Helper::rmdirr($file);
163
+                } catch (\UnexpectedValueException $ex) {
164
+                    $this->log->warning(
165
+                        "Error deleting temporary file/folder: {file} - Reason: {error}",
166
+                        [
167
+                            'file' => $file,
168
+                            'error' => $ex->getMessage(),
169
+                        ]
170
+                    );
171
+                }
172
+            }
173
+        }
174
+    }
175 175
 
176
-	/**
177
-	 * Remove old temporary files and folders that were failed to be cleaned
178
-	 */
179
-	public function cleanOld() {
180
-		$this->cleanFiles($this->getOldFiles());
181
-	}
176
+    /**
177
+     * Remove old temporary files and folders that were failed to be cleaned
178
+     */
179
+    public function cleanOld() {
180
+        $this->cleanFiles($this->getOldFiles());
181
+    }
182 182
 
183
-	/**
184
-	 * Get all temporary files and folders generated by oc older than an hour
185
-	 *
186
-	 * @return string[]
187
-	 */
188
-	protected function getOldFiles() {
189
-		$cutOfTime = time() - 3600;
190
-		$files = [];
191
-		$dh = opendir($this->tmpBaseDir);
192
-		if ($dh) {
193
-			while (($file = readdir($dh)) !== false) {
194
-				if (substr($file, 0, 7) === self::TMP_PREFIX) {
195
-					$path = $this->tmpBaseDir . '/' . $file;
196
-					$mtime = filemtime($path);
197
-					if ($mtime < $cutOfTime) {
198
-						$files[] = $path;
199
-					}
200
-				}
201
-			}
202
-		}
203
-		return $files;
204
-	}
183
+    /**
184
+     * Get all temporary files and folders generated by oc older than an hour
185
+     *
186
+     * @return string[]
187
+     */
188
+    protected function getOldFiles() {
189
+        $cutOfTime = time() - 3600;
190
+        $files = [];
191
+        $dh = opendir($this->tmpBaseDir);
192
+        if ($dh) {
193
+            while (($file = readdir($dh)) !== false) {
194
+                if (substr($file, 0, 7) === self::TMP_PREFIX) {
195
+                    $path = $this->tmpBaseDir . '/' . $file;
196
+                    $mtime = filemtime($path);
197
+                    if ($mtime < $cutOfTime) {
198
+                        $files[] = $path;
199
+                    }
200
+                }
201
+            }
202
+        }
203
+        return $files;
204
+    }
205 205
 
206
-	/**
207
-	 * Get the temporary base directory configured on the server
208
-	 *
209
-	 * @return string Path to the temporary directory or null
210
-	 * @throws \UnexpectedValueException
211
-	 */
212
-	public function getTempBaseDir() {
213
-		if ($this->tmpBaseDir) {
214
-			return $this->tmpBaseDir;
215
-		}
206
+    /**
207
+     * Get the temporary base directory configured on the server
208
+     *
209
+     * @return string Path to the temporary directory or null
210
+     * @throws \UnexpectedValueException
211
+     */
212
+    public function getTempBaseDir() {
213
+        if ($this->tmpBaseDir) {
214
+            return $this->tmpBaseDir;
215
+        }
216 216
 
217
-		$directories = [];
218
-		if ($temp = $this->config->getSystemValue('tempdirectory', null)) {
219
-			$directories[] = $temp;
220
-		}
221
-		if ($temp = $this->iniGetWrapper->get('upload_tmp_dir')) {
222
-			$directories[] = $temp;
223
-		}
224
-		if ($temp = getenv('TMP')) {
225
-			$directories[] = $temp;
226
-		}
227
-		if ($temp = getenv('TEMP')) {
228
-			$directories[] = $temp;
229
-		}
230
-		if ($temp = getenv('TMPDIR')) {
231
-			$directories[] = $temp;
232
-		}
233
-		if ($temp = sys_get_temp_dir()) {
234
-			$directories[] = $temp;
235
-		}
217
+        $directories = [];
218
+        if ($temp = $this->config->getSystemValue('tempdirectory', null)) {
219
+            $directories[] = $temp;
220
+        }
221
+        if ($temp = $this->iniGetWrapper->get('upload_tmp_dir')) {
222
+            $directories[] = $temp;
223
+        }
224
+        if ($temp = getenv('TMP')) {
225
+            $directories[] = $temp;
226
+        }
227
+        if ($temp = getenv('TEMP')) {
228
+            $directories[] = $temp;
229
+        }
230
+        if ($temp = getenv('TMPDIR')) {
231
+            $directories[] = $temp;
232
+        }
233
+        if ($temp = sys_get_temp_dir()) {
234
+            $directories[] = $temp;
235
+        }
236 236
 
237
-		foreach ($directories as $dir) {
238
-			if ($this->checkTemporaryDirectory($dir)) {
239
-				return $dir;
240
-			}
241
-		}
237
+        foreach ($directories as $dir) {
238
+            if ($this->checkTemporaryDirectory($dir)) {
239
+                return $dir;
240
+            }
241
+        }
242 242
 
243
-		$temp = tempnam(dirname(__FILE__), '');
244
-		if (file_exists($temp)) {
245
-			unlink($temp);
246
-			return dirname($temp);
247
-		}
248
-		throw new \UnexpectedValueException('Unable to detect system temporary directory');
249
-	}
243
+        $temp = tempnam(dirname(__FILE__), '');
244
+        if (file_exists($temp)) {
245
+            unlink($temp);
246
+            return dirname($temp);
247
+        }
248
+        throw new \UnexpectedValueException('Unable to detect system temporary directory');
249
+    }
250 250
 
251
-	/**
252
-	 * Check if a temporary directory is ready for use
253
-	 *
254
-	 * @param mixed $directory
255
-	 * @return bool
256
-	 */
257
-	private function checkTemporaryDirectory($directory) {
258
-		// suppress any possible errors caused by is_writable
259
-		// checks missing or invalid path or characters, wrong permissions etc
260
-		try {
261
-			if (is_writable($directory)) {
262
-				return true;
263
-			}
264
-		} catch (\Exception $e) {
265
-		}
266
-		$this->log->warning('Temporary directory {dir} is not present or writable',
267
-			['dir' => $directory]
268
-		);
269
-		return false;
270
-	}
251
+    /**
252
+     * Check if a temporary directory is ready for use
253
+     *
254
+     * @param mixed $directory
255
+     * @return bool
256
+     */
257
+    private function checkTemporaryDirectory($directory) {
258
+        // suppress any possible errors caused by is_writable
259
+        // checks missing or invalid path or characters, wrong permissions etc
260
+        try {
261
+            if (is_writable($directory)) {
262
+                return true;
263
+            }
264
+        } catch (\Exception $e) {
265
+        }
266
+        $this->log->warning('Temporary directory {dir} is not present or writable',
267
+            ['dir' => $directory]
268
+        );
269
+        return false;
270
+    }
271 271
 
272
-	/**
273
-	 * Override the temporary base directory
274
-	 *
275
-	 * @param string $directory
276
-	 */
277
-	public function overrideTempBaseDir($directory) {
278
-		$this->tmpBaseDir = $directory;
279
-	}
272
+    /**
273
+     * Override the temporary base directory
274
+     *
275
+     * @param string $directory
276
+     */
277
+    public function overrideTempBaseDir($directory) {
278
+        $this->tmpBaseDir = $directory;
279
+    }
280 280
 }
Please login to merge, or discard this patch.
lib/private/Tagging/Tag.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -36,54 +36,54 @@
 block discarded – undo
36 36
  * @method void setName(string $name)
37 37
  */
38 38
 class Tag extends Entity {
39
-	protected $owner;
40
-	protected $type;
41
-	protected $name;
39
+    protected $owner;
40
+    protected $type;
41
+    protected $name;
42 42
 
43
-	/**
44
-	 * Constructor.
45
-	 *
46
-	 * @param string $owner The tag's owner
47
-	 * @param string $type The type of item this tag is used for
48
-	 * @param string $name The tag's name
49
-	 */
50
-	public function __construct($owner = null, $type = null, $name = null) {
51
-		$this->setOwner($owner);
52
-		$this->setType($type);
53
-		$this->setName($name);
54
-	}
43
+    /**
44
+     * Constructor.
45
+     *
46
+     * @param string $owner The tag's owner
47
+     * @param string $type The type of item this tag is used for
48
+     * @param string $name The tag's name
49
+     */
50
+    public function __construct($owner = null, $type = null, $name = null) {
51
+        $this->setOwner($owner);
52
+        $this->setType($type);
53
+        $this->setName($name);
54
+    }
55 55
 
56
-	/**
57
-	 * Transform a database columnname to a property
58
-	 *
59
-	 * @param string $columnName the name of the column
60
-	 * @return string the property name
61
-	 * @todo migrate existing database columns to the correct names
62
-	 * to be able to drop this direct mapping
63
-	 */
64
-	public function columnToProperty($columnName) {
65
-		if ($columnName === 'category') {
66
-			return 'name';
67
-		} elseif ($columnName === 'uid') {
68
-			return 'owner';
69
-		} else {
70
-			return parent::columnToProperty($columnName);
71
-		}
72
-	}
56
+    /**
57
+     * Transform a database columnname to a property
58
+     *
59
+     * @param string $columnName the name of the column
60
+     * @return string the property name
61
+     * @todo migrate existing database columns to the correct names
62
+     * to be able to drop this direct mapping
63
+     */
64
+    public function columnToProperty($columnName) {
65
+        if ($columnName === 'category') {
66
+            return 'name';
67
+        } elseif ($columnName === 'uid') {
68
+            return 'owner';
69
+        } else {
70
+            return parent::columnToProperty($columnName);
71
+        }
72
+    }
73 73
 
74
-	/**
75
-	 * Transform a property to a database column name
76
-	 *
77
-	 * @param string $property the name of the property
78
-	 * @return string the column name
79
-	 */
80
-	public function propertyToColumn($property) {
81
-		if ($property === 'name') {
82
-			return 'category';
83
-		} elseif ($property === 'owner') {
84
-			return 'uid';
85
-		} else {
86
-			return parent::propertyToColumn($property);
87
-		}
88
-	}
74
+    /**
75
+     * Transform a property to a database column name
76
+     *
77
+     * @param string $property the name of the property
78
+     * @return string the column name
79
+     */
80
+    public function propertyToColumn($property) {
81
+        if ($property === 'name') {
82
+            return 'category';
83
+        } elseif ($property === 'owner') {
84
+            return 'uid';
85
+        } else {
86
+            return parent::propertyToColumn($property);
87
+        }
88
+    }
89 89
 }
Please login to merge, or discard this patch.
lib/private/Tagging/TagMapper.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 			$owners = [$owners];
55 55
 		}
56 56
 
57
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
58
-			. 'WHERE `uid` IN (' . str_repeat('?,', count($owners) - 1) . '?) AND `type` = ? ORDER BY `category`';
57
+		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` '
58
+			. 'WHERE `uid` IN ('.str_repeat('?,', count($owners) - 1).'?) AND `type` = ? ORDER BY `category`';
59 59
 		return $this->findEntities($sql, array_merge($owners, [$type]));
60 60
 	}
61 61
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @return bool
67 67
 	 */
68 68
 	public function tagExists($tag) {
69
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
69
+		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` '
70 70
 			. 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
71 71
 		try {
72 72
 			$this->findEntity($sql, [$tag->getOwner(), $tag->getType(), $tag->getName()]);
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -35,46 +35,46 @@
 block discarded – undo
35 35
  */
36 36
 class TagMapper extends Mapper {
37 37
 
38
-	/**
39
-	 * Constructor.
40
-	 *
41
-	 * @param IDBConnection $db Instance of the Db abstraction layer.
42
-	 */
43
-	public function __construct(IDBConnection $db) {
44
-		parent::__construct($db, 'vcategory', Tag::class);
45
-	}
38
+    /**
39
+     * Constructor.
40
+     *
41
+     * @param IDBConnection $db Instance of the Db abstraction layer.
42
+     */
43
+    public function __construct(IDBConnection $db) {
44
+        parent::__construct($db, 'vcategory', Tag::class);
45
+    }
46 46
 
47
-	/**
48
-	 * Load tags from the database.
49
-	 *
50
-	 * @param array|string $owners The user(s) whose tags we are going to load.
51
-	 * @param string $type The type of item for which we are loading tags.
52
-	 * @return array An array of Tag objects.
53
-	 */
54
-	public function loadTags($owners, $type) {
55
-		if (!is_array($owners)) {
56
-			$owners = [$owners];
57
-		}
47
+    /**
48
+     * Load tags from the database.
49
+     *
50
+     * @param array|string $owners The user(s) whose tags we are going to load.
51
+     * @param string $type The type of item for which we are loading tags.
52
+     * @return array An array of Tag objects.
53
+     */
54
+    public function loadTags($owners, $type) {
55
+        if (!is_array($owners)) {
56
+            $owners = [$owners];
57
+        }
58 58
 
59
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
60
-			. 'WHERE `uid` IN (' . str_repeat('?,', count($owners) - 1) . '?) AND `type` = ? ORDER BY `category`';
61
-		return $this->findEntities($sql, array_merge($owners, [$type]));
62
-	}
59
+        $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
60
+            . 'WHERE `uid` IN (' . str_repeat('?,', count($owners) - 1) . '?) AND `type` = ? ORDER BY `category`';
61
+        return $this->findEntities($sql, array_merge($owners, [$type]));
62
+    }
63 63
 
64
-	/**
65
-	 * Check if a given Tag object already exists in the database.
66
-	 *
67
-	 * @param Tag $tag The tag to look for in the database.
68
-	 * @return bool
69
-	 */
70
-	public function tagExists($tag) {
71
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
72
-			. 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
73
-		try {
74
-			$this->findEntity($sql, [$tag->getOwner(), $tag->getType(), $tag->getName()]);
75
-		} catch (DoesNotExistException $e) {
76
-			return false;
77
-		}
78
-		return true;
79
-	}
64
+    /**
65
+     * Check if a given Tag object already exists in the database.
66
+     *
67
+     * @param Tag $tag The tag to look for in the database.
68
+     * @return bool
69
+     */
70
+    public function tagExists($tag) {
71
+        $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
72
+            . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
73
+        try {
74
+            $this->findEntity($sql, [$tag->getOwner(), $tag->getType(), $tag->getName()]);
75
+        } catch (DoesNotExistException $e) {
76
+            return false;
77
+        }
78
+        return true;
79
+    }
80 80
 }
Please login to merge, or discard this patch.
Middleware/Security/Exceptions/StrictCookieMissingException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
  * @package OC\AppFramework\Middleware\Security\Exceptions
33 33
  */
34 34
 class StrictCookieMissingException extends SecurityException {
35
-	public function __construct() {
36
-		parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED);
37
-	}
35
+    public function __construct() {
36
+        parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED);
37
+    }
38 38
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/OCS/V1Response.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -27,52 +27,52 @@
 block discarded – undo
27 27
 
28 28
 class V1Response extends BaseResponse {
29 29
 
30
-	/**
31
-	 * The V1 endpoint has very limited http status codes basically everything
32
-	 * is status 200 except 401
33
-	 *
34
-	 * @return int
35
-	 */
36
-	public function getStatus() {
37
-		$status = parent::getStatus();
38
-		if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) {
39
-			return Http::STATUS_UNAUTHORIZED;
40
-		}
30
+    /**
31
+     * The V1 endpoint has very limited http status codes basically everything
32
+     * is status 200 except 401
33
+     *
34
+     * @return int
35
+     */
36
+    public function getStatus() {
37
+        $status = parent::getStatus();
38
+        if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) {
39
+            return Http::STATUS_UNAUTHORIZED;
40
+        }
41 41
 
42
-		return Http::STATUS_OK;
43
-	}
42
+        return Http::STATUS_OK;
43
+    }
44 44
 
45
-	/**
46
-	 * In v1 all OK is 100
47
-	 *
48
-	 * @return int
49
-	 */
50
-	public function getOCSStatus() {
51
-		$status = parent::getOCSStatus();
45
+    /**
46
+     * In v1 all OK is 100
47
+     *
48
+     * @return int
49
+     */
50
+    public function getOCSStatus() {
51
+        $status = parent::getOCSStatus();
52 52
 
53
-		if ($status === Http::STATUS_OK) {
54
-			return 100;
55
-		}
53
+        if ($status === Http::STATUS_OK) {
54
+            return 100;
55
+        }
56 56
 
57
-		return $status;
58
-	}
57
+        return $status;
58
+    }
59 59
 
60
-	/**
61
-	 * Construct the meta part of the response
62
-	 * And then late the base class render
63
-	 *
64
-	 * @return string
65
-	 */
66
-	public function render() {
67
-		$meta = [
68
-			'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure',
69
-			'statuscode' => $this->getOCSStatus(),
70
-			'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage,
71
-		];
60
+    /**
61
+     * Construct the meta part of the response
62
+     * And then late the base class render
63
+     *
64
+     * @return string
65
+     */
66
+    public function render() {
67
+        $meta = [
68
+            'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure',
69
+            'statuscode' => $this->getOCSStatus(),
70
+            'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage,
71
+        ];
72 72
 
73
-		$meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : '';
74
-		$meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: '';
73
+        $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : '';
74
+        $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: '';
75 75
 
76
-		return $this->renderResult($meta);
77
-	}
76
+        return $this->renderResult($meta);
77
+    }
78 78
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,8 +70,8 @@
 block discarded – undo
70 70
 			'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage,
71 71
 		];
72 72
 
73
-		$meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : '';
74
-		$meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: '';
73
+		$meta['totalitems'] = $this->itemsCount !== null ? (string) $this->itemsCount : '';
74
+		$meta['itemsperpage'] = $this->itemsPerPage !== null ? (string) $this->itemsPerPage : '';
75 75
 
76 76
 		return $this->renderResult($meta);
77 77
 	}
Please login to merge, or discard this patch.
lib/private/AppFramework/OCS/V2Response.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -27,49 +27,49 @@
 block discarded – undo
27 27
 
28 28
 class V2Response extends BaseResponse {
29 29
 
30
-	/**
31
-	 * The V2 endpoint just passes on status codes.
32
-	 * Of course we have to map the OCS specific codes to proper HTTP status codes
33
-	 *
34
-	 * @return int
35
-	 */
36
-	public function getStatus() {
37
-		$status = parent::getStatus();
38
-		if ($status === API::RESPOND_UNAUTHORISED) {
39
-			return Http::STATUS_UNAUTHORIZED;
40
-		} elseif ($status === API::RESPOND_NOT_FOUND) {
41
-			return Http::STATUS_NOT_FOUND;
42
-		} elseif ($status === API::RESPOND_SERVER_ERROR || $status === API::RESPOND_UNKNOWN_ERROR) {
43
-			return Http::STATUS_INTERNAL_SERVER_ERROR;
44
-		} elseif ($status < 200 || $status > 600) {
45
-			return Http::STATUS_BAD_REQUEST;
46
-		}
30
+    /**
31
+     * The V2 endpoint just passes on status codes.
32
+     * Of course we have to map the OCS specific codes to proper HTTP status codes
33
+     *
34
+     * @return int
35
+     */
36
+    public function getStatus() {
37
+        $status = parent::getStatus();
38
+        if ($status === API::RESPOND_UNAUTHORISED) {
39
+            return Http::STATUS_UNAUTHORIZED;
40
+        } elseif ($status === API::RESPOND_NOT_FOUND) {
41
+            return Http::STATUS_NOT_FOUND;
42
+        } elseif ($status === API::RESPOND_SERVER_ERROR || $status === API::RESPOND_UNKNOWN_ERROR) {
43
+            return Http::STATUS_INTERNAL_SERVER_ERROR;
44
+        } elseif ($status < 200 || $status > 600) {
45
+            return Http::STATUS_BAD_REQUEST;
46
+        }
47 47
 
48
-		return $status;
49
-	}
48
+        return $status;
49
+    }
50 50
 
51
-	/**
52
-	 * Construct the meta part of the response
53
-	 * And then late the base class render
54
-	 *
55
-	 * @return string
56
-	 */
57
-	public function render() {
58
-		$status = parent::getStatus();
51
+    /**
52
+     * Construct the meta part of the response
53
+     * And then late the base class render
54
+     *
55
+     * @return string
56
+     */
57
+    public function render() {
58
+        $status = parent::getStatus();
59 59
 
60
-		$meta = [
61
-			'status' => $status >= 200 && $status < 300 ? 'ok' : 'failure',
62
-			'statuscode' => $this->getOCSStatus(),
63
-			'message' => $status >= 200 && $status < 300 ? 'OK' : $this->statusMessage,
64
-		];
60
+        $meta = [
61
+            'status' => $status >= 200 && $status < 300 ? 'ok' : 'failure',
62
+            'statuscode' => $this->getOCSStatus(),
63
+            'message' => $status >= 200 && $status < 300 ? 'OK' : $this->statusMessage,
64
+        ];
65 65
 
66
-		if ($this->itemsCount !== null) {
67
-			$meta['totalitems'] = $this->itemsCount;
68
-		}
69
-		if ($this->itemsPerPage !== null) {
70
-			$meta['itemsperpage'] = $this->itemsPerPage;
71
-		}
66
+        if ($this->itemsCount !== null) {
67
+            $meta['totalitems'] = $this->itemsCount;
68
+        }
69
+        if ($this->itemsPerPage !== null) {
70
+            $meta['itemsperpage'] = $this->itemsPerPage;
71
+        }
72 72
 
73
-		return $this->renderResult($meta);
74
-	}
73
+        return $this->renderResult($meta);
74
+    }
75 75
 }
Please login to merge, or discard this patch.
apps/dav/lib/Comments/RootCollection.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@
 block discarded – undo
147 147
 		if (isset($this->entityTypeCollections[$name])) {
148 148
 			return $this->entityTypeCollections[$name];
149 149
 		}
150
-		throw new NotFound('Entity type "' . $name . '" not found."');
150
+		throw new NotFound('Entity type "'.$name.'" not found."');
151 151
 	}
152 152
 
153 153
 	/**
Please login to merge, or discard this patch.
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -37,176 +37,176 @@
 block discarded – undo
37 37
 
38 38
 class RootCollection implements ICollection {
39 39
 
40
-	/** @var EntityTypeCollection[]|null */
41
-	private $entityTypeCollections;
42
-
43
-	/** @var ICommentsManager */
44
-	protected $commentsManager;
45
-
46
-	/** @var string */
47
-	protected $name = 'comments';
48
-
49
-	/** @var ILogger */
50
-	protected $logger;
51
-
52
-	/** @var IUserManager */
53
-	protected $userManager;
54
-
55
-	/** @var IUserSession */
56
-	protected $userSession;
57
-
58
-	/** @var EventDispatcherInterface */
59
-	protected $dispatcher;
60
-
61
-	/**
62
-	 * @param ICommentsManager $commentsManager
63
-	 * @param IUserManager $userManager
64
-	 * @param IUserSession $userSession
65
-	 * @param EventDispatcherInterface $dispatcher
66
-	 * @param ILogger $logger
67
-	 */
68
-	public function __construct(
69
-		ICommentsManager $commentsManager,
70
-		IUserManager $userManager,
71
-		IUserSession $userSession,
72
-		EventDispatcherInterface $dispatcher,
73
-		ILogger $logger) {
74
-		$this->commentsManager = $commentsManager;
75
-		$this->logger = $logger;
76
-		$this->userManager = $userManager;
77
-		$this->userSession = $userSession;
78
-		$this->dispatcher = $dispatcher;
79
-	}
80
-
81
-	/**
82
-	 * initializes the collection. At this point of time, we need the logged in
83
-	 * user. Since it is not the case when the instance is created, we cannot
84
-	 * have this in the constructor.
85
-	 *
86
-	 * @throws NotAuthenticated
87
-	 */
88
-	protected function initCollections() {
89
-		if ($this->entityTypeCollections !== null) {
90
-			return;
91
-		}
92
-		$user = $this->userSession->getUser();
93
-		if (is_null($user)) {
94
-			throw new NotAuthenticated();
95
-		}
96
-
97
-		$event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY);
98
-		$this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
99
-
100
-		$this->entityTypeCollections = [];
101
-		foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
102
-			$this->entityTypeCollections[$entity] = new EntityTypeCollection(
103
-				$entity,
104
-				$this->commentsManager,
105
-				$this->userManager,
106
-				$this->userSession,
107
-				$this->logger,
108
-				$entityExistsFunction
109
-			);
110
-		}
111
-	}
112
-
113
-	/**
114
-	 * Creates a new file in the directory
115
-	 *
116
-	 * @param string $name Name of the file
117
-	 * @param resource|string $data Initial payload
118
-	 * @return null|string
119
-	 * @throws Forbidden
120
-	 */
121
-	public function createFile($name, $data = null) {
122
-		throw new Forbidden('Cannot create comments by id');
123
-	}
124
-
125
-	/**
126
-	 * Creates a new subdirectory
127
-	 *
128
-	 * @param string $name
129
-	 * @throws Forbidden
130
-	 */
131
-	public function createDirectory($name) {
132
-		throw new Forbidden('Permission denied to create collections');
133
-	}
134
-
135
-	/**
136
-	 * Returns a specific child node, referenced by its name
137
-	 *
138
-	 * This method must throw Sabre\DAV\Exception\NotFound if the node does not
139
-	 * exist.
140
-	 *
141
-	 * @param string $name
142
-	 * @return \Sabre\DAV\INode
143
-	 * @throws NotFound
144
-	 */
145
-	public function getChild($name) {
146
-		$this->initCollections();
147
-		if (isset($this->entityTypeCollections[$name])) {
148
-			return $this->entityTypeCollections[$name];
149
-		}
150
-		throw new NotFound('Entity type "' . $name . '" not found."');
151
-	}
152
-
153
-	/**
154
-	 * Returns an array with all the child nodes
155
-	 *
156
-	 * @return \Sabre\DAV\INode[]
157
-	 */
158
-	public function getChildren() {
159
-		$this->initCollections();
160
-		return $this->entityTypeCollections;
161
-	}
162
-
163
-	/**
164
-	 * Checks if a child-node with the specified name exists
165
-	 *
166
-	 * @param string $name
167
-	 * @return bool
168
-	 */
169
-	public function childExists($name) {
170
-		$this->initCollections();
171
-		return isset($this->entityTypeCollections[$name]);
172
-	}
173
-
174
-	/**
175
-	 * Deleted the current node
176
-	 *
177
-	 * @throws Forbidden
178
-	 */
179
-	public function delete() {
180
-		throw new Forbidden('Permission denied to delete this collection');
181
-	}
182
-
183
-	/**
184
-	 * Returns the name of the node.
185
-	 *
186
-	 * This is used to generate the url.
187
-	 *
188
-	 * @return string
189
-	 */
190
-	public function getName() {
191
-		return $this->name;
192
-	}
193
-
194
-	/**
195
-	 * Renames the node
196
-	 *
197
-	 * @param string $name The new name
198
-	 * @throws Forbidden
199
-	 */
200
-	public function setName($name) {
201
-		throw new Forbidden('Permission denied to rename this collection');
202
-	}
203
-
204
-	/**
205
-	 * Returns the last modification time, as a unix timestamp
206
-	 *
207
-	 * @return int
208
-	 */
209
-	public function getLastModified() {
210
-		return null;
211
-	}
40
+    /** @var EntityTypeCollection[]|null */
41
+    private $entityTypeCollections;
42
+
43
+    /** @var ICommentsManager */
44
+    protected $commentsManager;
45
+
46
+    /** @var string */
47
+    protected $name = 'comments';
48
+
49
+    /** @var ILogger */
50
+    protected $logger;
51
+
52
+    /** @var IUserManager */
53
+    protected $userManager;
54
+
55
+    /** @var IUserSession */
56
+    protected $userSession;
57
+
58
+    /** @var EventDispatcherInterface */
59
+    protected $dispatcher;
60
+
61
+    /**
62
+     * @param ICommentsManager $commentsManager
63
+     * @param IUserManager $userManager
64
+     * @param IUserSession $userSession
65
+     * @param EventDispatcherInterface $dispatcher
66
+     * @param ILogger $logger
67
+     */
68
+    public function __construct(
69
+        ICommentsManager $commentsManager,
70
+        IUserManager $userManager,
71
+        IUserSession $userSession,
72
+        EventDispatcherInterface $dispatcher,
73
+        ILogger $logger) {
74
+        $this->commentsManager = $commentsManager;
75
+        $this->logger = $logger;
76
+        $this->userManager = $userManager;
77
+        $this->userSession = $userSession;
78
+        $this->dispatcher = $dispatcher;
79
+    }
80
+
81
+    /**
82
+     * initializes the collection. At this point of time, we need the logged in
83
+     * user. Since it is not the case when the instance is created, we cannot
84
+     * have this in the constructor.
85
+     *
86
+     * @throws NotAuthenticated
87
+     */
88
+    protected function initCollections() {
89
+        if ($this->entityTypeCollections !== null) {
90
+            return;
91
+        }
92
+        $user = $this->userSession->getUser();
93
+        if (is_null($user)) {
94
+            throw new NotAuthenticated();
95
+        }
96
+
97
+        $event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY);
98
+        $this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
99
+
100
+        $this->entityTypeCollections = [];
101
+        foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
102
+            $this->entityTypeCollections[$entity] = new EntityTypeCollection(
103
+                $entity,
104
+                $this->commentsManager,
105
+                $this->userManager,
106
+                $this->userSession,
107
+                $this->logger,
108
+                $entityExistsFunction
109
+            );
110
+        }
111
+    }
112
+
113
+    /**
114
+     * Creates a new file in the directory
115
+     *
116
+     * @param string $name Name of the file
117
+     * @param resource|string $data Initial payload
118
+     * @return null|string
119
+     * @throws Forbidden
120
+     */
121
+    public function createFile($name, $data = null) {
122
+        throw new Forbidden('Cannot create comments by id');
123
+    }
124
+
125
+    /**
126
+     * Creates a new subdirectory
127
+     *
128
+     * @param string $name
129
+     * @throws Forbidden
130
+     */
131
+    public function createDirectory($name) {
132
+        throw new Forbidden('Permission denied to create collections');
133
+    }
134
+
135
+    /**
136
+     * Returns a specific child node, referenced by its name
137
+     *
138
+     * This method must throw Sabre\DAV\Exception\NotFound if the node does not
139
+     * exist.
140
+     *
141
+     * @param string $name
142
+     * @return \Sabre\DAV\INode
143
+     * @throws NotFound
144
+     */
145
+    public function getChild($name) {
146
+        $this->initCollections();
147
+        if (isset($this->entityTypeCollections[$name])) {
148
+            return $this->entityTypeCollections[$name];
149
+        }
150
+        throw new NotFound('Entity type "' . $name . '" not found."');
151
+    }
152
+
153
+    /**
154
+     * Returns an array with all the child nodes
155
+     *
156
+     * @return \Sabre\DAV\INode[]
157
+     */
158
+    public function getChildren() {
159
+        $this->initCollections();
160
+        return $this->entityTypeCollections;
161
+    }
162
+
163
+    /**
164
+     * Checks if a child-node with the specified name exists
165
+     *
166
+     * @param string $name
167
+     * @return bool
168
+     */
169
+    public function childExists($name) {
170
+        $this->initCollections();
171
+        return isset($this->entityTypeCollections[$name]);
172
+    }
173
+
174
+    /**
175
+     * Deleted the current node
176
+     *
177
+     * @throws Forbidden
178
+     */
179
+    public function delete() {
180
+        throw new Forbidden('Permission denied to delete this collection');
181
+    }
182
+
183
+    /**
184
+     * Returns the name of the node.
185
+     *
186
+     * This is used to generate the url.
187
+     *
188
+     * @return string
189
+     */
190
+    public function getName() {
191
+        return $this->name;
192
+    }
193
+
194
+    /**
195
+     * Renames the node
196
+     *
197
+     * @param string $name The new name
198
+     * @throws Forbidden
199
+     */
200
+    public function setName($name) {
201
+        throw new Forbidden('Permission denied to rename this collection');
202
+    }
203
+
204
+    /**
205
+     * Returns the last modification time, as a unix timestamp
206
+     *
207
+     * @return int
208
+     */
209
+    public function getLastModified() {
210
+        return null;
211
+    }
212 212
 }
Please login to merge, or discard this patch.