Passed
Push — master ( 7b8289...9c209a )
by Christoph
12:20 queued 36s
created
lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -29,31 +29,31 @@
 block discarded – undo
29 29
 
30 30
 class PgSqlExpressionBuilder extends ExpressionBuilder {
31 31
 
32
-	/**
33
-	 * Returns a IQueryFunction that casts the column to the given type
34
-	 *
35
-	 * @param string $column
36
-	 * @param mixed $type One of IQueryBuilder::PARAM_*
37
-	 * @return string
38
-	 */
39
-	public function castColumn($column, $type) {
40
-		switch ($type) {
41
-			case IQueryBuilder::PARAM_INT:
42
-				return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS INT)');
43
-			case IQueryBuilder::PARAM_STR:
44
-				return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS TEXT)');
45
-			default:
46
-				return parent::castColumn($column, $type);
47
-		}
48
-	}
32
+    /**
33
+     * Returns a IQueryFunction that casts the column to the given type
34
+     *
35
+     * @param string $column
36
+     * @param mixed $type One of IQueryBuilder::PARAM_*
37
+     * @return string
38
+     */
39
+    public function castColumn($column, $type) {
40
+        switch ($type) {
41
+            case IQueryBuilder::PARAM_INT:
42
+                return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS INT)');
43
+            case IQueryBuilder::PARAM_STR:
44
+                return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS TEXT)');
45
+            default:
46
+                return parent::castColumn($column, $type);
47
+        }
48
+    }
49 49
 
50
-	/**
51
-	 * @inheritdoc
52
-	 */
53
-	public function iLike($x, $y, $type = null) {
54
-		$x = $this->helper->quoteColumnName($x);
55
-		$y = $this->helper->quoteColumnName($y);
56
-		return $this->expressionBuilder->comparison($x, 'ILIKE', $y);
57
-	}
50
+    /**
51
+     * @inheritdoc
52
+     */
53
+    public function iLike($x, $y, $type = null) {
54
+        $x = $this->helper->quoteColumnName($x);
55
+        $y = $this->helper->quoteColumnName($y);
56
+        return $this->expressionBuilder->comparison($x, 'ILIKE', $y);
57
+    }
58 58
 
59 59
 }
Please login to merge, or discard this patch.
apps/user_ldap/templates/renewpassword.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php /** @var $l OC_L10N */ ?>
2 2
 <?php
3 3
 script('user_ldap', [
4
-	'renewPassword',
4
+    'renewPassword',
5 5
 ]);
6 6
 style('user_ldap', 'renewPassword');
7 7
 ?>
Please login to merge, or discard this patch.
lib/private/Collaboration/Resources/Resource.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -31,129 +31,129 @@
 block discarded – undo
31 31
 
32 32
 class Resource implements IResource {
33 33
 
34
-	/** @var IManager */
35
-	protected $manager;
36
-
37
-	/** @var IDBConnection */
38
-	protected $connection;
39
-
40
-	/** @var string */
41
-	protected $type;
42
-
43
-	/** @var string */
44
-	protected $id;
45
-
46
-	/** @var IUser|null */
47
-	protected $userForAccess;
48
-
49
-	/** @var bool|null */
50
-	protected $access;
51
-
52
-	/** @var array|null */
53
-	protected $data;
54
-
55
-	public function __construct(
56
-		IManager $manager,
57
-		IDBConnection $connection,
58
-		string $type,
59
-		string $id,
60
-		?IUser $userForAccess = null,
61
-		?bool $access = null
62
-	) {
63
-		$this->manager = $manager;
64
-		$this->connection = $connection;
65
-		$this->type = $type;
66
-		$this->id = $id;
67
-		$this->userForAccess = $userForAccess;
68
-		$this->access = $access;
69
-	}
70
-
71
-	/**
72
-	 * @return string
73
-	 * @since 16.0.0
74
-	 */
75
-	public function getType(): string {
76
-		return $this->type;
77
-	}
78
-
79
-	/**
80
-	 * @return string
81
-	 * @since 16.0.0
82
-	 */
83
-	public function getId(): string {
84
-		return $this->id;
85
-	}
86
-
87
-	/**
88
-	 * @return array
89
-	 * @since 16.0.0
90
-	 */
91
-	public function getRichObject(): array {
92
-		if ($this->data === null) {
93
-			$this->data = $this->manager->getResourceRichObject($this);
94
-		}
95
-
96
-		return $this->data;
97
-	}
98
-
99
-	/**
100
-	 * Can a user/guest access the resource
101
-	 *
102
-	 * @param IUser|null $user
103
-	 * @return bool
104
-	 * @since 16.0.0
105
-	 */
106
-	public function canAccess(?IUser $user): bool {
107
-		if ($user instanceof IUser) {
108
-			return $this->canUserAccess($user);
109
-		}
110
-		return $this->canGuestAccess();
111
-	}
112
-
113
-	protected function canUserAccess(IUser $user): bool {
114
-		if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
115
-			return $this->access;
116
-		}
117
-
118
-		$access = $this->manager->canAccessResource($this, $user);
119
-		if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
120
-			$this->access = $access;
121
-		}
122
-		return $access;
123
-	}
124
-
125
-	protected function canGuestAccess(): bool {
126
-		if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) {
127
-			return $this->access;
128
-		}
129
-
130
-		$access = $this->manager->canAccessResource($this, null);
131
-		if (!$this->userForAccess instanceof IUser) {
132
-			$this->access = $access;
133
-		}
134
-		return $access;
135
-	}
136
-
137
-	/**
138
-	 * @return ICollection[]
139
-	 * @since 16.0.0
140
-	 */
141
-	public function getCollections(): array {
142
-		$collections = [];
143
-
144
-		$query = $this->connection->getQueryBuilder();
145
-
146
-		$query->select('collection_id')
147
-			->from('collres_resources')
148
-			->where($query->expr()->eq('resource_type', $query->createNamedParameter($this->getType())))
149
-			->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($this->getId())));
150
-
151
-		$result = $query->execute();
152
-		while ($row = $result->fetch()) {
153
-			$collections[] = $this->manager->getCollection((int) $row['collection_id']);
154
-		}
155
-		$result->closeCursor();
156
-
157
-		return $collections;
158
-	}
34
+    /** @var IManager */
35
+    protected $manager;
36
+
37
+    /** @var IDBConnection */
38
+    protected $connection;
39
+
40
+    /** @var string */
41
+    protected $type;
42
+
43
+    /** @var string */
44
+    protected $id;
45
+
46
+    /** @var IUser|null */
47
+    protected $userForAccess;
48
+
49
+    /** @var bool|null */
50
+    protected $access;
51
+
52
+    /** @var array|null */
53
+    protected $data;
54
+
55
+    public function __construct(
56
+        IManager $manager,
57
+        IDBConnection $connection,
58
+        string $type,
59
+        string $id,
60
+        ?IUser $userForAccess = null,
61
+        ?bool $access = null
62
+    ) {
63
+        $this->manager = $manager;
64
+        $this->connection = $connection;
65
+        $this->type = $type;
66
+        $this->id = $id;
67
+        $this->userForAccess = $userForAccess;
68
+        $this->access = $access;
69
+    }
70
+
71
+    /**
72
+     * @return string
73
+     * @since 16.0.0
74
+     */
75
+    public function getType(): string {
76
+        return $this->type;
77
+    }
78
+
79
+    /**
80
+     * @return string
81
+     * @since 16.0.0
82
+     */
83
+    public function getId(): string {
84
+        return $this->id;
85
+    }
86
+
87
+    /**
88
+     * @return array
89
+     * @since 16.0.0
90
+     */
91
+    public function getRichObject(): array {
92
+        if ($this->data === null) {
93
+            $this->data = $this->manager->getResourceRichObject($this);
94
+        }
95
+
96
+        return $this->data;
97
+    }
98
+
99
+    /**
100
+     * Can a user/guest access the resource
101
+     *
102
+     * @param IUser|null $user
103
+     * @return bool
104
+     * @since 16.0.0
105
+     */
106
+    public function canAccess(?IUser $user): bool {
107
+        if ($user instanceof IUser) {
108
+            return $this->canUserAccess($user);
109
+        }
110
+        return $this->canGuestAccess();
111
+    }
112
+
113
+    protected function canUserAccess(IUser $user): bool {
114
+        if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
115
+            return $this->access;
116
+        }
117
+
118
+        $access = $this->manager->canAccessResource($this, $user);
119
+        if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
120
+            $this->access = $access;
121
+        }
122
+        return $access;
123
+    }
124
+
125
+    protected function canGuestAccess(): bool {
126
+        if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) {
127
+            return $this->access;
128
+        }
129
+
130
+        $access = $this->manager->canAccessResource($this, null);
131
+        if (!$this->userForAccess instanceof IUser) {
132
+            $this->access = $access;
133
+        }
134
+        return $access;
135
+    }
136
+
137
+    /**
138
+     * @return ICollection[]
139
+     * @since 16.0.0
140
+     */
141
+    public function getCollections(): array {
142
+        $collections = [];
143
+
144
+        $query = $this->connection->getQueryBuilder();
145
+
146
+        $query->select('collection_id')
147
+            ->from('collres_resources')
148
+            ->where($query->expr()->eq('resource_type', $query->createNamedParameter($this->getType())))
149
+            ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($this->getId())));
150
+
151
+        $result = $query->execute();
152
+        while ($row = $result->fetch()) {
153
+            $collections[] = $this->manager->getCollection((int) $row['collection_id']);
154
+        }
155
+        $result->closeCursor();
156
+
157
+        return $collections;
158
+    }
159 159
 }
Please login to merge, or discard this patch.
lib/public/Collaboration/Resources/IResource.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -29,36 +29,36 @@
 block discarded – undo
29 29
  */
30 30
 interface IResource {
31 31
 
32
-	/**
33
-	 * @return string
34
-	 * @since 16.0.0
35
-	 */
36
-	public function getType(): string;
32
+    /**
33
+     * @return string
34
+     * @since 16.0.0
35
+     */
36
+    public function getType(): string;
37 37
 
38
-	/**
39
-	 * @return string
40
-	 * @since 16.0.0
41
-	 */
42
-	public function getId(): string;
38
+    /**
39
+     * @return string
40
+     * @since 16.0.0
41
+     */
42
+    public function getId(): string;
43 43
 
44
-	/**
45
-	 * @return array
46
-	 * @since 16.0.0
47
-	 */
48
-	public function getRichObject(): array;
44
+    /**
45
+     * @return array
46
+     * @since 16.0.0
47
+     */
48
+    public function getRichObject(): array;
49 49
 
50
-	/**
51
-	 * Can a user/guest access the resource
52
-	 *
53
-	 * @param IUser|null $user
54
-	 * @return bool
55
-	 * @since 16.0.0
56
-	 */
57
-	public function canAccess(?IUser $user): bool;
50
+    /**
51
+     * Can a user/guest access the resource
52
+     *
53
+     * @param IUser|null $user
54
+     * @return bool
55
+     * @since 16.0.0
56
+     */
57
+    public function canAccess(?IUser $user): bool;
58 58
 
59
-	/**
60
-	 * @return ICollection[]
61
-	 * @since 16.0.0
62
-	 */
63
-	public function getCollections(): array;
59
+    /**
60
+     * @return ICollection[]
61
+     * @since 16.0.0
62
+     */
63
+    public function getCollections(): array;
64 64
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/Version1004Date20170924124212.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -28,23 +28,23 @@
 block discarded – undo
28 28
 
29 29
 class Version1004Date20170924124212 extends SimpleMigrationStep {
30 30
 
31
-	/**
32
-	 * @param IOutput $output
33
-	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
34
-	 * @param array $options
35
-	 * @return null|ISchemaWrapper
36
-	 * @since 13.0.0
37
-	 */
38
-	public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
39
-		/** @var ISchemaWrapper $schema */
40
-		$schema = $schemaClosure();
31
+    /**
32
+     * @param IOutput $output
33
+     * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
34
+     * @param array $options
35
+     * @return null|ISchemaWrapper
36
+     * @since 13.0.0
37
+     */
38
+    public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
39
+        /** @var ISchemaWrapper $schema */
40
+        $schema = $schemaClosure();
41 41
 
42
-		$table = $schema->getTable('cards');
43
-		$table->addIndex(['addressbookid'], 'cards_abid');
42
+        $table = $schema->getTable('cards');
43
+        $table->addIndex(['addressbookid'], 'cards_abid');
44 44
 
45
-		$table = $schema->getTable('cards_properties');
46
-		$table->addIndex(['addressbookid'], 'cards_prop_abid');
45
+        $table = $schema->getTable('cards_properties');
46
+        $table->addIndex(['addressbookid'], 'cards_prop_abid');
47 47
 
48
-		return $schema;
49
-	}
48
+        return $schema;
49
+    }
50 50
 }
Please login to merge, or discard this patch.
core/Controller/CollaborationResourcesController.php 1 patch
Indentation   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -37,256 +37,256 @@
 block discarded – undo
37 37
 
38 38
 class CollaborationResourcesController extends OCSController {
39 39
 
40
-	/** @var IManager */
41
-	private $manager;
42
-	/** @var IUserSession */
43
-	private $userSession;
44
-	/** @var ILogger */
45
-	private $logger;
46
-
47
-	public function __construct(
48
-		string $appName,
49
-		IRequest $request,
50
-		IManager $manager,
51
-		IUserSession $userSession,
52
-		ILogger $logger
53
-	) {
54
-		parent::__construct($appName, $request);
55
-
56
-		$this->manager = $manager;
57
-		$this->userSession = $userSession;
58
-		$this->logger = $logger;
59
-	}
60
-
61
-	/**
62
-	 * @param int $collectionId
63
-	 * @return ICollection
64
-	 * @throws CollectionException when the collection was not found for the user
65
-	 */
66
-	protected function getCollection(int $collectionId): ICollection {
67
-		$collection = $this->manager->getCollectionForUser($collectionId, $this->userSession->getUser());
68
-
69
-		if (!$collection->canAccess($this->userSession->getUser())) {
70
-			throw new CollectionException('Not found');
71
-		}
72
-
73
-		return $collection;
74
-	}
75
-
76
-	/**
77
-	 * @NoAdminRequired
78
-	 *
79
-	 * @param int $collectionId
80
-	 * @return DataResponse
81
-	 */
82
-	public function listCollection(int $collectionId): DataResponse {
83
-		try {
84
-			$collection = $this->getCollection($collectionId);
85
-		} catch (CollectionException $e) {
86
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
87
-		}
88
-
89
-		return $this->respondCollection($collection);
90
-	}
91
-
92
-	/**
93
-	 * @NoAdminRequired
94
-	 *
95
-	 * @param string $filter
96
-	 * @return DataResponse
97
-	 */
98
-	public function searchCollections(string $filter): DataResponse {
99
-		try {
100
-			$collections = $this->manager->searchCollections($this->userSession->getUser(), $filter);
101
-		} catch (CollectionException $e) {
102
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
103
-		}
104
-
105
-		return new DataResponse($this->prepareCollections($collections));
106
-	}
107
-
108
-	/**
109
-	 * @NoAdminRequired
110
-	 *
111
-	 * @param int $collectionId
112
-	 * @param string $resourceType
113
-	 * @param string $resourceId
114
-	 * @return DataResponse
115
-	 */
116
-	public function addResource(int $collectionId, string $resourceType, string $resourceId): DataResponse {
117
-		try {
118
-			$collection = $this->getCollection($collectionId);
119
-		} catch (CollectionException $e) {
120
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
121
-		}
122
-
123
-		$resource = $this->manager->createResource($resourceType, $resourceId);
124
-
125
-		if (!$resource->canAccess($this->userSession->getUser())) {
126
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
127
-		}
128
-
129
-		try {
130
-			$collection->addResource($resource);
131
-		} catch (ResourceException $e) {
132
-		}
133
-
134
-		return $this->respondCollection($collection);
135
-	}
136
-
137
-	/**
138
-	 * @NoAdminRequired
139
-	 *
140
-	 * @param int $collectionId
141
-	 * @param string $resourceType
142
-	 * @param string $resourceId
143
-	 * @return DataResponse
144
-	 */
145
-	public function removeResource(int $collectionId, string $resourceType, string $resourceId): DataResponse {
146
-		try {
147
-			$collection = $this->getCollection($collectionId);
148
-		} catch (CollectionException $e) {
149
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
150
-		}
151
-
152
-		try {
153
-			$resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser());
154
-		} catch (CollectionException $e) {
155
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
156
-		}
157
-
158
-		$collection->removeResource($resource);
159
-
160
-		return $this->respondCollection($collection);
161
-	}
162
-
163
-	/**
164
-	 * @NoAdminRequired
165
-	 *
166
-	 * @param string $resourceType
167
-	 * @param string $resourceId
168
-	 * @return DataResponse
169
-	 */
170
-	public function getCollectionsByResource(string $resourceType, string $resourceId): DataResponse {
171
-		try {
172
-			$resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser());
173
-		} catch (ResourceException $e) {
174
-			$resource = $this->manager->createResource($resourceType, $resourceId);
175
-		}
176
-
177
-		if (!$resource->canAccess($this->userSession->getUser())) {
178
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
179
-		}
180
-
181
-		return new DataResponse($this->prepareCollections($resource->getCollections()));
182
-	}
183
-
184
-	/**
185
-	 * @NoAdminRequired
186
-	 *
187
-	 * @param string $baseResourceType
188
-	 * @param string $baseResourceId
189
-	 * @param string $name
190
-	 * @return DataResponse
191
-	 */
192
-	public function createCollectionOnResource(string $baseResourceType, string $baseResourceId, string $name): DataResponse {
193
-		if (!isset($name[0]) || isset($name[64])) {
194
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
195
-		}
196
-
197
-		try {
198
-			$resource = $this->manager->createResource($baseResourceType, $baseResourceId);
199
-		} catch (CollectionException $e) {
200
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
201
-		}
202
-
203
-		if (!$resource->canAccess($this->userSession->getUser())) {
204
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
205
-		}
206
-
207
-		$collection = $this->manager->newCollection($name);
208
-		$collection->addResource($resource);
209
-
210
-		return $this->respondCollection($collection);
211
-	}
212
-
213
-	/**
214
-	 * @NoAdminRequired
215
-	 *
216
-	 * @param int $collectionId
217
-	 * @param string $collectionName
218
-	 * @return DataResponse
219
-	 */
220
-	public function renameCollection(int $collectionId, string $collectionName): DataResponse {
221
-		try {
222
-			$collection = $this->getCollection($collectionId);
223
-		} catch (CollectionException $exception) {
224
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
225
-		}
226
-
227
-		$collection->setName($collectionName);
228
-
229
-		return $this->respondCollection($collection);
230
-	}
231
-
232
-	protected function respondCollection(ICollection $collection): DataResponse {
233
-		try {
234
-			return new DataResponse($this->prepareCollection($collection));
235
-		} catch (CollectionException $e) {
236
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
237
-		} catch (Exception $e) {
238
-			$this->logger->logException($e);
239
-			return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
240
-		}
241
-	}
242
-
243
-	protected function prepareCollections(array $collections): array {
244
-		$result = [];
245
-
246
-		foreach ($collections as $collection) {
247
-			try {
248
-				$result[] = $this->prepareCollection($collection);
249
-			} catch (CollectionException $e) {
250
-			} catch (Exception $e) {
251
-				$this->logger->logException($e);
252
-			}
253
-		}
254
-
255
-		return $result;
256
-	}
257
-
258
-	protected function prepareCollection(ICollection $collection): array {
259
-		if (!$collection->canAccess($this->userSession->getUser())) {
260
-			throw new CollectionException('Can not access collection');
261
-		}
262
-
263
-		return [
264
-			'id' => $collection->getId(),
265
-			'name' => $collection->getName(),
266
-			'resources' => $this->prepareResources($collection->getResources()),
267
-		];
268
-	}
269
-
270
-	protected function prepareResources(array $resources): ?array {
271
-		$result = [];
272
-
273
-		foreach ($resources as $resource) {
274
-			try {
275
-				$result[] = $this->prepareResource($resource);
276
-			} catch (ResourceException $e) {
277
-			} catch (Exception $e) {
278
-				$this->logger->logException($e);
279
-			}
280
-		}
281
-
282
-		return $result;
283
-	}
284
-
285
-	protected function prepareResource(IResource $resource): array {
286
-		if (!$resource->canAccess($this->userSession->getUser())) {
287
-			throw new ResourceException('Can not access resource');
288
-		}
289
-
290
-		return $resource->getRichObject();
291
-	}
40
+    /** @var IManager */
41
+    private $manager;
42
+    /** @var IUserSession */
43
+    private $userSession;
44
+    /** @var ILogger */
45
+    private $logger;
46
+
47
+    public function __construct(
48
+        string $appName,
49
+        IRequest $request,
50
+        IManager $manager,
51
+        IUserSession $userSession,
52
+        ILogger $logger
53
+    ) {
54
+        parent::__construct($appName, $request);
55
+
56
+        $this->manager = $manager;
57
+        $this->userSession = $userSession;
58
+        $this->logger = $logger;
59
+    }
60
+
61
+    /**
62
+     * @param int $collectionId
63
+     * @return ICollection
64
+     * @throws CollectionException when the collection was not found for the user
65
+     */
66
+    protected function getCollection(int $collectionId): ICollection {
67
+        $collection = $this->manager->getCollectionForUser($collectionId, $this->userSession->getUser());
68
+
69
+        if (!$collection->canAccess($this->userSession->getUser())) {
70
+            throw new CollectionException('Not found');
71
+        }
72
+
73
+        return $collection;
74
+    }
75
+
76
+    /**
77
+     * @NoAdminRequired
78
+     *
79
+     * @param int $collectionId
80
+     * @return DataResponse
81
+     */
82
+    public function listCollection(int $collectionId): DataResponse {
83
+        try {
84
+            $collection = $this->getCollection($collectionId);
85
+        } catch (CollectionException $e) {
86
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
87
+        }
88
+
89
+        return $this->respondCollection($collection);
90
+    }
91
+
92
+    /**
93
+     * @NoAdminRequired
94
+     *
95
+     * @param string $filter
96
+     * @return DataResponse
97
+     */
98
+    public function searchCollections(string $filter): DataResponse {
99
+        try {
100
+            $collections = $this->manager->searchCollections($this->userSession->getUser(), $filter);
101
+        } catch (CollectionException $e) {
102
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
103
+        }
104
+
105
+        return new DataResponse($this->prepareCollections($collections));
106
+    }
107
+
108
+    /**
109
+     * @NoAdminRequired
110
+     *
111
+     * @param int $collectionId
112
+     * @param string $resourceType
113
+     * @param string $resourceId
114
+     * @return DataResponse
115
+     */
116
+    public function addResource(int $collectionId, string $resourceType, string $resourceId): DataResponse {
117
+        try {
118
+            $collection = $this->getCollection($collectionId);
119
+        } catch (CollectionException $e) {
120
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
121
+        }
122
+
123
+        $resource = $this->manager->createResource($resourceType, $resourceId);
124
+
125
+        if (!$resource->canAccess($this->userSession->getUser())) {
126
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
127
+        }
128
+
129
+        try {
130
+            $collection->addResource($resource);
131
+        } catch (ResourceException $e) {
132
+        }
133
+
134
+        return $this->respondCollection($collection);
135
+    }
136
+
137
+    /**
138
+     * @NoAdminRequired
139
+     *
140
+     * @param int $collectionId
141
+     * @param string $resourceType
142
+     * @param string $resourceId
143
+     * @return DataResponse
144
+     */
145
+    public function removeResource(int $collectionId, string $resourceType, string $resourceId): DataResponse {
146
+        try {
147
+            $collection = $this->getCollection($collectionId);
148
+        } catch (CollectionException $e) {
149
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
150
+        }
151
+
152
+        try {
153
+            $resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser());
154
+        } catch (CollectionException $e) {
155
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
156
+        }
157
+
158
+        $collection->removeResource($resource);
159
+
160
+        return $this->respondCollection($collection);
161
+    }
162
+
163
+    /**
164
+     * @NoAdminRequired
165
+     *
166
+     * @param string $resourceType
167
+     * @param string $resourceId
168
+     * @return DataResponse
169
+     */
170
+    public function getCollectionsByResource(string $resourceType, string $resourceId): DataResponse {
171
+        try {
172
+            $resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser());
173
+        } catch (ResourceException $e) {
174
+            $resource = $this->manager->createResource($resourceType, $resourceId);
175
+        }
176
+
177
+        if (!$resource->canAccess($this->userSession->getUser())) {
178
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
179
+        }
180
+
181
+        return new DataResponse($this->prepareCollections($resource->getCollections()));
182
+    }
183
+
184
+    /**
185
+     * @NoAdminRequired
186
+     *
187
+     * @param string $baseResourceType
188
+     * @param string $baseResourceId
189
+     * @param string $name
190
+     * @return DataResponse
191
+     */
192
+    public function createCollectionOnResource(string $baseResourceType, string $baseResourceId, string $name): DataResponse {
193
+        if (!isset($name[0]) || isset($name[64])) {
194
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
195
+        }
196
+
197
+        try {
198
+            $resource = $this->manager->createResource($baseResourceType, $baseResourceId);
199
+        } catch (CollectionException $e) {
200
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
201
+        }
202
+
203
+        if (!$resource->canAccess($this->userSession->getUser())) {
204
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
205
+        }
206
+
207
+        $collection = $this->manager->newCollection($name);
208
+        $collection->addResource($resource);
209
+
210
+        return $this->respondCollection($collection);
211
+    }
212
+
213
+    /**
214
+     * @NoAdminRequired
215
+     *
216
+     * @param int $collectionId
217
+     * @param string $collectionName
218
+     * @return DataResponse
219
+     */
220
+    public function renameCollection(int $collectionId, string $collectionName): DataResponse {
221
+        try {
222
+            $collection = $this->getCollection($collectionId);
223
+        } catch (CollectionException $exception) {
224
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
225
+        }
226
+
227
+        $collection->setName($collectionName);
228
+
229
+        return $this->respondCollection($collection);
230
+    }
231
+
232
+    protected function respondCollection(ICollection $collection): DataResponse {
233
+        try {
234
+            return new DataResponse($this->prepareCollection($collection));
235
+        } catch (CollectionException $e) {
236
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
237
+        } catch (Exception $e) {
238
+            $this->logger->logException($e);
239
+            return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
240
+        }
241
+    }
242
+
243
+    protected function prepareCollections(array $collections): array {
244
+        $result = [];
245
+
246
+        foreach ($collections as $collection) {
247
+            try {
248
+                $result[] = $this->prepareCollection($collection);
249
+            } catch (CollectionException $e) {
250
+            } catch (Exception $e) {
251
+                $this->logger->logException($e);
252
+            }
253
+        }
254
+
255
+        return $result;
256
+    }
257
+
258
+    protected function prepareCollection(ICollection $collection): array {
259
+        if (!$collection->canAccess($this->userSession->getUser())) {
260
+            throw new CollectionException('Can not access collection');
261
+        }
262
+
263
+        return [
264
+            'id' => $collection->getId(),
265
+            'name' => $collection->getName(),
266
+            'resources' => $this->prepareResources($collection->getResources()),
267
+        ];
268
+    }
269
+
270
+    protected function prepareResources(array $resources): ?array {
271
+        $result = [];
272
+
273
+        foreach ($resources as $resource) {
274
+            try {
275
+                $result[] = $this->prepareResource($resource);
276
+            } catch (ResourceException $e) {
277
+            } catch (Exception $e) {
278
+                $this->logger->logException($e);
279
+            }
280
+        }
281
+
282
+        return $result;
283
+    }
284
+
285
+    protected function prepareResource(IResource $resource): array {
286
+        if (!$resource->canAccess($this->userSession->getUser())) {
287
+            throw new ResourceException('Can not access resource');
288
+        }
289
+
290
+        return $resource->getRichObject();
291
+    }
292 292
 }
Please login to merge, or discard this patch.
lib/private/App/CodeChecker/NodeVisitor.php 1 patch
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -29,280 +29,280 @@
 block discarded – undo
29 29
 use PhpParser\NodeVisitorAbstract;
30 30
 
31 31
 class NodeVisitor extends NodeVisitorAbstract {
32
-	/** @var ICheck */
33
-	protected $list;
34
-
35
-	/** @var string */
36
-	protected $blackListDescription;
37
-	/** @var string[] */
38
-	protected $blackListedClassNames;
39
-	/** @var string[] */
40
-	protected $blackListedConstants;
41
-	/** @var string[] */
42
-	protected $blackListedFunctions;
43
-	/** @var string[] */
44
-	protected $blackListedMethods;
45
-	/** @var bool */
46
-	protected $checkEqualOperatorUsage;
47
-	/** @var string[] */
48
-	protected $errorMessages;
49
-
50
-	/**
51
-	 * @param ICheck $list
52
-	 */
53
-	public function __construct(ICheck $list) {
54
-		$this->list = $list;
55
-
56
-		$this->blackListedClassNames = [];
57
-		foreach ($list->getClasses() as $class => $blackListInfo) {
58
-			if (is_numeric($class) && is_string($blackListInfo)) {
59
-				$class = $blackListInfo;
60
-				$blackListInfo = null;
61
-			}
62
-
63
-			$class = strtolower($class);
64
-			$this->blackListedClassNames[$class] = $class;
65
-		}
66
-
67
-		$this->blackListedConstants = [];
68
-		foreach ($list->getConstants() as $constantName => $blackListInfo) {
69
-			$constantName = strtolower($constantName);
70
-			$this->blackListedConstants[$constantName] = $constantName;
71
-		}
72
-
73
-		$this->blackListedFunctions = [];
74
-		foreach ($list->getFunctions() as $functionName => $blackListInfo) {
75
-			$functionName = strtolower($functionName);
76
-			$this->blackListedFunctions[$functionName] = $functionName;
77
-		}
78
-
79
-		$this->blackListedMethods = [];
80
-		foreach ($list->getMethods() as $functionName => $blackListInfo) {
81
-			$functionName = strtolower($functionName);
82
-			$this->blackListedMethods[$functionName] = $functionName;
83
-		}
84
-
85
-		$this->checkEqualOperatorUsage = $list->checkStrongComparisons();
86
-
87
-		$this->errorMessages = [
88
-			CodeChecker::CLASS_EXTENDS_NOT_ALLOWED => "%s class must not be extended",
89
-			CodeChecker::CLASS_IMPLEMENTS_NOT_ALLOWED => "%s interface must not be implemented",
90
-			CodeChecker::STATIC_CALL_NOT_ALLOWED => "Static method of %s class must not be called",
91
-			CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED => "Constant of %s class must not not be fetched",
92
-			CodeChecker::CLASS_NEW_NOT_ALLOWED => "%s class must not be instantiated",
93
-			CodeChecker::CLASS_USE_NOT_ALLOWED => "%s class must not be imported with a use statement",
94
-			CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED => "Method of %s class must not be called",
95
-
96
-			CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED => "is discouraged",
97
-		];
98
-	}
99
-
100
-	/** @var array */
101
-	public $errors = [];
102
-
103
-	public function enterNode(Node $node) {
104
-		if ($this->checkEqualOperatorUsage && $node instanceof Node\Expr\BinaryOp\Equal) {
105
-			$this->errors[]= [
106
-				'disallowedToken' => '==',
107
-				'errorCode' => CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED,
108
-				'line' => $node->getLine(),
109
-				'reason' => $this->buildReason('==', CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED)
110
-			];
111
-		}
112
-		if ($this->checkEqualOperatorUsage && $node instanceof Node\Expr\BinaryOp\NotEqual) {
113
-			$this->errors[]= [
114
-				'disallowedToken' => '!=',
115
-				'errorCode' => CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED,
116
-				'line' => $node->getLine(),
117
-				'reason' => $this->buildReason('!=', CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED)
118
-			];
119
-		}
120
-		if ($node instanceof Node\Stmt\Class_) {
121
-			if (!is_null($node->extends)) {
122
-				$this->checkBlackList($node->extends->toString(), CodeChecker::CLASS_EXTENDS_NOT_ALLOWED, $node);
123
-			}
124
-			foreach ($node->implements as $implements) {
125
-				$this->checkBlackList($implements->toString(), CodeChecker::CLASS_IMPLEMENTS_NOT_ALLOWED, $node);
126
-			}
127
-		}
128
-		if ($node instanceof Node\Expr\StaticCall) {
129
-			if (!is_null($node->class)) {
130
-				if ($node->class instanceof Name) {
131
-					$this->checkBlackList($node->class->toString(), CodeChecker::STATIC_CALL_NOT_ALLOWED, $node);
132
-
133
-					$this->checkBlackListFunction($node->class->toString(), $node->name, $node);
134
-					$this->checkBlackListMethod($node->class->toString(), $node->name, $node);
135
-				}
136
-
137
-				if ($node->class instanceof Node\Expr\Variable) {
138
-					/**
139
-					 * TODO: find a way to detect something like this:
140
-					 *       $c = "OC_API";
141
-					 *       $n = $c::call();
142
-					 */
143
-					// $this->checkBlackListMethod($node->class->..., $node->name, $node);
144
-				}
145
-			}
146
-		}
147
-		if ($node instanceof Node\Expr\MethodCall) {
148
-			if (!is_null($node->var)) {
149
-				if ($node->var instanceof Node\Expr\Variable) {
150
-					/**
151
-					 * TODO: find a way to detect something like this:
152
-					 *       $c = new OC_API();
153
-					 *       $n = $c::call();
154
-					 *       $n = $c->call();
155
-					 */
156
-					// $this->checkBlackListMethod($node->var->..., $node->name, $node);
157
-				}
158
-			}
159
-		}
160
-		if ($node instanceof Node\Expr\ClassConstFetch) {
161
-			if (!is_null($node->class)) {
162
-				if ($node->class instanceof Name) {
163
-					$this->checkBlackList($node->class->toString(), CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED, $node);
164
-				}
165
-				if ($node->class instanceof Node\Expr\Variable || $node->class instanceof Node\Expr\PropertyFetch) {
166
-					/**
167
-					 * TODO: find a way to detect something like this:
168
-					 *       $c = "OC_API";
169
-					 *       $n = $i::ADMIN_AUTH;
170
-					 */
171
-				} else {
172
-					$this->checkBlackListConstant($node->class->toString(), $node->name, $node);
173
-				}
174
-			}
175
-		}
176
-		if ($node instanceof Node\Expr\New_) {
177
-			if (!is_null($node->class)) {
178
-				if ($node->class instanceof Name) {
179
-					$this->checkBlackList($node->class->toString(), CodeChecker::CLASS_NEW_NOT_ALLOWED, $node);
180
-				}
181
-				if ($node->class instanceof Node\Expr\Variable) {
182
-					/**
183
-					 * TODO: find a way to detect something like this:
184
-					 *       $c = "OC_API";
185
-					 *       $n = new $i;
186
-					 */
187
-				}
188
-			}
189
-		}
190
-		if ($node instanceof Node\Stmt\UseUse) {
191
-			$this->checkBlackList($node->name->toString(), CodeChecker::CLASS_USE_NOT_ALLOWED, $node);
192
-			if ($node->alias) {
193
-				$this->addUseNameToBlackList($node->name->toString(), $node->alias);
194
-			} else {
195
-				$this->addUseNameToBlackList($node->name->toString(), $node->name->getLast());
196
-			}
197
-		}
198
-	}
199
-
200
-	/**
201
-	 * Check whether an alias was introduced for a namespace of a blacklisted class
202
-	 *
203
-	 * Example:
204
-	 * - Blacklist entry:      OCP\AppFramework\IApi
205
-	 * - Name:                 OCP\AppFramework
206
-	 * - Alias:                OAF
207
-	 * =>  new blacklist entry:  OAF\IApi
208
-	 *
209
-	 * @param string $name
210
-	 * @param string $alias
211
-	 */
212
-	private function addUseNameToBlackList($name, $alias) {
213
-		$name = strtolower($name);
214
-		$alias = strtolower($alias);
215
-
216
-		foreach ($this->blackListedClassNames as $blackListedAlias => $blackListedClassName) {
217
-			if (strpos($blackListedClassName, $name . '\\') === 0) {
218
-				$aliasedClassName = str_replace($name, $alias, $blackListedClassName);
219
-				$this->blackListedClassNames[$aliasedClassName] = $blackListedClassName;
220
-			}
221
-		}
222
-
223
-		foreach ($this->blackListedConstants as $blackListedAlias => $blackListedConstant) {
224
-			if (strpos($blackListedConstant, $name . '\\') === 0 || strpos($blackListedConstant, $name . '::') === 0) {
225
-				$aliasedConstantName = str_replace($name, $alias, $blackListedConstant);
226
-				$this->blackListedConstants[$aliasedConstantName] = $blackListedConstant;
227
-			}
228
-		}
229
-
230
-		foreach ($this->blackListedFunctions as $blackListedAlias => $blackListedFunction) {
231
-			if (strpos($blackListedFunction, $name . '\\') === 0 || strpos($blackListedFunction, $name . '::') === 0) {
232
-				$aliasedFunctionName = str_replace($name, $alias, $blackListedFunction);
233
-				$this->blackListedFunctions[$aliasedFunctionName] = $blackListedFunction;
234
-			}
235
-		}
236
-
237
-		foreach ($this->blackListedMethods as $blackListedAlias => $blackListedMethod) {
238
-			if (strpos($blackListedMethod, $name . '\\') === 0 || strpos($blackListedMethod, $name . '::') === 0) {
239
-				$aliasedMethodName = str_replace($name, $alias, $blackListedMethod);
240
-				$this->blackListedMethods[$aliasedMethodName] = $blackListedMethod;
241
-			}
242
-		}
243
-	}
244
-
245
-	private function checkBlackList($name, $errorCode, Node $node) {
246
-		$lowerName = strtolower($name);
247
-
248
-		if (isset($this->blackListedClassNames[$lowerName])) {
249
-			$this->errors[]= [
250
-				'disallowedToken' => $name,
251
-				'errorCode' => $errorCode,
252
-				'line' => $node->getLine(),
253
-				'reason' => $this->buildReason($this->blackListedClassNames[$lowerName], $errorCode)
254
-			];
255
-		}
256
-	}
257
-
258
-	private function checkBlackListConstant($class, $constantName, Node $node) {
259
-		$name = $class . '::' . $constantName;
260
-		$lowerName = strtolower($name);
261
-
262
-		if (isset($this->blackListedConstants[$lowerName])) {
263
-			$this->errors[]= [
264
-				'disallowedToken' => $name,
265
-				'errorCode' => CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED,
266
-				'line' => $node->getLine(),
267
-				'reason' => $this->buildReason($this->blackListedConstants[$lowerName], CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED)
268
-			];
269
-		}
270
-	}
271
-
272
-	private function checkBlackListFunction($class, $functionName, Node $node) {
273
-		$name = $class . '::' . $functionName;
274
-		$lowerName = strtolower($name);
275
-
276
-		if (isset($this->blackListedFunctions[$lowerName])) {
277
-			$this->errors[]= [
278
-				'disallowedToken' => $name,
279
-				'errorCode' => CodeChecker::STATIC_CALL_NOT_ALLOWED,
280
-				'line' => $node->getLine(),
281
-				'reason' => $this->buildReason($this->blackListedFunctions[$lowerName], CodeChecker::STATIC_CALL_NOT_ALLOWED)
282
-			];
283
-		}
284
-	}
285
-
286
-	private function checkBlackListMethod($class, $functionName, Node $node) {
287
-		$name = $class . '::' . $functionName;
288
-		$lowerName = strtolower($name);
289
-
290
-		if (isset($this->blackListedMethods[$lowerName])) {
291
-			$this->errors[]= [
292
-				'disallowedToken' => $name,
293
-				'errorCode' => CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED,
294
-				'line' => $node->getLine(),
295
-				'reason' => $this->buildReason($this->blackListedMethods[$lowerName], CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED)
296
-			];
297
-		}
298
-	}
299
-
300
-	private function buildReason($name, $errorCode) {
301
-		if (isset($this->errorMessages[$errorCode])) {
302
-			$desc = $this->list->getDescription($errorCode, $name);
303
-			return sprintf($this->errorMessages[$errorCode], $desc);
304
-		}
305
-
306
-		return "$name usage not allowed - error: $errorCode";
307
-	}
32
+    /** @var ICheck */
33
+    protected $list;
34
+
35
+    /** @var string */
36
+    protected $blackListDescription;
37
+    /** @var string[] */
38
+    protected $blackListedClassNames;
39
+    /** @var string[] */
40
+    protected $blackListedConstants;
41
+    /** @var string[] */
42
+    protected $blackListedFunctions;
43
+    /** @var string[] */
44
+    protected $blackListedMethods;
45
+    /** @var bool */
46
+    protected $checkEqualOperatorUsage;
47
+    /** @var string[] */
48
+    protected $errorMessages;
49
+
50
+    /**
51
+     * @param ICheck $list
52
+     */
53
+    public function __construct(ICheck $list) {
54
+        $this->list = $list;
55
+
56
+        $this->blackListedClassNames = [];
57
+        foreach ($list->getClasses() as $class => $blackListInfo) {
58
+            if (is_numeric($class) && is_string($blackListInfo)) {
59
+                $class = $blackListInfo;
60
+                $blackListInfo = null;
61
+            }
62
+
63
+            $class = strtolower($class);
64
+            $this->blackListedClassNames[$class] = $class;
65
+        }
66
+
67
+        $this->blackListedConstants = [];
68
+        foreach ($list->getConstants() as $constantName => $blackListInfo) {
69
+            $constantName = strtolower($constantName);
70
+            $this->blackListedConstants[$constantName] = $constantName;
71
+        }
72
+
73
+        $this->blackListedFunctions = [];
74
+        foreach ($list->getFunctions() as $functionName => $blackListInfo) {
75
+            $functionName = strtolower($functionName);
76
+            $this->blackListedFunctions[$functionName] = $functionName;
77
+        }
78
+
79
+        $this->blackListedMethods = [];
80
+        foreach ($list->getMethods() as $functionName => $blackListInfo) {
81
+            $functionName = strtolower($functionName);
82
+            $this->blackListedMethods[$functionName] = $functionName;
83
+        }
84
+
85
+        $this->checkEqualOperatorUsage = $list->checkStrongComparisons();
86
+
87
+        $this->errorMessages = [
88
+            CodeChecker::CLASS_EXTENDS_NOT_ALLOWED => "%s class must not be extended",
89
+            CodeChecker::CLASS_IMPLEMENTS_NOT_ALLOWED => "%s interface must not be implemented",
90
+            CodeChecker::STATIC_CALL_NOT_ALLOWED => "Static method of %s class must not be called",
91
+            CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED => "Constant of %s class must not not be fetched",
92
+            CodeChecker::CLASS_NEW_NOT_ALLOWED => "%s class must not be instantiated",
93
+            CodeChecker::CLASS_USE_NOT_ALLOWED => "%s class must not be imported with a use statement",
94
+            CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED => "Method of %s class must not be called",
95
+
96
+            CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED => "is discouraged",
97
+        ];
98
+    }
99
+
100
+    /** @var array */
101
+    public $errors = [];
102
+
103
+    public function enterNode(Node $node) {
104
+        if ($this->checkEqualOperatorUsage && $node instanceof Node\Expr\BinaryOp\Equal) {
105
+            $this->errors[]= [
106
+                'disallowedToken' => '==',
107
+                'errorCode' => CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED,
108
+                'line' => $node->getLine(),
109
+                'reason' => $this->buildReason('==', CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED)
110
+            ];
111
+        }
112
+        if ($this->checkEqualOperatorUsage && $node instanceof Node\Expr\BinaryOp\NotEqual) {
113
+            $this->errors[]= [
114
+                'disallowedToken' => '!=',
115
+                'errorCode' => CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED,
116
+                'line' => $node->getLine(),
117
+                'reason' => $this->buildReason('!=', CodeChecker::OP_OPERATOR_USAGE_DISCOURAGED)
118
+            ];
119
+        }
120
+        if ($node instanceof Node\Stmt\Class_) {
121
+            if (!is_null($node->extends)) {
122
+                $this->checkBlackList($node->extends->toString(), CodeChecker::CLASS_EXTENDS_NOT_ALLOWED, $node);
123
+            }
124
+            foreach ($node->implements as $implements) {
125
+                $this->checkBlackList($implements->toString(), CodeChecker::CLASS_IMPLEMENTS_NOT_ALLOWED, $node);
126
+            }
127
+        }
128
+        if ($node instanceof Node\Expr\StaticCall) {
129
+            if (!is_null($node->class)) {
130
+                if ($node->class instanceof Name) {
131
+                    $this->checkBlackList($node->class->toString(), CodeChecker::STATIC_CALL_NOT_ALLOWED, $node);
132
+
133
+                    $this->checkBlackListFunction($node->class->toString(), $node->name, $node);
134
+                    $this->checkBlackListMethod($node->class->toString(), $node->name, $node);
135
+                }
136
+
137
+                if ($node->class instanceof Node\Expr\Variable) {
138
+                    /**
139
+                     * TODO: find a way to detect something like this:
140
+                     *       $c = "OC_API";
141
+                     *       $n = $c::call();
142
+                     */
143
+                    // $this->checkBlackListMethod($node->class->..., $node->name, $node);
144
+                }
145
+            }
146
+        }
147
+        if ($node instanceof Node\Expr\MethodCall) {
148
+            if (!is_null($node->var)) {
149
+                if ($node->var instanceof Node\Expr\Variable) {
150
+                    /**
151
+                     * TODO: find a way to detect something like this:
152
+                     *       $c = new OC_API();
153
+                     *       $n = $c::call();
154
+                     *       $n = $c->call();
155
+                     */
156
+                    // $this->checkBlackListMethod($node->var->..., $node->name, $node);
157
+                }
158
+            }
159
+        }
160
+        if ($node instanceof Node\Expr\ClassConstFetch) {
161
+            if (!is_null($node->class)) {
162
+                if ($node->class instanceof Name) {
163
+                    $this->checkBlackList($node->class->toString(), CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED, $node);
164
+                }
165
+                if ($node->class instanceof Node\Expr\Variable || $node->class instanceof Node\Expr\PropertyFetch) {
166
+                    /**
167
+                     * TODO: find a way to detect something like this:
168
+                     *       $c = "OC_API";
169
+                     *       $n = $i::ADMIN_AUTH;
170
+                     */
171
+                } else {
172
+                    $this->checkBlackListConstant($node->class->toString(), $node->name, $node);
173
+                }
174
+            }
175
+        }
176
+        if ($node instanceof Node\Expr\New_) {
177
+            if (!is_null($node->class)) {
178
+                if ($node->class instanceof Name) {
179
+                    $this->checkBlackList($node->class->toString(), CodeChecker::CLASS_NEW_NOT_ALLOWED, $node);
180
+                }
181
+                if ($node->class instanceof Node\Expr\Variable) {
182
+                    /**
183
+                     * TODO: find a way to detect something like this:
184
+                     *       $c = "OC_API";
185
+                     *       $n = new $i;
186
+                     */
187
+                }
188
+            }
189
+        }
190
+        if ($node instanceof Node\Stmt\UseUse) {
191
+            $this->checkBlackList($node->name->toString(), CodeChecker::CLASS_USE_NOT_ALLOWED, $node);
192
+            if ($node->alias) {
193
+                $this->addUseNameToBlackList($node->name->toString(), $node->alias);
194
+            } else {
195
+                $this->addUseNameToBlackList($node->name->toString(), $node->name->getLast());
196
+            }
197
+        }
198
+    }
199
+
200
+    /**
201
+     * Check whether an alias was introduced for a namespace of a blacklisted class
202
+     *
203
+     * Example:
204
+     * - Blacklist entry:      OCP\AppFramework\IApi
205
+     * - Name:                 OCP\AppFramework
206
+     * - Alias:                OAF
207
+     * =>  new blacklist entry:  OAF\IApi
208
+     *
209
+     * @param string $name
210
+     * @param string $alias
211
+     */
212
+    private function addUseNameToBlackList($name, $alias) {
213
+        $name = strtolower($name);
214
+        $alias = strtolower($alias);
215
+
216
+        foreach ($this->blackListedClassNames as $blackListedAlias => $blackListedClassName) {
217
+            if (strpos($blackListedClassName, $name . '\\') === 0) {
218
+                $aliasedClassName = str_replace($name, $alias, $blackListedClassName);
219
+                $this->blackListedClassNames[$aliasedClassName] = $blackListedClassName;
220
+            }
221
+        }
222
+
223
+        foreach ($this->blackListedConstants as $blackListedAlias => $blackListedConstant) {
224
+            if (strpos($blackListedConstant, $name . '\\') === 0 || strpos($blackListedConstant, $name . '::') === 0) {
225
+                $aliasedConstantName = str_replace($name, $alias, $blackListedConstant);
226
+                $this->blackListedConstants[$aliasedConstantName] = $blackListedConstant;
227
+            }
228
+        }
229
+
230
+        foreach ($this->blackListedFunctions as $blackListedAlias => $blackListedFunction) {
231
+            if (strpos($blackListedFunction, $name . '\\') === 0 || strpos($blackListedFunction, $name . '::') === 0) {
232
+                $aliasedFunctionName = str_replace($name, $alias, $blackListedFunction);
233
+                $this->blackListedFunctions[$aliasedFunctionName] = $blackListedFunction;
234
+            }
235
+        }
236
+
237
+        foreach ($this->blackListedMethods as $blackListedAlias => $blackListedMethod) {
238
+            if (strpos($blackListedMethod, $name . '\\') === 0 || strpos($blackListedMethod, $name . '::') === 0) {
239
+                $aliasedMethodName = str_replace($name, $alias, $blackListedMethod);
240
+                $this->blackListedMethods[$aliasedMethodName] = $blackListedMethod;
241
+            }
242
+        }
243
+    }
244
+
245
+    private function checkBlackList($name, $errorCode, Node $node) {
246
+        $lowerName = strtolower($name);
247
+
248
+        if (isset($this->blackListedClassNames[$lowerName])) {
249
+            $this->errors[]= [
250
+                'disallowedToken' => $name,
251
+                'errorCode' => $errorCode,
252
+                'line' => $node->getLine(),
253
+                'reason' => $this->buildReason($this->blackListedClassNames[$lowerName], $errorCode)
254
+            ];
255
+        }
256
+    }
257
+
258
+    private function checkBlackListConstant($class, $constantName, Node $node) {
259
+        $name = $class . '::' . $constantName;
260
+        $lowerName = strtolower($name);
261
+
262
+        if (isset($this->blackListedConstants[$lowerName])) {
263
+            $this->errors[]= [
264
+                'disallowedToken' => $name,
265
+                'errorCode' => CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED,
266
+                'line' => $node->getLine(),
267
+                'reason' => $this->buildReason($this->blackListedConstants[$lowerName], CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED)
268
+            ];
269
+        }
270
+    }
271
+
272
+    private function checkBlackListFunction($class, $functionName, Node $node) {
273
+        $name = $class . '::' . $functionName;
274
+        $lowerName = strtolower($name);
275
+
276
+        if (isset($this->blackListedFunctions[$lowerName])) {
277
+            $this->errors[]= [
278
+                'disallowedToken' => $name,
279
+                'errorCode' => CodeChecker::STATIC_CALL_NOT_ALLOWED,
280
+                'line' => $node->getLine(),
281
+                'reason' => $this->buildReason($this->blackListedFunctions[$lowerName], CodeChecker::STATIC_CALL_NOT_ALLOWED)
282
+            ];
283
+        }
284
+    }
285
+
286
+    private function checkBlackListMethod($class, $functionName, Node $node) {
287
+        $name = $class . '::' . $functionName;
288
+        $lowerName = strtolower($name);
289
+
290
+        if (isset($this->blackListedMethods[$lowerName])) {
291
+            $this->errors[]= [
292
+                'disallowedToken' => $name,
293
+                'errorCode' => CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED,
294
+                'line' => $node->getLine(),
295
+                'reason' => $this->buildReason($this->blackListedMethods[$lowerName], CodeChecker::CLASS_METHOD_CALL_NOT_ALLOWED)
296
+            ];
297
+        }
298
+    }
299
+
300
+    private function buildReason($name, $errorCode) {
301
+        if (isset($this->errorMessages[$errorCode])) {
302
+            $desc = $this->list->getDescription($errorCode, $name);
303
+            return sprintf($this->errorMessages[$errorCode], $desc);
304
+        }
305
+
306
+        return "$name usage not allowed - error: $errorCode";
307
+    }
308 308
 }
Please login to merge, or discard this patch.
lib/public/Files/SimpleFS/ISimpleFile.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -33,89 +33,89 @@
 block discarded – undo
33 33
  */
34 34
 interface ISimpleFile {
35 35
 
36
-	/**
37
-	 * Get the name
38
-	 *
39
-	 * @return string
40
-	 * @since 11.0.0
41
-	 */
42
-	public function getName();
36
+    /**
37
+     * Get the name
38
+     *
39
+     * @return string
40
+     * @since 11.0.0
41
+     */
42
+    public function getName();
43 43
 
44
-	/**
45
-	 * Get the size in bytes
46
-	 *
47
-	 * @return int
48
-	 * @since 11.0.0
49
-	 */
50
-	public function getSize();
44
+    /**
45
+     * Get the size in bytes
46
+     *
47
+     * @return int
48
+     * @since 11.0.0
49
+     */
50
+    public function getSize();
51 51
 
52
-	/**
53
-	 * Get the ETag
54
-	 *
55
-	 * @return string
56
-	 * @since 11.0.0
57
-	 */
58
-	public function getETag();
52
+    /**
53
+     * Get the ETag
54
+     *
55
+     * @return string
56
+     * @since 11.0.0
57
+     */
58
+    public function getETag();
59 59
 
60
-	/**
61
-	 * Get the last modification time
62
-	 *
63
-	 * @return int
64
-	 * @since 11.0.0
65
-	 */
66
-	public function getMTime();
60
+    /**
61
+     * Get the last modification time
62
+     *
63
+     * @return int
64
+     * @since 11.0.0
65
+     */
66
+    public function getMTime();
67 67
 
68
-	/**
69
-	 * Get the content
70
-	 *
71
-	 * @throws NotPermittedException
72
-	 * @throws NotFoundException
73
-	 * @return string
74
-	 * @since 11.0.0
75
-	 */
76
-	public function getContent();
68
+    /**
69
+     * Get the content
70
+     *
71
+     * @throws NotPermittedException
72
+     * @throws NotFoundException
73
+     * @return string
74
+     * @since 11.0.0
75
+     */
76
+    public function getContent();
77 77
 
78
-	/**
79
-	 * Overwrite the file
80
-	 *
81
-	 * @param string|resource $data
82
-	 * @throws NotPermittedException
83
-	 * @throws NotFoundException
84
-	 * @since 11.0.0
85
-	 */
86
-	public function putContent($data);
78
+    /**
79
+     * Overwrite the file
80
+     *
81
+     * @param string|resource $data
82
+     * @throws NotPermittedException
83
+     * @throws NotFoundException
84
+     * @since 11.0.0
85
+     */
86
+    public function putContent($data);
87 87
 
88
-	/**
89
-	 * Delete the file
90
-	 *
91
-	 * @throws NotPermittedException
92
-	 * @since 11.0.0
93
-	 */
94
-	public function delete();
88
+    /**
89
+     * Delete the file
90
+     *
91
+     * @throws NotPermittedException
92
+     * @since 11.0.0
93
+     */
94
+    public function delete();
95 95
 
96
-	/**
97
-	 * Get the MimeType
98
-	 *
99
-	 * @return string
100
-	 * @since 11.0.0
101
-	 */
102
-	public function getMimeType();
96
+    /**
97
+     * Get the MimeType
98
+     *
99
+     * @return string
100
+     * @since 11.0.0
101
+     */
102
+    public function getMimeType();
103 103
 
104
-	/**
105
-	 * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen
106
-	 *
107
-	 * @return resource
108
-	 * @throws \OCP\Files\NotPermittedException
109
-	 * @since 14.0.0
110
-	 */
111
-	public function read();
104
+    /**
105
+     * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen
106
+     *
107
+     * @return resource
108
+     * @throws \OCP\Files\NotPermittedException
109
+     * @since 14.0.0
110
+     */
111
+    public function read();
112 112
 
113
-	/**
114
-	 * Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen
115
-	 *
116
-	 * @return resource
117
-	 * @throws \OCP\Files\NotPermittedException
118
-	 * @since 14.0.0
119
-	 */
120
-	public function write();
113
+    /**
114
+     * Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen
115
+     *
116
+     * @return resource
117
+     * @throws \OCP\Files\NotPermittedException
118
+     * @since 14.0.0
119
+     */
120
+    public function write();
121 121
 }
Please login to merge, or discard this patch.
lib/public/FullTextSearch/IFullTextSearchManager.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -51,145 +51,145 @@
 block discarded – undo
51 51
 interface IFullTextSearchManager {
52 52
 
53 53
 
54
-	/**
55
-	 * Register a IProviderService.
56
-	 *
57
-	 * @since 15.0.0
58
-	 *
59
-	 * @param IProviderService $providerService
60
-	 */
61
-	public function registerProviderService(IProviderService $providerService);
62
-
63
-	/**
64
-	 * Register a IIndexService.
65
-	 *
66
-	 * @since 15.0.0
67
-	 *
68
-	 * @param IIndexService $indexService
69
-	 */
70
-	public function registerIndexService(IIndexService $indexService);
71
-
72
-	/**
73
-	 * Register a ISearchService.
74
-	 *
75
-	 * @since 15.0.0
76
-	 *
77
-	 * @param ISearchService $searchService
78
-	 */
79
-	public function registerSearchService(ISearchService $searchService);
80
-
81
-	/**
82
-	 * returns true is Full Text Search is available (app is present and Service
83
-	 * are registered)
84
-	 *
85
-	 * @since 16.0.0
86
-	 *
87
-	 * @return bool
88
-	 */
89
-	public function isAvailable(): bool;
90
-
91
-
92
-	/**
93
-	 * Add the Javascript API in the navigation page of an app.
94
-	 * Needed to replace the default search.
95
-	 *
96
-	 * @since 15.0.0
97
-	 */
98
-	public function addJavascriptAPI();
99
-
100
-
101
-	/**
102
-	 * Check if the provider $providerId is already indexed.
103
-	 *
104
-	 * @since 15.0.0
105
-	 *
106
-	 * @param string $providerId
107
-	 *
108
-	 * @return bool
109
-	 */
110
-	public function isProviderIndexed(string $providerId): bool;
111
-
112
-
113
-	/**
114
-	 * Retrieve an Index from the database, based on the Id of the Provider
115
-	 * and the Id of the Document
116
-	 *
117
-	 * @since 15.0.0
118
-	 *
119
-	 * @param string $providerId
120
-	 * @param string $documentId
121
-	 *
122
-	 * @return IIndex
123
-	 */
124
-	public function getIndex(string $providerId, string $documentId): IIndex;
125
-
126
-
127
-	/**
128
-	 * Create a new Index.
129
-	 *
130
-	 * This method must be called when a new document is created.
131
-	 *
132
-	 * @since 15.0.0
133
-	 *
134
-	 * @param string $providerId
135
-	 * @param string $documentId
136
-	 * @param string $userId
137
-	 * @param int $status
138
-	 *
139
-	 * @return IIndex
140
-	 */
141
-	public function createIndex(string $providerId, string $documentId, string $userId, int $status = 0): IIndex;
142
-
143
-
144
-	/**
145
-	 * Update the status of an Index. status is a bitflag, setting $reset to
146
-	 * true will reset the status to the value defined in the parameter.
147
-	 *
148
-	 * @since 15.0.0
149
-	 *
150
-	 * @param string $providerId
151
-	 * @param string $documentId
152
-	 * @param int $status
153
-	 * @param bool $reset
154
-	 */
155
-	public function updateIndexStatus(string $providerId, string $documentId, int $status, bool $reset = false);
156
-
157
-
158
-	/**
159
-	 * Update the status of an array of Index. status is a bit flag, setting $reset to
160
-	 * true will reset the status to the value defined in the parameter.
161
-	 *
162
-	 * @since 15.0.0
163
-	 *
164
-	 * @param string $providerId
165
-	 * @param array $documentIds
166
-	 * @param int $status
167
-	 * @param bool $reset
168
-	 */
169
-	public function updateIndexesStatus(string $providerId, array $documentIds, int $status, bool $reset = false);
170
-
171
-	/**
172
-	 * Update an array of Index.
173
-	 *
174
-	 * @since 15.0.0
175
-	 *
176
-	 * @param IIndex[] $indexes
177
-	 */
178
-	public function updateIndexes(array $indexes);
179
-
180
-	/**
181
-	 * Search using an array as request. If $userId is empty, will use the
182
-	 * current session.
183
-	 *
184
-	 * @see ISearchService::generateSearchRequest
185
-	 *
186
-	 * @since 15.0.0
187
-	 *
188
-	 * @param array $request
189
-	 * @param string $userId
190
-	 * @return ISearchResult[]
191
-	 */
192
-	public function search(array $request, string $userId = ''): array;
54
+    /**
55
+     * Register a IProviderService.
56
+     *
57
+     * @since 15.0.0
58
+     *
59
+     * @param IProviderService $providerService
60
+     */
61
+    public function registerProviderService(IProviderService $providerService);
62
+
63
+    /**
64
+     * Register a IIndexService.
65
+     *
66
+     * @since 15.0.0
67
+     *
68
+     * @param IIndexService $indexService
69
+     */
70
+    public function registerIndexService(IIndexService $indexService);
71
+
72
+    /**
73
+     * Register a ISearchService.
74
+     *
75
+     * @since 15.0.0
76
+     *
77
+     * @param ISearchService $searchService
78
+     */
79
+    public function registerSearchService(ISearchService $searchService);
80
+
81
+    /**
82
+     * returns true is Full Text Search is available (app is present and Service
83
+     * are registered)
84
+     *
85
+     * @since 16.0.0
86
+     *
87
+     * @return bool
88
+     */
89
+    public function isAvailable(): bool;
90
+
91
+
92
+    /**
93
+     * Add the Javascript API in the navigation page of an app.
94
+     * Needed to replace the default search.
95
+     *
96
+     * @since 15.0.0
97
+     */
98
+    public function addJavascriptAPI();
99
+
100
+
101
+    /**
102
+     * Check if the provider $providerId is already indexed.
103
+     *
104
+     * @since 15.0.0
105
+     *
106
+     * @param string $providerId
107
+     *
108
+     * @return bool
109
+     */
110
+    public function isProviderIndexed(string $providerId): bool;
111
+
112
+
113
+    /**
114
+     * Retrieve an Index from the database, based on the Id of the Provider
115
+     * and the Id of the Document
116
+     *
117
+     * @since 15.0.0
118
+     *
119
+     * @param string $providerId
120
+     * @param string $documentId
121
+     *
122
+     * @return IIndex
123
+     */
124
+    public function getIndex(string $providerId, string $documentId): IIndex;
125
+
126
+
127
+    /**
128
+     * Create a new Index.
129
+     *
130
+     * This method must be called when a new document is created.
131
+     *
132
+     * @since 15.0.0
133
+     *
134
+     * @param string $providerId
135
+     * @param string $documentId
136
+     * @param string $userId
137
+     * @param int $status
138
+     *
139
+     * @return IIndex
140
+     */
141
+    public function createIndex(string $providerId, string $documentId, string $userId, int $status = 0): IIndex;
142
+
143
+
144
+    /**
145
+     * Update the status of an Index. status is a bitflag, setting $reset to
146
+     * true will reset the status to the value defined in the parameter.
147
+     *
148
+     * @since 15.0.0
149
+     *
150
+     * @param string $providerId
151
+     * @param string $documentId
152
+     * @param int $status
153
+     * @param bool $reset
154
+     */
155
+    public function updateIndexStatus(string $providerId, string $documentId, int $status, bool $reset = false);
156
+
157
+
158
+    /**
159
+     * Update the status of an array of Index. status is a bit flag, setting $reset to
160
+     * true will reset the status to the value defined in the parameter.
161
+     *
162
+     * @since 15.0.0
163
+     *
164
+     * @param string $providerId
165
+     * @param array $documentIds
166
+     * @param int $status
167
+     * @param bool $reset
168
+     */
169
+    public function updateIndexesStatus(string $providerId, array $documentIds, int $status, bool $reset = false);
170
+
171
+    /**
172
+     * Update an array of Index.
173
+     *
174
+     * @since 15.0.0
175
+     *
176
+     * @param IIndex[] $indexes
177
+     */
178
+    public function updateIndexes(array $indexes);
179
+
180
+    /**
181
+     * Search using an array as request. If $userId is empty, will use the
182
+     * current session.
183
+     *
184
+     * @see ISearchService::generateSearchRequest
185
+     *
186
+     * @since 15.0.0
187
+     *
188
+     * @param array $request
189
+     * @param string $userId
190
+     * @return ISearchResult[]
191
+     */
192
+    public function search(array $request, string $userId = ''): array;
193 193
 
194 194
 
195 195
 }
Please login to merge, or discard this patch.