Code Duplication    Length = 46-48 lines in 2 locations

src/Module/Module.php 2 locations

@@ 108-155 (lines=48) @@
105
     * @throws Exception\ModuleException
106
     * @throws BitrixException
107
     */
108
    public function register()
109
    {
110
        if (!$this->isRegistered()) {
111
            $moduleObject =& $this->getObject();
112
113
            /**
114
             * It's important to check if module class defines InstallDB method (it must register module)
115
             * Thus absent InstallDB indicates that the module does not support automatic installation
116
             */
117
            if ((new \ReflectionClass($moduleObject))->getMethod('InstallDB')->class !== get_class($moduleObject)) {
118
                throw new Exception\ModuleInstallException(
119
                    'Missing InstallDB method. This module does not support automatic installation',
120
                    $this->name
121
                );
122
            }
123
124
            if (!$moduleObject->InstallDB() && BitrixException::hasException()) {
125
                throw new Exception\ModuleInstallException(
126
                    get_class($moduleObject) . '::InstallDB() returned false',
127
                    $this->name
128
                );
129
            }
130
131
            $moduleObject->InstallEvents();
132
133
            /** @noinspection PhpVoidFunctionResultUsedInspection */
134
            if (!$moduleObject->InstallFiles() && BitrixException::hasException()) {
135
                throw new Exception\ModuleInstallException(
136
                    get_class($moduleObject) . '::InstallFiles() returned false',
137
                    $this->name
138
                );
139
            }
140
141
            if (!$this->isRegistered()) {
142
                throw new Exception\ModuleInstallException(
143
                    'Module was not registered. Probably it does not support automatic installation.',
144
                    $this->name
145
                );
146
            }
147
        }
148
149
        return $this;
150
    }
151
152
    /**
153
     * Download module from Marketplace.
154
     *
155
     * @return $this
156
     */
157
    public function load()
158
    {
@@ 183-228 (lines=46) @@
180
     * @throws Exception\ModuleException
181
     * @throws BitrixException
182
     */
183
    public function unRegister()
184
    {
185
        $moduleObject = $this->getObject();
186
187
        if ($this->isRegistered()) {
188
            /**
189
             * It's important to check if module class defines UnInstallDB method (it should unregister module)
190
             * Thus absent UnInstallDB indicates that the module does not support automatic uninstallation
191
             */
192
            if ((new \ReflectionClass($moduleObject))->getMethod('UnInstallDB')->class !== get_class($moduleObject)) {
193
                throw new Exception\ModuleUninstallException(
194
                    'Missing UnInstallDB method. This module does not support automatic uninstallation',
195
                    $this->name
196
                );
197
            }
198
199
            /** @noinspection PhpVoidFunctionResultUsedInspection */
200
            if (!$moduleObject->UnInstallFiles() && BitrixException::hasException()) {
201
                throw new Exception\ModuleUninstallException(
202
                    get_class($moduleObject) . '::UnInstallFiles() returned false',
203
                    $this->name
204
                );
205
            }
206
207
            $moduleObject->UnInstallEvents();
208
209
            /** @noinspection PhpVoidFunctionResultUsedInspection */
210
            if (!$moduleObject->UnInstallDB() && BitrixException::hasException()) {
211
                throw new Exception\ModuleUninstallException(
212
                    get_class($moduleObject) . '::UnInstallFiles() returned false',
213
                    $this->name
214
                );
215
            }
216
217
            if ($this->isRegistered()) {
218
                throw new Exception\ModuleUninstallException('Module was not unregistered', $this->name);
219
            }
220
        }
221
222
        return $this;
223
    }
224
225
    /**
226
     * Uninstall and remove module directory.
227
     */
228
    public function remove()
229
    {
230
        if ($this->isRegistered()) {
231
            $this->unRegister();