Code Duplication    Length = 37-39 lines in 2 locations

Core/Executor/ObjectStateManager.php 1 location

@@ 83-119 (lines=37) @@
80
     *
81
     * @throws \Exception
82
     */
83
    protected function update()
84
    {
85
        $stateCollection = $this->matchObjectStates('update');
86
87
        if (count($stateCollection) > 1 && array_key_exists('references', $this->dsl)) {
88
            throw new \Exception("Can not execute Object State update because multiple states match, and a references section is specified in the dsl. References can be set when only 1 state matches");
89
        }
90
91
        if (count($stateCollection) > 1 && isset($this->dsl['identifier'])) {
92
            throw new \Exception("Can not execute Object State update because multiple states match, and an identifier is specified in the dsl.");
93
        }
94
95
        $objectStateService = $this->repository->getObjectStateService();
96
97
        foreach ($stateCollection as $state) {
98
            $objectStateUpdateStruct = $objectStateService->newObjectStateUpdateStruct();
99
100
            if (isset($this->dsl['identifier'])) {
101
                $objectStateUpdateStruct->identifier = $this->dsl['identifier'];
102
            }
103
            if (isset($this->dsl['names'])) {
104
                foreach ($this->dsl['names'] as $name) {
105
                    $objectStateUpdateStruct->names[$name['languageCode']] = $name['name'];
106
                }
107
            }
108
            if (isset($this->dsl['descriptions'])) {
109
                foreach ($this->dsl['descriptions'] as $languageCode => $description) {
110
                    $objectStateUpdateStruct->descriptions[$languageCode] = $description;
111
                }
112
            }
113
            $state = $objectStateService->updateObjectState($state, $objectStateUpdateStruct);
114
115
            $this->setReferences($state);
116
        }
117
118
        return $stateCollection;
119
    }
120
121
    /**
122
     * Handle the deletion step of object state migrations.

Core/Executor/ObjectStateGroupManager.php 1 location

@@ 69-107 (lines=39) @@
66
     *
67
     * @todo add support for defaultLanguageCode
68
     */
69
    protected function update()
70
    {
71
        $objectStateService = $this->repository->getObjectStateService();
72
73
        $groupsCollection = $this->matchObjectStateGroups('update');
74
75
        if (count($groupsCollection) > 1 && isset($this->dsl['references'])) {
76
            throw new \Exception("Can not execute Object State Group update because multiple groups match, and a references section is specified in the dsl. References can be set when only 1 state group matches");
77
        }
78
79
        if (count($groupsCollection) > 1 && isset($this->dsl['identifier'])) {
80
            throw new \Exception("Can not execute Object State Group update because multiple groups match, and an identifier is specified in the dsl.");
81
        }
82
83
        foreach ($groupsCollection as $objectStateGroup) {
84
            $objectStateGroupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct();
85
86
            if (isset($this->dsl['identifier'])) {
87
                $objectStateGroupUpdateStruct->identifier = $this->dsl['identifier'];
88
            }
89
            if (isset($this->dsl['names'])) {
90
                foreach ($this->dsl['names'] as $languageCode => $name) {
91
                    $objectStateGroupUpdateStruct->names[$languageCode] = $name;
92
                }
93
            }
94
            if (isset($this->dsl['descriptions'])) {
95
                foreach ($this->dsl['descriptions'] as $languageCode => $description) {
96
                    $objectStateGroupUpdateStruct->descriptions[$languageCode] = $description;
97
                }
98
            }
99
            $objectStateGroup = $objectStateService->updateObjectStateGroup($objectStateGroup, $objectStateGroupUpdateStruct);
100
101
            $this->setReferences($objectStateGroup);
102
        }
103
104
        return $groupsCollection;
105
    }
106
107
    /**
108
     * Handle the delete step of object state group migrations
109
     */
110
    protected function delete()