Code Duplication    Length = 8-10 lines in 4 locations

lib/backend/database.php 2 locations

@@ 587-594 (lines=8) @@
584
585
		$uri = isset($options['uri']) ? $options['uri'] : null;
586
587
		if (!$contact instanceof VCard) {
588
			try {
589
				$contact = Reader::read($contact);
590
			} catch(\Exception $e) {
591
				\OCP\Util::writeLog('contacts', __METHOD__.', exception: '.$e->getMessage(), \OCP\Util::ERROR);
592
				return false;
593
			}
594
		}
595
596
		try {
597
			$contact->validate(VCard::REPAIR|VCard::UPGRADE);
@@ 663-670 (lines=8) @@
660
		$updateRevision = true;
661
		$isCardDAV = false;
662
663
		if (!$contact instanceof VCard) {
664
			try {
665
				$contact = Reader::read($contact);
666
			} catch(\Exception $e) {
667
				\OCP\Util::writeLog('contacts', __METHOD__.', exception: '.$e->getMessage(), \OCP\Util::ERROR);
668
				return false;
669
			}
670
		}
671
672
		if (is_array($id)) {
673

lib/backend/ldap.php 2 locations

@@ 612-619 (lines=8) @@
609
			$contact->FN = $generated;
610
		}
611
612
		if(!$contact instanceof VCard) {
613
			try {
614
				$contact = Reader::read($contact);
615
			} catch(\Exception $e) {
616
				\OCP\Util::writeLog('contacts', __METHOD__.', exception: '.$e->getMessage(), \OCP\Util::ERROR);
617
				return false;
618
			}
619
		}
620
621
		try {
622
			$contact->validate(VCard::REPAIR|VCard::UPGRADE);
@@ 662-671 (lines=10) @@
659
	 * @return bool
660
	 */
661
	public function updateContact($addressbookid, $id, $carddata, array $options = array()) {
662
		if(!$carddata instanceof VCard) {
663
			try {
664
				$vcard = \Sabre\VObject\Reader::read($carddata);
665
			} catch(\Exception $e) {
666
				\OCP\Util::writeLog('contacts', __METHOD__.', exception: '.$e->getMessage(), \OCP\Util::ERROR);
667
				return false;
668
			}
669
		} else {
670
			$vcard = $carddata;
671
		}
672
		
673
		try {
674
			$vcard->validate(VCard::REPAIR|VCard::UPGRADE);