You are here

protected function SensorGitDirtyTree::getShortFileList in Monitoring 7

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 SensorGitDirtyTree::getShortFileList()
SensorGitDirtyTree::runSensor in lib/Drupal/monitoring/Sensor/Sensors/SensorGitDirtyTree.php
Runs the sensor, updating $sensor_result.

File

lib/Drupal/monitoring/Sensor/Sensors/SensorGitDirtyTree.php, line 139
Contains \Drupal\monitoring\Sensor\Sensors\SensorGitDirtyTree.

Class

SensorGitDirtyTree
Monitors the git repository for dirty files.

Namespace

Drupal\monitoring\Sensor\Sensors

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);
}