mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Minor code improvements
This commit is contained in:
parent
d4a23c1fbe
commit
d220812f5e
|
|
@ -145,7 +145,7 @@ class LogViewer
|
|||
'logger' => $data['logger'],
|
||||
'level' => $data['level'],
|
||||
'message' => $data['message'],
|
||||
'trace' => isset($data['trace']) ? $this->parseTrace($data['trace']) : null,
|
||||
'trace' => isset($data['trace']) ? self::parseTrace($data['trace']) : null,
|
||||
'context' => json_decode($data['context'], true),
|
||||
'extra' => json_decode($data['extra'], true)
|
||||
];
|
||||
|
|
|
|||
|
|
@ -62,12 +62,14 @@ class PermissionsReader
|
|||
{
|
||||
$list = [];
|
||||
foreach ($actions as $name => $action) {
|
||||
$prefixNname = $prefix . $name;
|
||||
$list[$prefixNname] = null;
|
||||
$prefixName = $prefix . $name;
|
||||
$list[$prefixName] = null;
|
||||
|
||||
// Support nested sets of actions.
|
||||
if (isset($action['actions']) && is_array($action['actions'])) {
|
||||
$list += static::read($action['actions'], "{$prefixNname}.");
|
||||
$innerList = static::read($action['actions'], "{$prefixName}.");
|
||||
|
||||
$list += $innerList;
|
||||
}
|
||||
|
||||
unset($action['actions']);
|
||||
|
|
@ -76,7 +78,7 @@ class PermissionsReader
|
|||
$action = static::addDefaults($action);
|
||||
|
||||
// Build flat list of actions.
|
||||
$list[$prefixNname] = $action;
|
||||
$list[$prefixName] = $action;
|
||||
}
|
||||
|
||||
return $list;
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ class FileCache extends AbstractCache
|
|||
*/
|
||||
protected function initFileCache($namespace, $directory)
|
||||
{
|
||||
if (!isset($directory[0])) {
|
||||
if ($directory === '') {
|
||||
$directory = sys_get_temp_dir() . '/grav-cache';
|
||||
} else {
|
||||
$directory = realpath($directory) ?: $directory;
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ class AbstractFile implements FileInterface
|
|||
$lock = $block ? LOCK_EX : LOCK_EX | LOCK_NB;
|
||||
|
||||
// Some filesystems do not support file locks, only fail if another process holds the lock.
|
||||
$this->locked = flock($this->handle, $lock, $wouldblock) || !$wouldblock;
|
||||
$this->locked = flock($this->handle, $lock, $wouldBlock) || !$wouldBlock;
|
||||
|
||||
return $this->locked;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||
namespace Grav\Framework\File\Formatter;
|
||||
|
||||
use Grav\Framework\File\Interfaces\FileFormatterInterface;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class IniFormatter
|
||||
|
|
@ -59,7 +60,7 @@ class IniFormatter extends AbstractFormatter
|
|||
$decoded = @parse_ini_string($data);
|
||||
|
||||
if ($decoded === false) {
|
||||
throw new \RuntimeException('Decoding INI failed');
|
||||
throw new RuntimeException('Decoding INI failed');
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||
namespace Grav\Framework\File\Formatter;
|
||||
|
||||
use Grav\Framework\File\Interfaces\FileFormatterInterface;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class MarkdownFormatter
|
||||
|
|
@ -99,7 +100,7 @@ class MarkdownFormatter extends AbstractFormatter
|
|||
// Normalize line endings to Unix style.
|
||||
$encoded = preg_replace("/(\r\n|\r)/u", "\n", $encoded);
|
||||
if (null === $encoded) {
|
||||
throw new \RuntimeException('Encoding markdown failed');
|
||||
throw new RuntimeException('Encoding markdown failed');
|
||||
}
|
||||
|
||||
return $encoded;
|
||||
|
|
@ -126,7 +127,7 @@ class MarkdownFormatter extends AbstractFormatter
|
|||
// Normalize line endings to Unix style.
|
||||
$data = preg_replace("/(\r\n|\r)/u", "\n", $data);
|
||||
if (null === $data) {
|
||||
throw new \RuntimeException('Decoding markdown failed');
|
||||
throw new RuntimeException('Decoding markdown failed');
|
||||
}
|
||||
|
||||
// Parse header.
|
||||
|
|
|
|||
|
|
@ -460,7 +460,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
|
|||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
public function getMetaData(string $key): array
|
||||
public function getMetaData($key): array
|
||||
{
|
||||
$object = $this->get($key);
|
||||
|
||||
|
|
|
|||
|
|
@ -140,5 +140,5 @@ interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionI
|
|||
* @param string $key Key.
|
||||
* @return array
|
||||
*/
|
||||
public function getMetaData(string $key): array;
|
||||
public function getMetaData($key): array;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,4 +43,9 @@ interface FlexFormInterface extends Serializable, FormInterface
|
|||
* @return Route|null Returns Route object or null if file uploads are not enabled.
|
||||
*/
|
||||
public function getFileDeleteAjaxRoute($field, $filename);
|
||||
|
||||
// /**
|
||||
// * @return FlexObjectInterface
|
||||
// */
|
||||
// public function getObject();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ namespace Grav\Framework\Form;
|
|||
|
||||
use Grav\Framework\Psr7\Stream;
|
||||
use InvalidArgumentException;
|
||||
use JsonSerializable;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use RuntimeException;
|
||||
|
|
@ -23,7 +24,7 @@ use function sprintf;
|
|||
* Class FormFlashFile
|
||||
* @package Grav\Framework\Form
|
||||
*/
|
||||
class FormFlashFile implements UploadedFileInterface, \JsonSerializable
|
||||
class FormFlashFile implements UploadedFileInterface, JsonSerializable
|
||||
{
|
||||
/** @var string */
|
||||
private $field;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,13 @@
|
|||
|
||||
namespace Grav\Framework\Media\Interfaces;
|
||||
|
||||
use ArrayAccess;
|
||||
use Countable;
|
||||
use Iterator;
|
||||
|
||||
/**
|
||||
* Class implements media collection interface.
|
||||
*/
|
||||
interface MediaCollectionInterface extends \ArrayAccess, \Countable, \Iterator
|
||||
interface MediaCollectionInterface extends ArrayAccess, Countable, Iterator
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ namespace Grav\Framework\Object\Base;
|
|||
|
||||
use Grav\Framework\Compat\Serializable;
|
||||
use Grav\Framework\Object\Interfaces\ObjectInterface;
|
||||
use InvalidArgumentException;
|
||||
use function call_user_func_array;
|
||||
use function get_class;
|
||||
use function is_callable;
|
||||
|
|
@ -51,6 +52,7 @@ trait ObjectCollectionTrait
|
|||
}
|
||||
|
||||
$class = get_class($this);
|
||||
|
||||
return $type . strtolower(substr($class, strrpos($class, '\\') + 1));
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +169,7 @@ trait ObjectCollectionTrait
|
|||
protected function doUnserialize(array $data)
|
||||
{
|
||||
if (!isset($data['key'], $data['type'], $data['elements']) || $data['type'] !== $this->getType()) {
|
||||
throw new \InvalidArgumentException("Cannot unserialize '{$this->getType()}': Bad data");
|
||||
throw new InvalidArgumentException("Cannot unserialize '{$this->getType()}': Bad data");
|
||||
}
|
||||
|
||||
$this->setKey($data['key']);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace Grav\Framework\Object\Collection;
|
||||
|
||||
use ArrayAccess;
|
||||
use Closure;
|
||||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
|
|
@ -42,7 +43,7 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
|
|||
$field = rtrim($field, ')');
|
||||
}
|
||||
|
||||
if (isset($object[$field])) {
|
||||
if ($object instanceof ArrayAccess && isset($object[$field])) {
|
||||
$value = $object[$field];
|
||||
} else {
|
||||
$accessors = array('', 'get', 'is');
|
||||
|
|
@ -233,7 +234,7 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
|
|||
};
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Unknown comparison operator: " . $comparison->getOperator());
|
||||
throw new RuntimeException('Unknown comparison operator: ' . $comparison->getOperator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,13 +98,8 @@ class ServerRequest implements ServerRequestInterface
|
|||
public function getCookieParam($key, $default = null)
|
||||
{
|
||||
$cookies = $this->getRequest()->getCookieParams();
|
||||
$result = $default;
|
||||
|
||||
if (isset($cookies[$key])) {
|
||||
$result = $cookies[$key];
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $cookies[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -238,13 +233,8 @@ class ServerRequest implements ServerRequestInterface
|
|||
public function getQueryParam($key, $default = null)
|
||||
{
|
||||
$getParams = $this->getQueryParams();
|
||||
$result = $default;
|
||||
|
||||
if (isset($getParams[$key])) {
|
||||
$result = $getParams[$key];
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $getParams[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace Grav\Framework\Route;
|
||||
|
||||
use Grav\Framework\Uri\Uri;
|
||||
use Grav\Framework\Uri\UriFactory;
|
||||
use InvalidArgumentException;
|
||||
use function array_slice;
|
||||
|
|
@ -318,7 +319,7 @@ class Route
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \Grav\Framework\Uri\Uri
|
||||
* @return Uri
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@ final class DeferredNodeVisitorCompat implements NodeVisitorInterface
|
|||
{
|
||||
private $hasDeferred = false;
|
||||
|
||||
/**
|
||||
* @param \Twig_NodeInterface $node
|
||||
* @param Environment $env
|
||||
* @return Node
|
||||
*/
|
||||
public function enterNode(\Twig_NodeInterface $node, Environment $env): Node
|
||||
{
|
||||
if (!$this->hasDeferred && $node instanceof DeferredBlockNode) {
|
||||
|
|
@ -33,6 +38,11 @@ final class DeferredNodeVisitorCompat implements NodeVisitorInterface
|
|||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Twig_NodeInterface $node
|
||||
* @param Environment $env
|
||||
* @return Node|null
|
||||
*/
|
||||
public function leaveNode(\Twig_NodeInterface $node, Environment $env): ?Node
|
||||
{
|
||||
if ($this->hasDeferred && $node instanceof ModuleNode) {
|
||||
|
|
@ -46,6 +56,9 @@ final class DeferredNodeVisitorCompat implements NodeVisitorInterface
|
|||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPriority() : int
|
||||
{
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user