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 ( 60568e...519fd1 )
by Devin
05:14
created

MiscellaneousContext::openModerationSidebar()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 16
rs 9.4285
1
<?php
2
3
namespace Acquia\DFExtension\Context;
4
5
use Acquia\LightningExtension\AwaitTrait;
6
use Acquia\LightningExtension\Context\PanelsInPlaceContext;
7
use Acquia\LightningExtension\Context\UtilityContext;
8
use Drupal\DrupalExtension\Context\DrupalSubContextBase;
9
10
/**
11
 * A context with miscellaneous helpers.
12
 */
13
class MiscellaneousContext extends DrupalSubContextBase {
14
15
  use AwaitTrait;
16
17
  /**
18
   * Close the Panels IPE tray.
19
   *
20
   * @When I close the editor
21
   */
22
  public function closeEditor() {
23
    $assert = $this->assertSession();
24
25
    $panelsinplace = $this->getContext(PanelsInPlaceContext::class);
26
27
    // Assert that the tab exists...
28
    $link = $assert->elementExists(
29
      'named',
30
      ['link', 'Cancel'],
31
      $assert->elementExists('css', '.ipe-tabs', $panelsinplace->assertTray())
32
    );
33
34
    $link->click();
35
36
    /** @var \Acquia\LightningExtension\Context\UtilityContext $utility */
37
    $utility = $this->getContext(UtilityContext::class);
38
    $utility->acceptAlerts(function () {
39
      $this->awaitAjax();
40
    });
41
  }
42
43
  /**
44
   * "Manually" writes text into a field.
45
   *
46
   * @param string $text
47
   *   The text to write into the field.
48
   * @param string $field
49
   *   The label, placeholder, ID or name of the field.
50
   *
51
   * @Given I write :text into :field
52
   */
53
  public function iWriteTextIntoField($text, $field) {
54
    $this->getSession()
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Behat\Mink\Driver\DriverInterface as the method getWebDriverSession() does only exist in the following implementations of said interface: Behat\Mink\Driver\Selenium2Driver.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
55
      ->getDriver()
56
      ->getWebDriverSession()
57
      ->element('xpath', $this->getSession()->getSelectorsHandler()->selectorToXpath('named_exact', array('field', $field)))
58
      ->postValue(['value' => [$text]]);
59
  }
60
61
  /**
62
   * Asserts that the current page is an admin page.
63
   *
64
   * @Then The page should be an admin page
65
   */
66
  public function assertAdminPage() {
67
    /** @var \Drupal\Core\Routing\AdminContext $admin_context */
68
    $admin_context = \Drupal::service('router.admin_context');
69
    return $admin_context->isAdminRoute();
70
  }
71
72
}
73