<commit_before><?php namespace ThibaudDauce\SQLView;

use Closure;
use Illuminate\Support\Fluent;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Grammars\Grammar;
use ThibaudDauce\SQLView\Grammars\Grammar as ViewGrammar;
use ThibaudDauce\SQLView\Exceptions\BlueprintNotReadyException;
use ThibaudDauce\SQLView\Exceptions\InvalidQueryException;
use Illuminate\Database\Query\Builder as QueryBuilder;

class Blueprint {

  /**
   * The view the blueprint describes.
   *
   * @var string
   */
  protected $view;

  /**
   * The connection.
   *
   * @var string
   */
  protected $connection;

  /**
   * View's SQL statement.
   *
   * @var \Illuminate\Database\Query\Builder
   */
  protected $query;

  /**
   * The commands that should be run for the view.
   *
   * @var array
   */
  protected $commands = array();

  /**
   * Create a new view blueprint.
   *
   * @param  string   $view
   * @param  \Closure $callback
   * @return void
   */
  public function __construct($view, Connection $connection, Closure $callback = null)
  {
    $this->view = $view;
    $this->connection = $connection;

    if ( ! is_null($callback)) $callback($this);
  }

  /**
   * Get a new query builder instance for the connection.
   *
   * @return \Illuminate\Database\Query\Builder
   */
  protected function newBaseQueryBuilder(Connection $connection)
  {
    $grammar = $connection->getQueryGrammar();

    return new QueryBuilder($connection, $grammar, $connection->getPostProcessor());
  }

  /**
   * Get the view's SQL statement.
   *
   * @return string
   */
  public function getView()
  {
    return $this->view;
  }

  /**
   * Get the query the blueprint describes.
   *
   * @return \Illuminate\Database\Query\Builder
   */
  public function getQuery()
  {
    return $this->query;
  }

  /**
   * Create or return the query the blueprint describes.
   *
   * @return \Illuminate\Database\Query\Builder
   */
  public function query($table = null)
  {
    if (isset($this->query))
      return $this->getQuery();
    elseif ($table !== null) {

      $this->query = $this->newBaseQueryBuilder($this->connection)->from($table);
      return $this->getQuery();
    }

    throw new InvalidQueryException("Call first query method with table name parameter.")
  }

  /**
   * Is the blueprint ready to build.
   *
   * @return boolean
   */
  public function isReady()
  {
    return isset($this->query);
  }

  /**
   * Execute the blueprint against the database.
   *
   * @param  \Illuminate\Database\Connection        $connection
   * @param  \ThibaudDauce\SQLView\Grammars\Grammar $grammar
   * @return void
   */
  public function build(Connection $connection, ViewGrammar $grammar)
  {<commit_msg>Fix missing ;<commit_after><?php namespace ThibaudDauce\SQLView;

use Closure;
use Illuminate\Support\Fluent;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Grammars\Grammar;
use ThibaudDauce\SQLView\Grammars\Grammar as ViewGrammar;
use ThibaudDauce\SQLView\Exceptions\BlueprintNotReadyException;
use ThibaudDauce\SQLView\Exceptions\InvalidQueryException;
use Illuminate\Database\Query\Builder as QueryBuilder;

class Blueprint {

  /**
   * The view the blueprint describes.
   *
   * @var string
   */
  protected $view;

  /**
   * The connection.
   *
   * @var string
   */
  protected $connection;

  /**
   * View's SQL statement.
   *
   * @var \Illuminate\Database\Query\Builder
   */
  protected $query;

  /**
   * The commands that should be run for the view.
   *
   * @var array
   */
  protected $commands = array();

  /**
   * Create a new view blueprint.
   *
   * @param  string   $view
   * @param  \Closure $callback
   * @return void
   */
  public function __construct($view, Connection $connection, Closure $callback = null)
  {
    $this->view = $view;
    $this->connection = $connection;

    if ( ! is_null($callback)) $callback($this);
  }

  /**
   * Get a new query builder instance for the connection.
   *
   * @return \Illuminate\Database\Query\Builder
   */
  protected function newBaseQueryBuilder(Connection $connection)
  {
    $grammar = $connection->getQueryGrammar();

    return new QueryBuilder($connection, $grammar, $connection->getPostProcessor());
  }

  /**
   * Get the view's SQL statement.
   *
   * @return string
   */
  public function getView()
  {
    return $this->view;
  }

  /**
   * Get the query the blueprint describes.
   *
   * @return \Illuminate\Database\Query\Builder
   */
  public function getQuery()
  {
    return $this->query;
  }

  /**
   * Create or return the query the blueprint describes.
   *
   * @return \Illuminate\Database\Query\Builder
   */
  public function query($table = null)
  {
    if (isset($this->query))
      return $this->getQuery();
    elseif ($table !== null) {

      $this->query = $this->newBaseQueryBuilder($this->connection)->from($table);
      return $this->getQuery();
    }

    throw new InvalidQueryException("Call first query method with table name parameter.");
  }

  /**
   * Is the blueprint ready to build.
   *
   * @return boolean
   */
  public function isReady()
  {
    return isset($this->query);
  }

  /**
   * Execute the blueprint against the database.
   *
   * @param  \Illuminate\Database\Connection        $connection
   * @param  \ThibaudDauce\SQLView\Grammars\Grammar $grammar
   * @return void
   */
  public function build(Connection $connection, ViewGrammar $grammar)
  {
{'fraction_non_alphanumeric': 0.1254355400696864, 'fraction_numerical': 0.0, 'mean_word_length': 2.9379061371841155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '657509', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1728, 'n_words': 410}