<commit_before><?php
declare(strict_types=1);

namespace SetBased\Audit;

use SetBased\Audit\Metadata\TableMetadata;
use SetBased\Audit\Style\AuditStyle;
use SetBased\Exception\FallenException;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableSeparator;

/**
 * Class for printing the differences between audit and data tables.
 */
class DiffTable
{
  //--------------------------------------------------------------------------------------------------------------------
  /**
   * The audit table.
   *
   * @var TableMetadata
   */
  private $auditTable;

  /**
   * The data table.
   *
   * @var TableMetadata
   */
  private $dataTable;

  /**
   * The join column names of the audit and data table.
   *
   * @var array[]
   */
  private $rows = [];

  //--------------------------------------------------------------------------------------------------------------------
  /**
   * Object constructor.
   *
   * @param TableMetadata $dataTable  The data table.
   * @param TableMetadata $auditTable The audit table.
   */
  public function __construct(TableMetadata $dataTable, TableMetadata $auditTable)
  {
    $this->dataTable  = $dataTable;
    $this->auditTable = $auditTable;
  }

  //--------------------------------------------------------------------------------------------------------------------
  /**
   * @param AuditStyle $io   The IO object.
   * @param bool       $full If false and only if only differences are shown.
   */
  public function print(AuditStyle $io, bool $full): void
  {
    $this->rowsEnhanceWithTableColumns();
    $this->rowsEnhanceWithTableOptions();
    $this->rowsEnhanceWithDiffIndicator();
    $this->rowsEnhanceWithColumnTypeInfo();
    $this->rowsEnhanceWithFormatting();

    if ($full || $this->hasDifferences())
    {
      $io->writeln('<dbo>'.$this->dataTable->getTableName().'</dbo>');

      $table = new Table($io);
      $table->setHeaders(['column', 'audit table', 'config / data table'])
            ->setRows($this->getRows($full));
      $table->render();

      $io->writeln('');
    }
  }

  //--------------------------------------------------------------------------------------------------------------------
  /**
   * Returns the rows suitable for Symfony's table.
   *
   * @param bool $full If false and only if only differences are shown.
   *
   * @return array[]
   */
  private function getRows(bool $full): array
  {
    $ret     = [];
    $options = false;
    foreach ($this->rows as $row)
    {
      // Add separator between columns and options.
      if ($options===false && $row['type']=='option')
      {
        if (!empty($ret)) $ret[] = new TableSeparator();
        $options = true;
      }<commit_msg>Fix issue found by Scrutinizer.<commit_after><?php
declare(strict_types=1);

namespace SetBased\Audit;

use SetBased\Audit\Metadata\TableMetadata;
use SetBased\Audit\Style\AuditStyle;
use SetBased\Exception\FallenException;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableSeparator;

/**
 * Class for printing the differences between audit and data tables.
 */
class DiffTable
{
  //--------------------------------------------------------------------------------------------------------------------
  /**
   * The audit table.
   *
   * @var TableMetadata
   */
  private $auditTable;

  /**
   * The data table.
   *
   * @var TableMetadata
   */
  private $dataTable;

  /**
   * The join column names of the audit and data table.
   *
   * @var array[]
   */
  private $rows = [];

  //--------------------------------------------------------------------------------------------------------------------
  /**
   * Object constructor.
   *
   * @param TableMetadata $dataTable  The data table.
   * @param TableMetadata $auditTable The audit table.
   */
  public function __construct(TableMetadata $dataTable, TableMetadata $auditTable)
  {
    $this->dataTable  = $dataTable;
    $this->auditTable = $auditTable;
  }

  //--------------------------------------------------------------------------------------------------------------------
  /**
   * @param AuditStyle $io   The IO object.
   * @param bool       $full If false and only if only differences are shown.
   */
  public function print(AuditStyle $io, bool $full): void
  {
    $this->rowsEnhanceWithTableColumns();
    $this->rowsEnhanceWithTableOptions();
    $this->rowsEnhanceWithDiffIndicator();
    $this->rowsEnhanceWithColumnTypeInfo();
    $this->rowsEnhanceWithFormatting();

    if ($full || $this->hasDifferences())
    {
      $io->writeln('<dbo>'.$this->dataTable->getTableName().'</dbo>');

      $table = new Table($io);
      $table->setHeaders(['column', 'audit table', 'config / data table'])
            ->setRows($this->getRows($full));
      $table->render();

      $io->writeln('');
    }
  }

  //--------------------------------------------------------------------------------------------------------------------
  /**
   * Returns the rows suitable for Symfony's table.
   *
   * @param bool $full If false and only if only differences are shown.
   *
   * @return array
   */
  private function getRows(bool $full): array
  {
    $ret     = [];
    $options = false;
    foreach ($this->rows as $row)
    {
      // Add separator between columns and options.
      if ($options===false && $row['type']=='option')
      {
        if (!empty($ret)) $ret[] = new TableSeparator();
        $options = true;
      }
{'fraction_non_alphanumeric': 0.291697147037308, 'fraction_numerical': 0.000365764447695684, 'mean_word_length': 1.5748587570621468, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, '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': '3171471', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1439, 'n_words': 350}