Skip to content

Commit

Permalink
Fixes for PHP 8.0 (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
CedNet authored Nov 30, 2020
1 parent 625e1db commit 9c56e05
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=7.2.0",
"php": "^7.2|^8.0",
"anahkiasen/html-object": "~1.4",
"illuminate/config": "~5.0|^6.0|^7.0|^8.0",
"illuminate/container": "~5.0|^6.0|^7.0|^8.0",
Expand Down
6 changes: 3 additions & 3 deletions src/Former/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static function queryToArray($query, $text = null, $attributes = null)
// Automatically fetch Lang objects for people who store translated options lists
// Same of unfetched queries
if (!$query instanceof Collection) {
if (method_exists($query, 'get')) {
if ((is_object($query) || is_string($query)) && method_exists($query, 'get')) {
$query = $query->get();
}
if (!is_array($query)) {
Expand All @@ -127,10 +127,10 @@ public static function queryToArray($query, $text = null, $attributes = null)
//Convert parametrs of old format to new format
if (!is_callable($text)) {
$optionTextValue = $text;
$text = function ($model) use($optionTextValue) {
$text = function ($model) use ($optionTextValue) {
if ($optionTextValue and isset($model->$optionTextValue)) {
return $model->$optionTextValue;
} elseif (method_exists($model, '__toString')) {
} elseif ((is_object($model) || is_string($model)) && method_exists($model, '__toString')) {
return $model->__toString();
} else {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Former/Traits/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function __call($method, $parameters)
}

// Redirect calls to the Control Group
if (method_exists($this->group, $method) or Str::startsWith($method, 'onGroup')) {
if ((!empty($this->group) && method_exists($this->group, $method)) or Str::startsWith($method, 'onGroup')) {
$method = str_replace('onGroup', '', $method);
$method = lcfirst($method);

Expand Down
2 changes: 1 addition & 1 deletion tests/Fields/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testCanCreateTextFieldWithoutFormInstance()

$input = $this->former->text('foo')->data('foo')->class('bar')->__toString();

$label = array('tag' => 'label', 'content' => 'Foo', array('for' => 'foo'));
$label = array('tag' => 'label', 'content' => 'Foo', 'attributes' => array('for' => 'foo'));
$this->assertHTML($label, $input);
$this->assertHTML($this->matchField(), $input);

Expand Down
3 changes: 2 additions & 1 deletion tests/TestCases/FormerTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use DOMNode;
use DOMDocument;
use DOMNodeList;
use PHPUnit\Framework\Exception;
use PHPUnit\Util\Xml;

/**
Expand Down Expand Up @@ -416,7 +417,7 @@ public static function assertValidKeys(array $hash, array $validKeys)
}

if (!empty($unknown)) {
throw new PHPUnit_Framework_Exception(
throw new Exception(
'Unknown key(s): ' . implode(', ', $unknown)
);
}
Expand Down

0 comments on commit 9c56e05

Please sign in to comment.