You are here

protected function GitDirtyTreeSensorPlugin::getShortFileList in Monitoring 8

Returns a shortened file list for the status message.

Parameters

string $input: Result from running the git command.

int $max_files: Limit the number of files returned.

int $max_length: Limit the length of the path to the file.

Return value

string File names from $output.

1 call to GitDirtyTreeSensorPlugin::getShortFileList()
GitDirtyTreeSensorPlugin::runSensor in src/Plugin/monitoring/SensorPlugin/GitDirtyTreeSensorPlugin.php
Runs the sensor, updating $sensor_result.

File

src/Plugin/monitoring/SensorPlugin/GitDirtyTreeSensorPlugin.php, line 147
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\GitDirtyTreeSensorPlugin.

Class

GitDirtyTreeSensorPlugin
Monitors the git repository for dirty files.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

protected function getShortFileList($input, $max_files = 2, $max_length = 50) {
  $output = array();

  // Remove unnecessary whitespace.
  foreach (array_slice($input, 0, $max_files) as $line) {

    // Separate type of modification and path to file.
    $parts = explode(' ', $line, 2);
    if (strlen($parts[1]) > $max_length) {

      // Put together type of modification and path to file limited by
      // $pathLength.
      $output[] = $parts[0] . ' …' . substr($parts[1], -$max_length);
    }
    else {

      // Return whole line if path is shorter then $pathLength.
      $output[] = $line;
    }
  }
  return implode(', ', $output);
}