Skip to content

Commit

Permalink
Fixed coding standards.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Oct 16, 2024
1 parent e5d92be commit f5ecd33
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 44 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"drevops/behat-screenshot": "^1.5",
"drupal/coder": "^8.3",
"dvdoug/behat-code-coverage": "^5.3",
"mglaman/phpstan-drupal": "^1.2",
"mglaman/phpstan-drupal": "^1.3",
"palantirnet/drupal-rector": "^0.20",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpcompatibility/php-compatibility": "^9.3",
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@ parameters:

scanFiles:
- vendor/behat/behat/bin/behat

drupal:
drupal_root: web
2 changes: 1 addition & 1 deletion src/ElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function elementAssertAttributeContains(string $selector, string $attribu
$attr_pattern_matched = FALSE;

foreach ($elements as $element) {
$attr = $element->getAttribute($attribute);
$attr = (string) $element->getAttribute($attribute);
if (!empty($attr)) {
$attr_found = TRUE;
// Convert wildcard pattern to regex.
Expand Down
6 changes: 3 additions & 3 deletions src/EmailTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function emailAssertEmailHeadersContains(string $header, PyStringNode $st

foreach ($this->emailGetCollectedEmails() as $record) {
$header_value = $record['headers'][$header] ?? '';
$header_value = $exact ? $header_value : trim(preg_replace('/\s+/', ' ', $header_value));
$header_value = $exact ? $header_value : trim((string) preg_replace('/\s+/', ' ', (string) $header_value));

if (str_contains((string) $header_value, $string_value)) {
return $record;
Expand Down Expand Up @@ -252,7 +252,7 @@ public function emailAssertEmailContains(string $field, PyStringNode $string, bo

foreach (self::emailGetCollectedEmails() as $record) {
$field_string = $record[$field] ?? '';
$field_string = $exact ? $field_string : trim(preg_replace('/\s+/', ' ', $field_string));
$field_string = $exact ? $field_string : trim((string) preg_replace('/\s+/', ' ', (string) $field_string));

if (str_contains((string) $field_string, $string)) {
return $record;
Expand Down Expand Up @@ -287,7 +287,7 @@ public function emailAssertEmailNotContains(string $field, PyStringNode $string,
$string = $exact ? $string : trim((string) preg_replace('/\s+/', ' ', $string));

foreach (self::emailGetCollectedEmails() as $record) {
$field_string = $exact ? $record[$field] : trim(preg_replace('/\s+/', ' ', $record[$field]));
$field_string = $exact ? $record[$field] : trim((string) preg_replace('/\s+/', ' ', (string) $record[$field]));

if (str_contains((string) $field_string, $string)) {
throw new \Exception(sprintf('Found record with%s text "%s" in field "%s" retrieved from test record collector, but should not.', ($exact ? ' exact' : ''), $string, $field));
Expand Down
12 changes: 6 additions & 6 deletions src/FieldTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ public function fieldAssertExistsState(string $field_name, string $presence, str
* @When /^(?:|I )fill color in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/
* @When /^(?:|I )fill color in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/
*/
public function fillColorField(string $field, string $value = NULL): mixed {
public function fillColorField(string $field, ?string $value = NULL): mixed {
$js = <<<JS
(function() {
var element = document.querySelector('$field');
var element = document.querySelector('{$field}');
if (!element) {
throw new Error('Element not found: $field');
throw new Error('Element not found: {$field}');
}
element.value = '$value';
element.value = '{$value}';
var event = new Event('change', { bubbles: true });
element.dispatchEvent(event);
})();
Expand All @@ -156,9 +156,9 @@ public function fillColorField(string $field, string $value = NULL): mixed {
public function assertColorFieldHasValue(string $field, string $value): void {
$js = <<<JS
(function() {
var element = document.querySelector('$field');
var element = document.querySelector('{$field}');
if (!element) {
throw new Error('Element not found: $field');
throw new Error('Element not found: {$field}');
}
return element.value;
})();
Expand Down
4 changes: 2 additions & 2 deletions src/FileDownloadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ protected function fileDownloadProcess(string $url, array $options = []): array
protected function fileDownloadParseHeaders(array $headers): array {
$parsed_headers = [];
foreach ($headers as $header) {
if (preg_match('/Content-Disposition:\s*attachment;\s*filename\s*=\s*\"([^"]+)"/', (string) $header, $matches) && isset($matches[1])) {
if (preg_match('/Content-Disposition:\s*attachment;\s*filename\s*=\s*\"([^"]+)"/', (string) $header, $matches) && !empty($matches[1])) {
$parsed_headers['file_name'] = trim($matches[1]);
continue;
}

if (preg_match('/Content-Type:\s*(.+)/', (string) $header, $matches) && isset($matches[1])) {
if (preg_match('/Content-Type:\s*(.+)/', (string) $header, $matches) && !empty($matches[1])) {
$parsed_headers['content_type'] = trim($matches[1]);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/JsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ public function iScrollToElementWithId(string $id): void {
public function assertElementAtTopOfPage(string $id): void {
$script = <<<JS
(function() {
var element = document.getElementById('$id');
var element = document.getElementById('{$id}');
var rect = element.getBoundingClientRect();
return (rect.top >= 0 && rect.top <= window.innerHeight);
})();
JS;
$result = $this->getSession()->evaluateScript($script);
if (!$result) {
throw new \Exception("Element with ID '$id' is not at the top of the page.");
throw new \Exception(sprintf("Element with ID '%s' is not at the top of the page.", $id));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/LinkTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trait LinkTrait {
* @Then I should see the link :text with :href
* @Then I should see the link :text with :href in :locator
*/
public function linkAssertTextHref(string $text, string $href, string $locator = NULL): void {
public function linkAssertTextHref(string $text, string $href, ?string $locator = NULL): void {
/** @var \Behat\Mink\Element\DocumentElement $page */
$page = $this->getSession()->getPage();

Expand Down Expand Up @@ -74,7 +74,7 @@ public function linkAssertTextHref(string $text, string $href, string $locator =
* @Then I should not see the link :text with :href
* @Then I should not see the link :text with :href in :locator
*/
public function linkAssertTextHrefNotExists(string $text, string $href, string $locator = NULL): void {
public function linkAssertTextHrefNotExists(string $text, string $href, ?string $locator = NULL): void {
/** @var \Behat\Mink\Element\DocumentElement $page */
$page = $this->getSession()->getPage();

Expand Down
4 changes: 2 additions & 2 deletions src/MediaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ protected function mediaCreateEntity(\StdClass $stub) {
*
* This is a re-use of the functionality provided by DrupalExtension.
*/
protected function mediaExpandEntityFields(string $entity_type, \StdClass $stub) {
protected function mediaExpandEntityFields(string $entity_type, \StdClass $stub): void {
$core = $this->getDriver()->getCore();

$class = new \ReflectionClass($core::class);
$method = $class->getMethod('expandEntityFields');
$method->setAccessible(TRUE);

return $method->invokeArgs($core, func_get_args());
$method->invokeArgs($core, func_get_args());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/MenuTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function menuCreate(TableNode $table): void {
// Create menu id if one not provided.
$menu_id = strtolower((string) $menu_hash['label']);
$menu_id = preg_replace('/[^a-z0-9_]+/', '_', $menu_id);
$menu_id = preg_replace('/_+/', '_', $menu_id);
$menu_id = preg_replace('/_+/', '_', (string) $menu_id);
$menu_hash['id'] = $menu_id;
}
$menu = Menu::create($menu_hash);
Expand Down
4 changes: 2 additions & 2 deletions src/ParagraphsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ protected function paragraphsFindEntity(array $conditions = []): ContentEntityIn
/**
* Expand parsed fields into expected field values based on field type.
*/
protected function paragraphsExpandEntityFields(string $entity_type, \StdClass $stub) {
protected function paragraphsExpandEntityFields(string $entity_type, \StdClass $stub): void {
$core = $this->getDriver()->getCore();

$class = new \ReflectionClass($core::class);
$method = $class->getMethod('expandEntityFields');
$method->setAccessible(TRUE);

return $method->invokeArgs($core, func_get_args());
$method->invokeArgs($core, func_get_args());
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/RoleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ trait RoleTrait {

/**
* Roles ids.
*
* @var array
*/
protected array $rolesNeedClean = [];

Expand Down
2 changes: 1 addition & 1 deletion src/WaitTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function waitForAjaxToFinish(string|int $timeout): void {
$driver->evaluateScript('true');
}
catch (UnsupportedDriverActionException) {
throw new \RuntimeException(sprintf('Method can be used only with JS-capable driver. Driver %s is not JS-capable driver', get_class($driver)));
throw new \RuntimeException(sprintf('Method can be used only with JS-capable driver. Driver %s is not JS-capable driver', $driver::class));
}

$condition = <<<JS
Expand Down
16 changes: 0 additions & 16 deletions tests/behat/features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,3 @@ Feature: Check that UserTrait works for or D9
Then I visit "/admin/people?user=administrator_user_test_last_access"
Then I should not see the text "never"
Then I should see the text "10 years ago"

@api
Scenario: Assert "Then the last access time of user :name is :time"
Given users:
| name | mail | roles | status |
| administrator_user_test_last_access | administrator_user_test_last_access@myexample.com | administrator | 1 |
Then I am logged in as a user with the "administrator" role
And I visit "/admin/people?user=administrator_user_test_last_access"
Then I should see the text "never"
Then the last access time of user "administrator_user_test_last_access" is "1406774864"
# We should not need clear cache at here. Re-check later.
Then I visit "/admin/config/development/performance"
Then I press the "Clear all cache" button
Then I visit "/admin/people?user=administrator_user_test_last_access"
Then I should not see the text "never"
Then I should see the text "10 years ago"

0 comments on commit f5ecd33

Please sign in to comment.