Commit 79c28c31 authored by Damien McKenna's avatar Damien McKenna Committed by Damien McKenna
Browse files

Issue #3262391 by DamienMcKenna: Coding standards improvements.

parent 31db30e0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ Backup and Migrate 5.1.x-dev, xxxx-xx-xx
  scheduled backup.
#3258613 by Anybody, hmendes, pmagunia, DamienMcKenna: Improve Quick Backup
  status message.
#3262391 by DamienMcKenna: Coding standards improvements.


Backup and Migrate 5.0.x-dev, xxxx-xx-xx
+1 −2
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ namespace Drupal\backup_migrate\Controller;
use Drupal\backup_migrate\Entity\Schedule;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Exception;

/**
 * Provides a listing of Schedule entities.
@@ -35,7 +34,7 @@ class ScheduleListBuilder extends ConfigEntityListBuilder {
   */
  public function buildRow(EntityInterface $entity) {
    if (!$entity instanceof Schedule) {
      throw new Exception();
      throw new \Exception();
    }
    $row['label'] = $entity->label();
    $row['enabled'] = $entity->get('enabled') ? $this->t('Yes') : $this->t('No');
+17 −5
Original line number Diff line number Diff line
@@ -128,24 +128,36 @@ trait ConfigurableTrait {

        // Check if it's required.
        if (!empty($field['required']) && empty($value)) {
          $out[] = new ValidationError($key, $this->t('%title is required.'), ['%title' => $field['title']]);
          $out[] = new ValidationError($key, $this->t('%title is required.'), [
            '%title' => $field['title'],
          ]);
        }

        // Check it for length.
        if (!empty($field['min_length']) && strlen($value) < $field['min_length']) {
          $out[] = new ValidationError($key, $this->t('%title must be at least %count characters.'), ['%title' => $field['title'], '%count' => $field['min_length']]);
          $out[] = new ValidationError($key, $this->t('%title must be at least %count characters.'), [
            '%title' => $field['title'],
            '%count' => $field['min_length'],
          ]);
        }
        if (!empty($field['max_length']) && strlen($value) > $field['max_length']) {
          $out[] = new ValidationError($key, $this->t('%title must be at no more than %count characters.'), ['%title' => $field['title'], '%count' => $field['max_length']]);
          $out[] = new ValidationError($key, $this->t('%title must be at no more than %count characters.'), [
            '%title' => $field['title'],
            '%count' => $field['max_length'],
          ]);
        }

        // Check for the regular expression match.
        if (!empty($field['must_match']) && !preg_match($field['must_match'], $value)) {
          if (!empty($field['must_match_error'])) {
            $out[] = new ValidationError($key, $field['must_match_error'], ['%title' => $field['title']]);
            $out[] = new ValidationError($key, $field['must_match_error'], [
              '%title' => $field['title'],
            ]);
          }
          else {
            $out[] = new ValidationError($key, $this->t('%title contains invalid characters.'), ['%title' => $field['title']]);
            $out[] = new ValidationError($key, $this->t('%title contains invalid characters.'), [
              '%title' => $field['title'],
            ]);
          }
        }
      }
+15 −8
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use Drupal\backup_migrate\Core\Plugin\PluginCallerInterface;
use Drupal\backup_migrate\Core\Plugin\PluginCallerTrait;

/**
 *
 * A destination that downloads files to the browser.
 *
 * @package Drupal\backup_migrate\Core\Destination
 */
@@ -21,8 +21,14 @@ class BrowserDownloadDestination extends StreamDestination implements WritableDe
  public function saveFile(BackupFileReadableInterface $file) {
    // Set some default download headers.
    $headers = [
      ['key' => 'Content-Disposition', 'value' => 'attachment; filename="' . $file->getFullName() . '"'],
      ['key' => 'Cache-Control', 'value' => 'no-cache'],
      [
        'key' => 'Content-Disposition',
        'value' => 'attachment; filename="' . $file->getFullName() . '"',
      ],
      [
        'key' => 'Cache-Control',
        'value' => 'no-cache',
      ],
    ];

    // Set a mime-type header.
@@ -32,7 +38,9 @@ class BrowserDownloadDestination extends StreamDestination implements WritableDe
    else {
      // Get the mime type for this file if possible.
      $mime = 'application/octet-stream';
      $mime = $this->plugins()->call('alterMime', $mime, ['ext' => $file->getExtLast()]);
      $mime = $this->plugins()->call('alterMime', $mime, [
        'ext' => $file->getExtLast(),
      ]);

      $headers[] = ['key' => 'Content-Type', 'value' => $mime];
    }
@@ -74,11 +82,10 @@ class BrowserDownloadDestination extends StreamDestination implements WritableDe
   */
  public function checkWritable() {
    // Check that we're running as a web process via a browser.
    // @todo we could check if the 'HTTP_ACCEPT' header contains the right mime but that is probably overkill.
    // @todo It could check if the 'HTTP_ACCEPT' header contains the right mime
    // but that is probably overkill.
    if (!isset($_SERVER['REQUEST_METHOD'])) {
      throw new DestinationNotWritableException(
        "The download destination only works when accessed through a http client."
      );
      throw new DestinationNotWritableException('The download destination only works when accessed through a http client.');
    }
  }

+1 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ use Drupal\backup_migrate\Core\Config\Config;
use Drupal\backup_migrate\Core\File\BackupFileReadableInterface;

/**
 *
 * A destination that adds debugging.
 *
 * @package Drupal\backup_migrate\Core\Destination
 */
@@ -16,7 +16,6 @@ class DebugDestination extends StreamDestination implements WritableDestinationI
   * {@inheritdoc}
   */
  public function saveFile(BackupFileReadableInterface $file) {

    // Quick and dirty way to html format this output.
    if ($this->confGet('format') == 'html') {
      print '<pre>';
Loading