private function detectHomeDirectory()
    {
        // Environment variable COMPOSER points to the composer.json we should use.
        if (false !== ($home = getenv('COMPOSER'))) {
            return dirname($home);
        }

        if ('' !== \Phar::running()) {
            // Strip scheme "phar://" prefix and "tenside.phar" suffix.
            $home = dirname(substr(\Phar::running(), 7));
        } else {
            $home = getcwd();
        }

        if ((PHP_SAPI !== 'cli') && (substr($home, -4) !== DIRECTORY_SEPARATOR . 'web')) {
            throw new \RuntimeException(
                'Tenside is intended to be run from within the web directory but it appears you are running it from ' .
                basename($home)
            );
        }

        return dirname($home);
    }