original_string: public function formatMetrics(DataTable $dataTable, Report $report = null, $metricsToFormat = null, $formatAll = false)
      {
          $metrics = $this->getMetricsToFormat($dataTable, $report);
          if (empty($metrics)
              || $dataTable->getMetadata(self::PROCESSED_METRICS_FORMATTED_FLAG)
          ) {
              return;
          }
  
          $dataTable->setMetadata(self::PROCESSED_METRICS_FORMATTED_FLAG, true);
  
          if ($metricsToFormat !== null) {
              $metricMatchRegex = $this->makeRegexToMatchMetrics($metricsToFormat);
              $metrics = array_filter($metrics, function ($metric) use ($metricMatchRegex) {
                  /** @var ProcessedMetric|ArchivedMetric $metric */
                  return preg_match($metricMatchRegex, $metric->getName());
              });
          }
  
          foreach ($metrics as $name => $metric) {
              if (!$metric->beforeFormat($report, $dataTable)) {
                  continue;
              }
  
              foreach ($dataTable->getRows() as $row) {
                  $columnValue = $row->getColumn($name);
                  if ($columnValue !== false) {
                      $row->setColumn($name, $metric->format($columnValue, $this));
                  }
              }
          }
  
          foreach ($dataTable->getRows() as $row) {
              $subtable = $row->getSubtable();
              if (!empty($subtable)) {
                  $this->formatMetrics($subtable, $report, $metricsToFormat);
              }
          }
  
          $idSite = DataTableFactory::getSiteIdFromMetadata($dataTable);
          if (empty($idSite)) {
              // possible when using search in visualization
              $idSite = Common::getRequestVar('idSite', 0, 'int');
          }
  
          // @todo for matomo 4, should really use the Metric class to house this kind of logic
          // format other metrics
          if ($formatAll) {
              foreach ($dataTable->getRows() as $row) {
                  foreach ($row->getColumns() as $column => $columnValue) {
                      if (strpos($column, 'revenue') === false
                          || !is_numeric($columnValue)
                      ) {
                          continue;
                      }
  
                      if ($columnValue !== false) {
                          $row->setColumn($column, $this->getPrettyMoney($columnValue, $idSite));
                      }
                  }
              }
          }
      }
code: public function formatMetrics(DataTable $dataTable, Report $report = null, $metricsToFormat = null, $formatAll = false)
      {
          $metrics = $this->getMetricsToFormat($dataTable, $report);
          if (empty($metrics)
              || $dataTable->getMetadata(self::PROCESSED_METRICS_FORMATTED_FLAG)
          ) {
              return;
          }
  
          $dataTable->setMetadata(self::PROCESSED_METRICS_FORMATTED_FLAG, true);
  
          if ($metricsToFormat !== null) {
              $metricMatchRegex = $this->makeRegexToMatchMetrics($metricsToFormat);
              $metrics = array_filter($metrics, function ($metric) use ($metricMatchRegex) {
                  /** @var ProcessedMetric|ArchivedMetric $metric */
                  return preg_match($metricMatchRegex, $metric->getName());
              });
          }
  
          foreach ($metrics as $name => $metric) {
              if (!$metric->beforeFormat($report, $dataTable)) {
                  continue;
              }
  
              foreach ($dataTable->getRows() as $row) {
                  $columnValue = $row->getColumn($name);
                  if ($columnValue !== false) {
                      $row->setColumn($name, $metric->format($columnValue, $this));
                  }
              }
          }
  
          foreach ($dataTable->getRows() as $row) {
              $subtable = $row->getSubtable();
              if (!empty($subtable)) {
                  $this->formatMetrics($subtable, $report, $metricsToFormat);
              }
          }
  
          $idSite = DataTableFactory::getSiteIdFromMetadata($dataTable);
          if (empty($idSite)) {
              // possible when using search in visualization
              $idSite = Common::getRequestVar('idSite', 0, 'int');
          }
  
          // @todo for matomo 4, should really use the Metric class to house this kind of logic
          // format other metrics
          if ($formatAll) {
              foreach ($dataTable->getRows() as $row) {
                  foreach ($row->getColumns() as $column => $columnValue) {
                      if (strpos($column, 'revenue') === false
                          || !is_numeric($columnValue)
                      ) {
                          continue;
                      }
  
                      if ($columnValue !== false) {
                          $row->setColumn($column, $this->getPrettyMoney($columnValue, $idSite));
                      }
                  }
              }
          }
      }
code_tokens: public function formatMetrics ( DataTable $ dataTable , Report $ report = null , $ metricsToFormat = null , $ formatAll = false ) { $ metrics = $ this -> getMetricsToFormat ( $ dataTable , $ report ) ; if ( empty ( $ metrics ) || $ dataTable -> getMetadata ( self :: PROCESSED_METRICS_FORMATTED_FLAG ) ) { return ; } $ dataTable -> setMetadata ( self :: PROCESSED_METRICS_FORMATTED_FLAG , true ) ; if ( $ metricsToFormat !== null ) { $ metricMatchRegex = $ this -> makeRegexToMatchMetrics ( $ metricsToFormat ) ; $ metrics = array_filter ( $ metrics , function ( $ metric ) use ( $ metricMatchRegex ) { /** @var ProcessedMetric|ArchivedMetric $metric */ return preg_match ( $ metricMatchRegex , $ metric -> getName ( ) ) ; } ) ; } foreach ( $ metrics as $ name => $ metric ) { if ( ! $ metric -> beforeFormat ( $ report , $ dataTable ) ) { continue ; } foreach ( $ dataTable -> getRows ( ) as $ row ) { $ columnValue = $ row -> getColumn ( $ name ) ; if ( $ columnValue !== false ) { $ row -> setColumn ( $ name , $ metric -> format ( $ columnValue , $ this ) ) ; } } } foreach ( $ dataTable -> getRows ( ) as $ row ) { $ subtable = $ row -> getSubtable ( ) ; if ( ! empty ( $ subtable ) ) { $ this -> formatMetrics ( $ subtable , $ report , $ metricsToFormat ) ; } } $ idSite = DataTableFactory :: getSiteIdFromMetadata ( $ dataTable ) ; if ( empty ( $ idSite ) ) { // possible when using search in visualization $ idSite = Common :: getRequestVar ( 'idSite' , 0 , 'int' ) ; } // @todo for matomo 4, should really use the Metric class to house this kind of logic // format other metrics if ( $ formatAll ) { foreach ( $ dataTable -> getRows ( ) as $ row ) { foreach ( $ row -> getColumns ( ) as $ column => $ columnValue ) { if ( strpos ( $ column , 'revenue' ) === false || ! is_numeric ( $ columnValue ) ) { continue ; } if ( $ columnValue !== false ) { $ row -> setColumn ( $ column , $ this -> getPrettyMoney ( $ columnValue , $ idSite ) ) ; } } } } }
docstring: Formats all metrics, including processed metrics, for a DataTable. Metrics to format
  are found through report metadata and DataTable metadata.
  
  @param DataTable $dataTable The table to format metrics for.
  @param Report|null $report The report the table belongs to.
  @param string[]|null $metricsToFormat Whitelist of names of metrics to format.
  @param boolean $formatAll If true, will also apply formatting to non-processed metrics like revenue.
  This parameter is not currently supported and subject to change.
  @api
docstring_tokens: Formats all metrics including processed metrics for a DataTable . Metrics to format are found through report metadata and DataTable metadata .