Code Duplication    Length = 22-22 lines in 2 locations

lib/private/IntegrityCheck/Checker.php 2 locations

@@ 260-281 (lines=22) @@
257
	 * @param RSA $privateKey
258
	 * @throws \Exception
259
	 */
260
	public function writeAppSignature($path,
261
									  X509 $certificate,
262
									  RSA $privateKey) {
263
		$appInfoDir = $path . '/appinfo';
264
		$this->fileAccessHelper->assertDirectoryExists($path);
265
		$this->fileAccessHelper->assertDirectoryExists($appInfoDir);
266
267
		$iterator = $this->getFolderIterator($path);
268
		$hashes = $this->generateHashes($iterator, $path);
269
		$signature = $this->createSignatureData($hashes, $certificate, $privateKey);
270
		try {
271
			$this->fileAccessHelper->file_put_contents(
272
				$appInfoDir . '/signature.json',
273
				json_encode($signature, JSON_PRETTY_PRINT)
274
			);
275
		} catch (\Exception $e){
276
			if (!$this->fileAccessHelper->is_writeable($appInfoDir)){
277
				throw new \Exception($appInfoDir . ' is not writable');
278
			}
279
			throw $e;
280
		}
281
	}
282
283
	/**
284
	 * Write the signature of core
@@ 291-312 (lines=22) @@
288
	 * @param string $path
289
	 * @throws \Exception
290
	 */
291
	public function writeCoreSignature(X509 $certificate,
292
									   RSA $rsa,
293
									   $path) {
294
		$coreDir = $path . '/core';
295
		$this->fileAccessHelper->assertDirectoryExists($path);
296
		$this->fileAccessHelper->assertDirectoryExists($coreDir);
297
298
		$iterator = $this->getFolderIterator($path, $path);
299
		$hashes = $this->generateHashes($iterator, $path);
300
		$signatureData = $this->createSignatureData($hashes, $certificate, $rsa);
301
		try {
302
			$this->fileAccessHelper->file_put_contents(
303
				$coreDir . '/signature.json',
304
				json_encode($signatureData, JSON_PRETTY_PRINT)
305
			);
306
		} catch (\Exception $e){
307
			if (!$this->fileAccessHelper->is_writeable($coreDir)){
308
				throw new \Exception($coreDir . ' is not writable');
309
			}
310
			throw $e;
311
		}
312
	}
313
314
	/**
315
	 * Verifies the signature for the specified path.