Skip to content

Commit

Permalink
PHP 8.1 compatibility changes (GetDKAN#3908)
Browse files Browse the repository at this point in the history
* Remove ini_set of deprecated auto_detect_line_endings
* Don’t pass a null value to json_decode()
* Consistently implement setUp() and tearDown() in tests
* Add #[\ReturnTypeWillChange] for mismatched return types
* Explicitly retype boolean to array
* Update weitzman/drupal-test-traits to 2.x version
* Simplify code complexity
* Don’t redeclare protected variable
  • Loading branch information
jastraat authored Feb 14, 2023
1 parent 9a65b1c commit 65c62bf
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 23 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"getdkan/procrastinator": "^4.0.0",
"getdkan/rooted-json-data": "^0.0.2",
"getdkan/sql-parser": "^2.0.0",
"guzzlehttp/guzzle" : "^6.3",
"guzzlehttp/guzzle" : "^6.5.8 || ^7.4.5",
"ilbee/csv-response": "^1.0",
"m1x0n/opis-json-schema-error-presenter": "^0.5.2",
"neitanod/forceutf8": "~2.0",
Expand All @@ -37,7 +37,7 @@
},
"require-dev": {
"getdkan/mock-chain": "^1.3.0",
"weitzman/drupal-test-traits": "^1.5",
"weitzman/drupal-test-traits": "^2.0.1",
"phpunit/phpunit": "^8.5.14 || ^9"
},
"repositories": {
Expand Down
4 changes: 4 additions & 0 deletions modules/common/src/DataResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public function getTableName() {
*
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
return $this->serialize();
}
Expand Down Expand Up @@ -316,6 +317,9 @@ private static function getDistribution($identifier) {
$storage = $factory->getInstance('distribution');

$distroJson = $storage->retrieve($identifier);
if (is_null($distroJson)) {
$distroJson = '';
}
return json_decode($distroJson);
}

Expand Down
1 change: 0 additions & 1 deletion modules/common/tests/src/Functional/Api1TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ abstract class Api1TestBase extends ExistingSiteBase {
use CleanUp;

protected $http;
protected $baseUrl;
protected $spec;
protected $auth;
protected $endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,9 @@ protected function runIt() {
*/
protected function getColsFromFile(string $file_path, string $delimiter): array {

// Ensure the "auto_detect_line_endings" ini setting is enabled before
// openning the file to ensure Mac style EOL characters are detected.
$old_ini = ini_set('auto_detect_line_endings', '1');
// Open the CSV file.
$f = fopen($file_path, 'r');
// Revert ini setting once the file has been opened.
if ($old_ini !== FALSE) {
ini_set('auto_detect_line_endings', $old_ini);
}

// Ensure the file could be successfully opened.
if (!isset($f) || $f === FALSE) {
throw new FileException(sprintf('Failed to open resource file "%s".', $file_path));
Expand Down
1 change: 1 addition & 0 deletions modules/datastore/src/DatastoreResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function getMimeType() {
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
return (object) [
'filePath' => $this->filePath,
Expand Down
1 change: 1 addition & 0 deletions modules/datastore/src/Storage/DatabaseTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function getSummary() {
*
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
return (object) ['resource' => $this->resource];
}
Expand Down
1 change: 1 addition & 0 deletions modules/datastore/src/Storage/TableSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function __construct(
*
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
return array_filter([
'numOfColumns' => $this->numOfColumns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function setUp(): void {
->getExternalUrl();
}

public function tearDown() {
public function tearDown(): void {
parent::tearDown();
$this->removeAllMappedFiles();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class QueryControllerTest extends TestCase {

protected function setUp() {
protected function setUp(): void {
parent::setUp();
// Set cache services
$options = (new Options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QueryDownloadControllerTest extends TestCase {

private $buffer;

protected function setUp() {
protected function setUp(): void {
parent::setUp();
// Set cache services
$options = (new Options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function setUp(): void {
$this->assertTrue($this->database instanceof DatabaseTableInterface);
}

protected function tearDown() {
protected function tearDown(): void {
parent::tearDown();
$this->database = NULL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function count(): int
return count($this->storage);
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return (object) ['storage' => $this->storage];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class WebServiceApiTest extends TestCase {
use TestHelperTrait;

protected function setUp() {
protected function setUp(): void {
parent::setUp();
// Set cache services
$options = (new Options)
Expand Down
4 changes: 2 additions & 2 deletions modules/json_form_widget/src/ValueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public function handleObjectValues($formValues, $property, $schema) {
}

$properties = array_keys((array) $schema->properties);
$data = FALSE;
$data = [];
foreach ($properties as $sub_property) {
$value = $this->flattenValues($formValues, $sub_property, $schema->properties->$sub_property);
if ($value) {
$data[$sub_property] = $value;
}
}
return $data;
return $data ?: FALSE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function getProperties($include_computed = FALSE) {
*
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function toArray() {
// @todo Implement toArray() method.
}
Expand All @@ -62,6 +63,7 @@ public function toArray() {
*
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function isEmpty() {
// @todo Implement isEmpty() method.
}
Expand All @@ -71,6 +73,7 @@ public function isEmpty() {
*
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function current() {
// @todo Implement current() method.
}
Expand All @@ -80,6 +83,7 @@ public function current() {
*
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function next() {
// @todo Implement next() method.
}
Expand All @@ -89,6 +93,7 @@ public function next() {
*
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function key() {
// @todo Implement key() method.
}
Expand All @@ -98,6 +103,7 @@ public function key() {
*
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function valid() {
// @todo Implement valid() method.
}
Expand All @@ -107,6 +113,7 @@ public function valid() {
*
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function rewind() {
// @todo Implement rewind() method.
}
Expand All @@ -116,6 +123,7 @@ public function rewind() {
*
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function onChange($name) {
// @todo Implement onChange() method.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function test() {
/**
*
*/
public function tearDown() {
public function tearDown(): void {
parent::tearDown();
$this->removeAllNodes();
$this->removeAllMappedFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function test() {
/**
*
*/
public function tearDown() {
public function tearDown(): void {
parent::tearDown();
$this->removeAllNodes();
$this->removeAllMappedFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OrphanCheckerTest extends ExistingSiteBase {
*/
protected $validMetadataFactory;

public function setUp() {
public function setUp(): void {
parent::setUp();
$this->removeHarvests();
$this->removeAllNodes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function provideFormData(): array {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();

$this->form = new DataDictionarySettingsForm($this->container->get('config.factory'));
Expand Down
2 changes: 1 addition & 1 deletion modules/metastore/tests/src/Unit/SchemaRetrieverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SchemaRetrieverTest extends TestCase {
/**
* Protected.
*/
protected function setUp() {
protected function setUp(): void {
// TODO: Change the autogenerated stub.
parent::setUp();
if (!defined("DRUPAL_MINIMUM_PHP")) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/DatasetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function setUp(): void {
$this->validMetadataFactory = ServiceTest::getValidMetadataFactory($this);
}

public function tearDown() {
public function tearDown(): void {
parent::tearDown();
$this->removeHarvests();
$this->removeAllNodes();
Expand Down

0 comments on commit 65c62bf

Please sign in to comment.