Code Duplication    Length = 45-45 lines in 2 locations

src/Discovery/DiscoveryManagerImpl.php 2 locations

@@ 645-689 (lines=45) @@
642
    /**
643
     * {@inheritdoc}
644
     */
645
    public function enableBindingDescriptor(Uuid $uuid)
646
    {
647
        $this->assertModulesLoaded();
648
649
        if (!$this->bindingDescriptors->contains($uuid)) {
650
            throw NoSuchBindingException::forUuid($uuid);
651
        }
652
653
        $bindingDescriptor = $this->bindingDescriptors->get($uuid);
654
        $module = $bindingDescriptor->getContainingModule();
655
656
        if ($module instanceof RootModule) {
657
            throw NonRootModuleExpectedException::cannotEnableBinding($uuid, $module->getName());
658
        }
659
660
        if ($bindingDescriptor->isTypeNotFound()) {
661
            throw NoSuchTypeException::forTypeName($bindingDescriptor->getTypeName());
662
        }
663
664
        if ($bindingDescriptor->isTypeNotEnabled()) {
665
            throw TypeNotEnabledException::forTypeName($bindingDescriptor->getTypeName());
666
        }
667
668
        if ($bindingDescriptor->isEnabled()) {
669
            return;
670
        }
671
672
        $tx = new Transaction();
673
674
        try {
675
            $syncOp = $this->syncBindingUuid($uuid);
676
            $syncOp->takeSnapshot();
677
678
            $tx->execute($this->enableBindingUuid($uuid, $module->getInstallInfo()));
679
            $tx->execute($syncOp);
680
681
            $this->saveRootModuleFile();
682
683
            $tx->commit();
684
        } catch (Exception $e) {
685
            $tx->rollback();
686
687
            throw $e;
688
        }
689
    }
690
691
    /**
692
     * {@inheritdoc}
@@ 694-738 (lines=45) @@
691
    /**
692
     * {@inheritdoc}
693
     */
694
    public function disableBindingDescriptor(Uuid $uuid)
695
    {
696
        $this->assertModulesLoaded();
697
698
        if (!$this->bindingDescriptors->contains($uuid)) {
699
            throw NoSuchBindingException::forUuid($uuid);
700
        }
701
702
        $bindingDescriptor = $this->bindingDescriptors->get($uuid);
703
        $module = $bindingDescriptor->getContainingModule();
704
705
        if ($module instanceof RootModule) {
706
            throw NonRootModuleExpectedException::cannotDisableBinding($uuid, $module->getName());
707
        }
708
709
        if ($bindingDescriptor->isTypeNotFound()) {
710
            throw NoSuchTypeException::forTypeName($bindingDescriptor->getTypeName());
711
        }
712
713
        if ($bindingDescriptor->isTypeNotEnabled()) {
714
            throw TypeNotEnabledException::forTypeName($bindingDescriptor->getTypeName());
715
        }
716
717
        if ($bindingDescriptor->isDisabled()) {
718
            return;
719
        }
720
721
        $tx = new Transaction();
722
723
        try {
724
            $syncOp = $this->syncBindingUuid($uuid);
725
            $syncOp->takeSnapshot();
726
727
            $tx->execute($this->disableBindingUuid($uuid, $module->getInstallInfo()));
728
            $tx->execute($syncOp);
729
730
            $this->saveRootModuleFile();
731
732
            $tx->commit();
733
        } catch (Exception $e) {
734
            $tx->rollback();
735
736
            throw $e;
737
        }
738
    }
739
740
    /**
741
     * {@inheritdoc}