Improve Framework code

This commit is contained in:
Matias Griese 2021-12-07 13:10:19 +02:00
parent 5b84213fce
commit 70c0dc6419
8 changed files with 16 additions and 22 deletions

View File

@ -203,7 +203,7 @@ trait FormTrait
*/
public function getFiles(): array
{
return $this->files ?? [];
return $this->files;
}
/**
@ -221,8 +221,8 @@ trait FormTrait
*/
public function getDefaultValue(string $name)
{
$path = explode('.', $name) ?: [];
$offset = array_shift($path) ?? '';
$path = explode('.', $name);
$offset = array_shift($path);
$current = $this->getDefaultValues();
@ -692,7 +692,7 @@ trait FormTrait
throw new RuntimeException(sprintf('FlexForm: Bad HTTP method %s', $method));
}
$body = $request->getParsedBody();
$body = (array)$request->getParsedBody();
$data = isset($body['data']) ? $this->decodeData($body['data']) : null;
$flash = $this->getFlash();
@ -799,9 +799,7 @@ trait FormTrait
// Decode JSON encoded fields and merge them to data.
if (isset($data['_json'])) {
$data = array_replace_recursive($data, $this->jsonDecode($data['_json']));
if (null === $data) {
throw new RuntimeException(__METHOD__ . '(): Unexpected error');
}
unset($data['_json']);
}

View File

@ -42,8 +42,8 @@ trait NestedPropertyTrait
public function getNestedProperty($property, $default = null, $separator = null)
{
$separator = $separator ?: '.';
$path = explode($separator, $property) ?: [];
$offset = array_shift($path) ?? '';
$path = explode($separator, $property);
$offset = array_shift($path);
if (!$this->hasProperty($offset)) {
return $default;
@ -85,8 +85,8 @@ trait NestedPropertyTrait
public function setNestedProperty($property, $value, $separator = null)
{
$separator = $separator ?: '.';
$path = explode($separator, $property) ?: [];
$offset = array_shift($path) ?? '';
$path = explode($separator, $property);
$offset = array_shift($path);
if (!$path) {
$this->setProperty($offset, $value);
@ -127,8 +127,8 @@ trait NestedPropertyTrait
public function unsetNestedProperty($property, $separator = null)
{
$separator = $separator ?: '.';
$path = explode($separator, $property) ?: [];
$offset = array_shift($path) ?? '';
$path = explode($separator, $property);
$offset = array_shift($path);
if (!$path) {
$this->unsetProperty($offset);

View File

@ -97,7 +97,7 @@ trait ArrayPropertyTrait
*/
protected function getElements()
{
return array_filter($this->_elements, function ($val) {
return array_filter($this->_elements, static function ($val) {
return $val !== null;
});
}

View File

@ -87,8 +87,7 @@ trait LazyPropertyTrait
*/
protected function doUnsetProperty($property)
{
$this->hasObjectProperty($property) ?
$this->unsetObjectProperty($property) : $this->unsetArrayProperty($property);
$this->hasObjectProperty($property) ? $this->unsetObjectProperty($property) : $this->unsetArrayProperty($property);
}
/**

View File

@ -41,7 +41,7 @@ abstract class AbstractPaginationPage implements PaginationPageInterface
*/
public function getOptions(): array
{
return $this->options ?? [];
return $this->options;
}
/**

View File

@ -258,7 +258,7 @@ class Response implements ResponseInterface
}
$output .= self::EOL;
$output .= (string) $response->getBody();
$output .= $response->getBody();
return $output;
}

View File

@ -24,9 +24,6 @@ class Uri implements UriInterface
{
use UriDecorationTrait;
/** @var array Array of Uri query. */
private $queryParams;
public function __construct(string $uri = '')
{
$this->uri = new \Nyholm\Psr7\Uri($uri);

View File

@ -30,7 +30,7 @@ parameters:
# These checks are new in phpstan 1, ignore them for now.
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
#checkGenericClassInNonGenericObjectType: false
universalObjectCratesClasses:
- Grav\Common\Config\Config