public function register()
    {
        if (!$this->isRegistered()) {
            $moduleObject =& $this->getObject();

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

            if (!$moduleObject->InstallDB() && BitrixException::hasException()) {
                throw new Exception\ModuleInstallException(
                    get_class($moduleObject) . '::InstallDB() returned false',
                    $this->name
                );
            }

            $moduleObject->InstallEvents();

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

            if (!$this->isRegistered()) {
                throw new Exception\ModuleInstallException(
                    'Module was not registered. Probably it does not support automatic installation.',
                    $this->name
                );
            }
        }

        return $this;
    }