Skip to content

Commit

Permalink
Minor refactor. Phpstan fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ragnarkurmwunder committed Apr 19, 2022
1 parent 6677f91 commit dc31637
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 119 deletions.
4 changes: 3 additions & 1 deletion .lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ tooling:
- php -l _ping.custom.php
- php -l _ping.php
- php -l settings.php
- ./vendor/bin/phpcs -sp --report=full --runtime-set testVersion 7.4 --standard=Drupal,DrupalPractice,Security,PHPCompatibility,VariableAnalysis,WunderDrupal,WunderSecurity _ping.php _ping.custom.php settings.php
- php -l phpstan-drupal9-autoload.php
- ./vendor/bin/phpcs -sp --report=full --runtime-set testVersion 7.4 --standard=Drupal,DrupalPractice,Security,PHPCompatibility,VariableAnalysis,WunderDrupal,WunderSecurity _ping.php _ping.custom.php settings.php phpstan-drupal9-autoload.php
- ./vendor/bin/phpstan analyze --level=5 --autoload-file phpstan-drupal9-autoload.php -- _ping.php _ping.custom.php settings.php phpstan-drupal9-autoload.php

version: 3.6.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Following statuses are issued:
* `disabled` - No Elasticsearch servers defined in settings
* `success` - All connections succeed
* `warning` - At least one connection failed, and all failed connections have been configured with 'severity' = 'warning'
* `error` - At least one connection failed, and all failed connections have been configured with 'severity' = 'error'
* `error` - At least one connection failed, and at least one of the failed connections have been configured with 'severity' = 'error'

### FS Scheme

Expand Down
17 changes: 6 additions & 11 deletions _ping.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ abstract class Checker {
*
* @var string
*/
protected $status = NULL;
protected $status = '';

/**
* The name of the checker.
Expand All @@ -414,7 +414,7 @@ public function getName(): string {
}

/**
* Return chekcer status.
* Return checker status.
*
* @return array
* Array of [
Expand Down Expand Up @@ -455,7 +455,7 @@ public function getStatusInfo(): array {
* The purpose of this function is to catch exceptions.
*/
public function check(): void {
$this->status = NULL;
$this->status = '';
try {
$this->status = $this->check2();
}
Expand Down Expand Up @@ -687,6 +687,8 @@ protected function check2(): string {
// Errors.
return '';
}

return 'internal_error';
}

}
Expand Down Expand Up @@ -948,7 +950,7 @@ protected function check2(): string {
* Hmm.
*/
// @codingStandardsIgnoreLine Drupal.NamingConventions.ValidFunctionName.NotCamelCaps
function file_uri_scheme($uri) {
function file_uri_scheme($uri) { // @phpstan-ignore-line
return \Drupal::service('file_system')->uriScheme($uri);
}

Expand Down Expand Up @@ -1238,13 +1240,6 @@ class Status {
*/
private $items = [];

/**
* Holds name of currently executing context.
*
* @var string
*/
private $name;

/**
* Set status for the current context.
*
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
}
],
"keywords": [
"drupal","ping","healthcheck"
"drupal",
"ping",
"healthcheck"
],
"require": {
"drupal/core": "~8.0 || ~9.0",
"koodimonni/composer-dropin-installer": ">=1.0.1"
},
"require-dev": {
Expand Down
31 changes: 31 additions & 0 deletions phpstan-drupal9-autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* @file
* Autoloader for php stan to be able to reach all functions.
*/

require_once '/app/drupal9/vendor//symfony/http-foundation/Request.php';

require_once '/app/drupal9/web/core/lib/Drupal/Core/Installer/InstallerRedirectTrait.php';
require_once '/app/drupal9/vendor/symfony/http-kernel/TerminableInterface.php';
require_once '/app/drupal9/vendor/symfony/http-kernel/HttpKernelInterface.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/DrupalKernelInterface.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/DrupalKernel.php';

require_once '/app/drupal9/web/core/lib/Drupal/Core/Site/Settings.php';

require_once '/app/drupal9/web/core/lib/Drupal/Core/Database/StatementInterface.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/Database/Connection.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/Database/Database.php';

require_once '/app/drupal9/web/core/lib/Drupal/Core/Cache/CacheableDependencyTrait.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/Cache/CacheableDependencyInterface.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/Cache/RefinableCacheableDependencyInterface.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/Config/ConfigBase.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/Config/StorableConfigBase.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/Config/Config.php';
require_once '/app/drupal9/web/core/lib/Drupal/Core/Config/ImmutableConfig.php';
require_once '/app/drupal9//web/core/lib/Drupal.php';
9 changes: 1 addition & 8 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
class AppTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
$b = new BootstrapChecker();
$b->check();
require_once 'init.php';
}

/**
Expand Down
10 changes: 1 addition & 9 deletions tests/BootstrapCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
class BootstrapCheckerTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
global $_bootstrapChecker;
$_bootstrapChecker = new BootstrapChecker();
$_bootstrapChecker->check();
require_once 'init.php';
}

/**
Expand Down
9 changes: 1 addition & 8 deletions tests/CheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
use \PHPUnit\Framework\TestCase;

// we need to import Checker class before we can extend it.
if (!class_exists('App')) {
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
global $_bootstrapChecker;
$_bootstrapChecker = new BootstrapChecker();
$_bootstrapChecker->check();
}
require_once 'init.php';

class DummyChecker extends Checker {

Expand Down
10 changes: 1 addition & 9 deletions tests/CustomPingCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
class CustomPingCheckerTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
global $_bootstrapChecker;
$_bootstrapChecker = new BootstrapChecker();
$_bootstrapChecker->check();
require_once 'init.php';
}

/**
Expand Down
10 changes: 1 addition & 9 deletions tests/DbCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@
class DbCheckerTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
global $_bootstrapChecker;
$_bootstrapChecker = new BootstrapChecker();
$_bootstrapChecker->check();
require_once 'init.php';
}

/**
Expand Down
10 changes: 1 addition & 9 deletions tests/ElasticsearchCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
class ElasticsearchCheckerTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
global $_bootstrapChecker;
$_bootstrapChecker = new BootstrapChecker();
$_bootstrapChecker->check();
require_once 'init.php';
}

/**
Expand Down
10 changes: 1 addition & 9 deletions tests/FsSchemeCreateCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
class FsSchemeCreateCheckerTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
global $_bootstrapChecker;
$_bootstrapChecker = new BootstrapChecker();
$_bootstrapChecker->check();
require_once 'init.php';
}

/**
Expand Down
10 changes: 1 addition & 9 deletions tests/FsSchemeDeleteCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
class FsSchemeDeleteCheckerTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
global $_bootstrapChecker;
$_bootstrapChecker = new BootstrapChecker();
$_bootstrapChecker->check();
require_once 'init.php';
}

/**
Expand Down
10 changes: 1 addition & 9 deletions tests/MemcacheCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
class MemcacheCheckerTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
global $_bootstrapChecker;
$_bootstrapChecker = new BootstrapChecker();
$_bootstrapChecker->check();
require_once 'init.php';
}

/**
Expand Down
9 changes: 1 addition & 8 deletions tests/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
class ProfileTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
$b = new BootstrapChecker();
$b->check();
require_once 'init.php';
}

/**
Expand Down
10 changes: 1 addition & 9 deletions tests/RedisCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
class RedisCheckerTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
global $_bootstrapChecker;
$_bootstrapChecker = new BootstrapChecker();
$_bootstrapChecker->check();
require_once 'init.php';
}

/**
Expand Down
9 changes: 1 addition & 8 deletions tests/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
class StatusTest extends TestCase {

public static function setUpBeforeClass(): void {
if (class_exists('App')) {
return;
}
chdir('/app/drupal9/web');
putenv('TESTING=1');
require '_ping.php';
$b = new BootstrapChecker();
$b->check();
require_once 'init.php';
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

if (!class_exists('App')) {
chdir('/app/drupal9/web');
putenv('TESTING=1');
require_once '_ping.php';
global $_bootstrapChecker;
$_bootstrapChecker = new BootstrapChecker();
$_bootstrapChecker->check();
}

0 comments on commit dc31637

Please sign in to comment.