GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 8.x-2.x ( bdb6af...21ed67 )
by Devin
56:27
created

FieldApiContext::setMaximumUploadSize()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 4
nop 2
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Acquia\DFExtension\Context;
4
5
use Drupal\Component\Utility\Bytes;
6
use Drupal\DrupalExtension\Context\DrupalSubContextBase;
7
use Drupal\field\Entity\FieldConfig;
8
9
/**
10
 * Contains steps for working with fields at the API level.
11
 */
12
class FieldApiContext extends DrupalSubContextBase {
13
14
  /**
15
   * Sets the maximum upload size for a file or image field.
16
   *
17
   * @param string $field
18
   *   The field config entity ID.
19
   * @param string $size
20
   *   (optional) The maximum upload size, e.g. 50 KB, 32 MB, etc.
21
   *
22
   * @Given :field has a maximum upload size of :size
23
   * @Given :field has no maximum upload size
24
   *
25
   * @When I set the maximum upload size of :field to :size
26
   * @When I clear the maximum upload size of :field
27
   */
28
  public function setMaximumUploadSize($field, $size = NULL) {
29
    $field = FieldConfig::load($field);
30
31
    /** @var UndoContext $undo */
32
    $undo = $this->getContext(UndoContext::class);
33
    if ($undo) {
34
      $undo->push([$this, __FUNCTION__], [
35
        $field->id(),
36
        $field->getSetting('max_filesize'),
37
      ]);
38
    }
39
40
    if ($size) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $size of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
41
      $size = Bytes::toInt($size);
42
    }
43
    $field->setSetting('max_filesize', $size)->save();
44
  }
45
46
  /**
47
   * Sets the allowed extensions for a file or image field.
48
   *
49
   * @param string $field
50
   *   The field config entity ID.
51
   * @param string $extensions
52
   *   A space-separated list of allowed extensions.
53
   *
54
   * @Given :field accepts the :extensions extension(s)
55
   * @Given :field accepts :extensions files
56
   *
57
   * @When I configure :field to accept the :extensions extension(s)
58
   * @When I configure :field to accept :extensions files
59
   */
60
  public function setAllowedExtensions($field, $extensions) {
61
    $field = FieldConfig::load($field);
62
63
    /** @var UndoContext $undo */
64
    $undo = $this->getContext(UndoContext::class);
65
    if ($undo) {
66
      $undo->push([$this, __FUNCTION__], [
67
        $field->id(),
68
        $field->getSetting('file_extensions'),
69
      ]);
70
    }
71
72
    $field->setSetting('file_extensions', $extensions)->save();
73
  }
74
75
}
76