Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
agentrickard committed Nov 9, 2023
1 parent ff50383 commit f019e3d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 27 deletions.
6 changes: 2 additions & 4 deletions modules/tester_error_generator/src/TesterErrorClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
class TesterErrorClass {

/**
* Sets a dynamic property, value.
*
* @return void
* Sets a dynamic property to trigger a warning.
*/
public function testDynamicProperty() {
public function testDynamicProperty(): void {
$this->value = 'dynamic property error';
}

Expand Down
10 changes: 8 additions & 2 deletions modules/tester_error_generator/tester_error_generator.module
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php

use \Drupal\tester_error_generator\TesterErrorClass;
/**
* @file
* A small module that deliberately throws errors.
*/

use Drupal\tester_error_generator\TesterErrorClass;

/**
* Implements hook_page_top().
Expand Down Expand Up @@ -29,9 +34,10 @@ function tester_error_generator_page_top(&$page_top) {
break;

case 4:
$test = t('Generate class errors');
$text = t('Generate class errors');
$testcase = new TesterErrorClass();
$testcase->testDynamicProperty();
break;

default:
$text = t('The <em>tester_error_generator</em> module should not be used in production');
Expand Down
21 changes: 10 additions & 11 deletions src/Commands/TesterCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Drupal\tester\Commands;

use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drupal\tester\TesterPluginManager;
use Drush\Commands\DrushCommands;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Connection;
Expand All @@ -14,7 +12,8 @@
use Drupal\Core\Http\ClientFactory;
use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use GuzzleHttp\Cookie\SessionCookieJar;
use Drupal\tester\TesterPluginManager;
use Drush\Commands\DrushCommands;
use GuzzleHttp\Cookie\CookieJar;

/**
Expand Down Expand Up @@ -88,7 +87,7 @@ class TesterCommands extends DrushCommands {
protected $errorLog = [];

/**
* The admin user
* The admin user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
Expand All @@ -113,7 +112,6 @@ class TesterCommands extends DrushCommands {
* The database connection.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*
*/
public function __construct(TesterPluginManager $plugin_manager, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ClientFactory $http_client_factory, ConfigFactoryInterface $config_factory, StateInterface $state, Connection $database, EntityTypeManagerInterface $entity_type_manager) {
$this->pluginManager = $plugin_manager;
Expand Down Expand Up @@ -200,7 +198,7 @@ public function crawl($base_url = NULL, array $options = ['test' => NULL, 'limit
$this->io()->title("Crawling URLs");

if (is_null($base_url)) {
GLOBAL $base_url;
global $base_url;
}

$urls = array_unique($this->getUrls($options));
Expand Down Expand Up @@ -246,7 +244,7 @@ public function crawl($base_url = NULL, array $options = ['test' => NULL, 'limit
$response = $this->httpClient->request('GET', $path, $options);
$this->io()->progressAdvance();

$this->setErrorLog($path,['response' => $response->getStatusCode()]);
$this->setErrorLog($path, ['response' => $response->getStatusCode()]);
$this->captureErrors($path);

// @todo Move to a render function?
Expand Down Expand Up @@ -287,7 +285,6 @@ public function crawl($base_url = NULL, array $options = ['test' => NULL, 'limit
$this->io()->success($message);
}


return new RowsOfFields($rows);
}

Expand All @@ -312,7 +309,6 @@ public function chooseOptions() {
return $options;
}


/**
* Retrieves the list of URLs to test.
*
Expand Down Expand Up @@ -358,7 +354,8 @@ private function isAllowed(array $dependencies) {
switch ($type) {
case "modules":
default:
foreach ($extensions as $extension) {}
foreach ($extensions as $extension) {
}
if (!$this->moduleHandler->moduleExists($extension)) {
$return = FALSE;
}
Expand Down Expand Up @@ -450,9 +447,11 @@ public function getErrorLog($path, $value) {
case 'response':
$return = $this->errorLog[$path][$value] ?: NULL;
break;

case 'errors':
$return = $this->errorLog[$path][$value] ?: [];
break;

default:
$return = $this->errorLog[$path][$value] ?: 0;
break;
Expand Down Expand Up @@ -484,7 +483,7 @@ public function setErrorLog($path, array $values) {
*
* We do this so we can query the errors specific to a path.
*
* @return integer
* @return int
* The count.
*/
protected function getWatchdogCount() {
Expand Down
7 changes: 2 additions & 5 deletions src/Plugin/Tester/MenuTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Drupal\tester\Plugin\Tester;

use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Link;
use Drupal\Core\Menu\MenuLinkTreeElement;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\tester\Plugin\TesterPluginInterface;

Expand All @@ -14,7 +12,6 @@
* @TesterPlugin(
* id = "menu",
* )
*
*/
class MenuTester extends PluginBase implements TesterPluginInterface {

Expand All @@ -25,7 +22,7 @@ public function urls(array $options) {
$urls = [];
// @todo Figure out how to inject this service.
$storage = \Drupal::menuTree();
$parameters = new MenuTreeParameters;
$parameters = new MenuTreeParameters();
// Normalize menu options to array.
$options['menus'] = explode(',', $options['menus']);

Expand Down Expand Up @@ -69,7 +66,7 @@ public function buildUrls($tree, array &$urls) {
$string = $url->toString();
// Ignore any token paths, which break logins.
// And explicitly do not log out.
if (!str_contains($string, '?token=') && !str_contains($string, 'user/logout') ) {
if (!str_contains($string, '?token=') && !str_contains($string, 'user/logout')) {
$urls[] = $string;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Plugin/Tester/NodeTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* @TesterPlugin(
* id = "node",
* )
*
*/
class NodeTester extends PluginBase implements TesterPluginInterface {

Expand Down
1 change: 0 additions & 1 deletion src/Plugin/Tester/SystemTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* @TesterPlugin(
* id = "system",
* )
*
*/
class SystemTester extends PluginBase implements TesterPluginInterface {

Expand Down
1 change: 0 additions & 1 deletion src/Plugin/Tester/UserTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* @TesterPlugin(
* id = "user",
* )
*
*/
class UserTester extends PluginBase implements TesterPluginInterface {

Expand Down
6 changes: 5 additions & 1 deletion src/Plugin/TesterPluginInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use Drupal\Component\Plugin\PluginInspectionInterface;

/**
*
*/
interface TesterPluginInterface extends PluginInspectionInterface {

/**
* Returns an array of URLs for testing.
*
* @param integer $options
* @param int $options
* The options passed to the command.
*
* @return array
Expand All @@ -27,4 +30,5 @@ public function urls(array $options);
* @return array
*/
public function dependencies();

}
2 changes: 1 addition & 1 deletion src/TesterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Drupal\tester;

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;

/**
* Tester plugin manager.
Expand Down

0 comments on commit f019e3d

Please sign in to comment.