public function unRegister()
    {
        $moduleObject = $this->getObject();

        if ($this->isRegistered()) {
            /**
             * It's important to check if module class defines UnInstallDB method (it should unregister module)
             * Thus absent UnInstallDB indicates that the module does not support automatic uninstallation
             */
            if ((new \ReflectionClass($moduleObject))->getMethod('UnInstallDB')->class !== get_class($moduleObject)) {
                throw new Exception\ModuleUninstallException(
                    'Missing UnInstallDB method. This module does not support automatic uninstallation',
                    $this->name
                );
            }

            /** @noinspection PhpVoidFunctionResultUsedInspection */
            if (!$moduleObject->UnInstallFiles() && BitrixException::hasException()) {
                throw new Exception\ModuleUninstallException(
                    get_class($moduleObject) . '::UnInstallFiles() returned false',
                    $this->name
                );
            }

            $moduleObject->UnInstallEvents();

            /** @noinspection PhpVoidFunctionResultUsedInspection */
            if (!$moduleObject->UnInstallDB() && BitrixException::hasException()) {
                throw new Exception\ModuleUninstallException(
                    get_class($moduleObject) . '::UnInstallFiles() returned false',
                    $this->name
                );
            }

            if ($this->isRegistered()) {
                throw new Exception\ModuleUninstallException('Module was not unregistered', $this->name);
            }
        }

        return $this;
    }