Check that the passed project slug complies to the transifex restrictions.

@param string $slug The slug to test.

@return void

@throws \RuntimeException When the slug is invalid, an exception is thrown.
760638
protected function checkValidSlug($slug)
    {
        if (preg_match_all('#^([a-z,A-Z,0-9,\-,_]*)(.+)?$#', $slug, $matches)
            && (strlen($matches[2][0]) > 0)
        ) {
            throw new \RuntimeException(
                sprintf(
                    'Error: prefix "%s" is invalid. It must only contain letters, numbers, underscores and hyphens. ' .
                    'Found problem near: "%s"',
                    $slug,
                    $matches[2][0]
                )
            );
        }
    }
987451
protected function reset($slug)
    {
        if (! $this->packages->exists($slug)) {
            return $this->error('Package does not exist.');
        }

        $this->requireMigrations($slug);

        //
        $this->migrator->setconnection($this->input->getOption('database'));

        $pretend = $this->input->getOption('pretend');

        while (true) {
            $count = $this->migrator->rollback($pretend, $slug);

            foreach ($this->migrator->getNotes() as $note) {
                $this->output->writeln($note);
            }

            if ($count == 0) break;
        }
    }
295682
public function hasRoleSlug($slug)
    {
        $roles = $this->active_roles->filter(function (Role $role) use ($slug) {
            return $role->hasSlug($slug);
        });

        return ! $roles->isEmpty();
    }
139646
public function is_plugin_activated( $slug )
	{
		$element = $this->search_plugin( $slug );
		if ( ! $element ) {
			throw new \Exception( sprintf(
				"The %s plugin is not installed.",
				$slug
			) );
		}
		$classes = preg_split( '/\s+/', trim( $element->getAttribute( "class" ) ) );
		if ( in_array( 'active', $classes ) ) {
			return true;
		} else {
			return false;
		}
	}
1159749
public function load($slug, $branch = 'master')
    {
        $this->data = array();
        $this->httpClient->setBaseUrl($this->helper->getRawFileUrl($slug, $branch, ''));

        $this->data = $this->getResponse('composer.json');
    }
218417
private function validate($method)
    {
        $actionMethod = $method.'Method';
        $ref = new \ReflectionClass($this->manager);

        if (null === $this->$actionMethod || !$ref->hasMethod($this->$actionMethod)) {
            throw new \RuntimeException(sprintf('The "%s" method for "%s" adapter is does not supported', $method, $this->getClass()));
        }
    }
1352877
private function checkStage($stage)
    {
        if ($this->runtime->getStage() !== $stage) {
            throw new RuntimeException(sprintf('Invalid stage, got "%s" but expected "%"', $this->runtime->getStage(), $stage));
        }
    }
1084821
public function checkDirectory($path)
    {
        $dir = dirname($path);
        if (!is_dir($dir)) {
            if (false === @mkdir($dir, 0777, true)) {
                throw new RuntimeException(sprintf('Unable to create the "%s" directory', $dir));
            }
        }
    }
683284
protected function prepare( $slug ) {

		$this->slug = $slug;

		$file = Plugin::WP_Plugin_Info()->getOption( 'file', 'plugins' );

		if ( empty( $this->plugin ) ) {

			$this->plugin = $this->model->get_plugins_info( $file );
		}

		if ( ! $this->is_updated() ) {

			$this->plugin[ $slug ] = $this->get_plugin_info( $slug );

			$this->plugin[ $slug ]['last-update'] = time();

			$this->model->set_plugins_info( $this->plugin, $file );
		}
	}
674365
public function getEntity(string $slug): self
    {
        $this->entity = Dashboard::getEntities()->where('slug', $slug)->first();

        throw_if(is_null($this->entity), EntityTypeException::class, "{$slug} Type is not found");

        return $this;
    }
1160359
public function validatePlugin($plugin)
    {
        if ($this->isValidModuleOptions($plugin)) {
            return;
        }

        throw new Exception\RuntimeException(sprintf(
            'Plugin of type %s is invalid; must implement %s',
            (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
            ModuleOptionsInterface::class
        ));
    }
891855
public function updateProject(Project $project)
    {
        $stmt = $this->db->prepare('SELECT COUNT(*) FROM project WHERE slug = :slug');
        $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);

        if (false === $stmt->execute()) {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException(sprintf('Unable to verify existence of project "%s".', $project->getName()));
            // @codeCoverageIgnoreEnd
        }

        if ($stmt->fetchColumn(0)) {
            $stmt = $this->db->prepare('UPDATE project SET slug = :slug, name = :name, repository = :repository, branch = :branch, command = :command, url_pattern = :url_pattern WHERE slug = :slug');
        } else {
            $stmt = $this->db->prepare('INSERT INTO project (slug, name, repository, branch, command, url_pattern) VALUES (:slug, :name, :repository, :branch, :command, :url_pattern)');
        }

        $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);
        $stmt->bindValue(':name', $project->getName(), \PDO::PARAM_STR);
        $stmt->bindValue(':repository', $project->getRepository(), \PDO::PARAM_STR);
        $stmt->bindValue(':branch', $project->getBranch(), \PDO::PARAM_STR);
        $stmt->bindValue(':command', $project->getCommand(), \PDO::PARAM_STR);
        $stmt->bindValue(':url_pattern', $project->getUrlPattern(), \PDO::PARAM_STR);

        if (false === $stmt->execute()) {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException(sprintf('Unable to save project "%s".', $project->getName()));
            // @codeCoverageIgnoreEnd
        }

        // related commits
        $stmt = $this->db->prepare('SELECT sha, author, date, build_date, message, status, output FROM `commit` WHERE slug = :slug ORDER BY `status` = "building" DESC, build_date DESC LIMIT 100');
        $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);

        if (false === $stmt->execute()) {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException(sprintf('Unable to get latest commit for project "%s".', $project->getName()));
            // @codeCoverageIgnoreEnd
        }

        $commits = array();
        while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
            $commits[] = $this->createCommit($project, $result);
        }

        $project->setCommits($commits);

        // project building?
        $stmt = $this->db->prepare('SELECT COUNT(*) AS count FROM `commit` WHERE slug = :slug AND status = "building"');
        $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);

        $building = false;
        if ($stmt->execute() and intval($stmt->fetchColumn(0))) {
            $building = true;
        }

        $project->setBuilding($building);
    }
1294898
protected function migrate($slug)
    {
        if (! $this->packages->exists($slug)) {
            return $this->error('Package does not exist.');
        }

        $path = $this->getMigrationPath($slug);

        //
        $pretend = $this->input->getOption('pretend');

        $this->migrator->run($path, $pretend, $slug);

        //
        foreach ($this->migrator->getNotes() as $note) {
            if (! $this->option('quiet')) {
                $this->line($note);
            }
        }

        if ($this->option('seed')) {
            $this->call('package:seed', array('slug' => $slug, '--force' => true));
        }
    }
666720
public function getBySlug($slug)
    {
        if (empty($slug))
            throw new Exception("Cannot retrieve object [".get_class($this->getModel())."] without slug");

        $results = $this->multiGetBySlug((array)$slug);
        if (isset($results[$slug]))
            return $results[$slug];

        throw new Exception(get_class($this->getModel()).' not found for slug: '.$slug);

    }
25793
protected function _checkCipher($encrypt)
    {
        if (!in_array($encrypt, $this->_validCiphers)) {
            $msg = sprintf(
                'Invalid encryption cipher. Must be one of %s or false.',
                implode(', ', $this->_validCiphers)
            );
            throw new RuntimeException($msg);
        }
    }
247332
public function deactivate_plugin( $slug )
	{
		$element = $this->search_plugin( $slug );
		if ( ! $element ) {
			throw new \Exception( sprintf(
				"The %s plugin is not installed.",
				$slug
			) );
		}
		$edit = $element->find( 'css', '.deactivate a' );
		$edit->click();
		sleep( 1 );
	}
1305402
protected function checkEndpoint()
    {
        if ($this->endpoint == '' || null === $this->endpoint || empty($this->endpoint)) {
            throw new \RunTimeException('No endpoint defined.');
        }
    }