Code Duplication    Length = 26-26 lines in 2 locations

cloudcontrol/library/storage/JsonStorage.php 2 locations

@@ 276-301 (lines=26) @@
273
			$this->save();
274
		}
275
276
		public function deleteDocumentBySlug($slug)
277
		{
278
			$documentContainer = $this->getDocumentContainerByPath($slug);
279
			$indices = $documentContainer['indices'];
280
281
			$folder = $this->repository->documents;
282
			$previousFolder = $this->repository->documents;
283
			foreach ($indices as $index) {
284
				if ($folder === $this->repository->documents) {
285
					$folder = $folder[$index];
286
				} else {
287
					$previousFolder = $folder;
288
					$folder = $folder->content[$index];
289
				}
290
			}
291
292
			if ($previousFolder === $this->repository->documents) {
293
				unset($this->repository->documents[end($indices)]);
294
				$this->repository->documents = array_values($this->repository->documents);
295
			} else {
296
				unset($previousFolder->content[end($indices)]);
297
				$previousFolder->content = array_values($previousFolder->content);
298
			}
299
300
			$this->save();
301
		}
302
303
		private function createDocumentFromPostValues($postValues)
304
		{
@@ 421-446 (lines=26) @@
418
		 *
419
		 * @throws \Exception
420
		 */
421
		public function deleteDocumentFolderBySlug($slug)
422
		{
423
			$documentContainer = $this->getDocumentContainerByPath($slug);
424
			$indices = $documentContainer['indices'];
425
426
			$folder = $this->repository->documents;
427
			$previousFolder = $this->repository->documents;
428
			foreach ($indices as $index) {
429
				if ($folder === $this->repository->documents) {
430
					$folder = $folder[$index];
431
				} else {
432
					$previousFolder = $folder;
433
					$folder = $folder->content[$index];
434
				}
435
			}
436
437
			if ($previousFolder === $this->repository->documents) {
438
				unset($this->repository->documents[end($indices)]);
439
				$this->repository->documents = array_values($this->repository->documents);
440
			} else {
441
				unset($previousFolder->content[end($indices)]);
442
				$previousFolder->content = array_values($previousFolder->content);
443
			}
444
445
			$this->save();
446
		}
447
448
		/**
449
		 * Retrieve a folder by its compound slug