Update Framework classes to use PHP 7.1 syntax

This commit is contained in:
Matias Griese
2018-09-12 14:23:13 +03:00
parent 9444b63f8b
commit a358f2953a
46 changed files with 316 additions and 92 deletions

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Cache
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Cache
*
@@ -48,7 +49,7 @@ class ChainCache extends AbstractCache
throw new InvalidArgumentException(
sprintf(
"The class '%s' does not implement the '%s' interface",
get_class($cache),
\get_class($cache),
CacheInterface::class
)
);
@@ -56,7 +57,7 @@ class ChainCache extends AbstractCache
}
$this->caches = array_values($caches);
$this->count = count($caches);
$this->count = \count($caches);
}
/**

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Cache
*
@@ -10,7 +11,6 @@ namespace Grav\Framework\Cache\Adapter;
use Doctrine\Common\Cache\CacheProvider;
use Grav\Framework\Cache\AbstractCache;
use Grav\Framework\Cache\Exception\InvalidArgumentException;
/**
* Cache class for PSR-16 compatible "Simple Cache" implementation using Doctrine Cache backend.
@@ -100,16 +100,6 @@ class DoctrineCache extends AbstractCache
*/
public function doDeleteMultiple($keys)
{
// TODO: Remove when Doctrine Cache has been updated to support the feature.
if (!method_exists($this->driver, 'deleteMultiple')) {
$success = true;
foreach ($keys as $key) {
$success = $this->delete($key) && $success;
}
return $success;
}
return $this->driver->deleteMultiple($keys);
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Cache
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Cache
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Cache
*
@@ -66,7 +67,7 @@ class SessionCache extends AbstractCache
protected function doGetStored($key)
{
$stored = isset($_SESSION[$this->getNamespace()][$key]) ? $_SESSION[$this->getNamespace()][$key] : null;
$stored = $_SESSION[$this->getNamespace()][$key] ?? null;
if (isset($stored[self::LIFETIME]) && $stored[self::LIFETIME] < time()) {
unset($_SESSION[$this->getNamespace()][$key]);

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Cache
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Cache
*
@@ -120,11 +121,11 @@ trait CacheTrait
{
if ($keys instanceof \Traversable) {
$keys = iterator_to_array($keys, false);
} elseif (!is_array($keys)) {
} elseif (!\is_array($keys)) {
throw new InvalidArgumentException(
sprintf(
'Cache keys must be array or Traversable, "%s" given',
is_object($keys) ? get_class($keys) : gettype($keys)
\is_object($keys) ? \get_class($keys) : \gettype($keys)
)
);
}
@@ -164,7 +165,7 @@ trait CacheTrait
throw new InvalidArgumentException(
sprintf(
'Cache values must be array or Traversable, "%s" given',
is_object($values) ? get_class($values) : gettype($values)
\is_object($values) ? \get_class($values) : \gettype($values)
)
);
}
@@ -195,7 +196,7 @@ trait CacheTrait
throw new InvalidArgumentException(
sprintf(
'Cache keys must be array or Traversable, "%s" given',
is_object($keys) ? get_class($keys) : gettype($keys)
\is_object($keys) ? \get_class($keys) : \gettype($keys)
)
);
}
@@ -283,20 +284,20 @@ trait CacheTrait
*/
protected function validateKey($key)
{
if (!is_string($key)) {
if (!\is_string($key)) {
throw new InvalidArgumentException(
sprintf(
'Cache key must be string, "%s" given',
is_object($key) ? get_class($key) : gettype($key)
\is_object($key) ? \get_class($key) : \gettype($key)
)
);
}
if (!isset($key[0])) {
throw new InvalidArgumentException('Cache key length must be greater than zero');
}
if (strlen($key) > 64) {
if (\strlen($key) > 64) {
throw new InvalidArgumentException(
sprintf('Cache key length must be less than 65 characters, key had %s characters', strlen($key))
sprintf('Cache key length must be less than 65 characters, key had %s characters', \strlen($key))
);
}
if (strpbrk($key, '{}()/\@:') !== false) {
@@ -332,7 +333,7 @@ trait CacheTrait
return $this->getDefaultLifetime();
}
if (is_int($ttl)) {
if (\is_int($ttl)) {
return $ttl;
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Cache
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Cache
*

View File

@@ -95,7 +95,7 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
if ($orderings = $criteria->getOrderings()) {
$next = null;
foreach (array_reverse($orderings) as $field => $ordering) {
$next = ClosureExpressionVisitor::sortByField($field, $ordering == Criteria::DESC ? -1 : 1, $next);
$next = ClosureExpressionVisitor::sortByField($field, $ordering === Criteria::DESC ? -1 : 1, $next);
}
uasort($filtered, $next);
@@ -107,7 +107,7 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
$length = $criteria->getMaxResults();
if ($offset || $length) {
$filtered = array_slice($filtered, (int)$offset, $length);
$filtered = \array_slice($filtered, (int)$offset, $length);
}
return new ArrayCollection($filtered);

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\ContentBlock
*
@@ -104,7 +105,7 @@ class ContentBlock implements ContentBlockInterface
}
$array = [
'_type' => get_class($this),
'_type' => \get_class($this),
'_version' => $this->version,
'id' => $this->id
];
@@ -163,8 +164,8 @@ class ContentBlock implements ContentBlockInterface
{
$this->checkVersion($serialized);
$this->id = isset($serialized['id']) ? $serialized['id'] : $this->generateId();
$this->checksum = isset($serialized['checksum']) ? $serialized['checksum'] : null;
$this->id = $serialized['id'] ?? $this->generateId();
$this->checksum = $serialized['checksum'] ?? null;
if (isset($serialized['content'])) {
$this->setContent($serialized['content']);

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\ContentBlock
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\ContentBlock
*
@@ -131,7 +132,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
*/
public function addStyle($element, $priority = 0, $location = 'head')
{
if (!is_array($element)) {
if (!\is_array($element)) {
$element = ['href' => (string) $element];
}
if (empty($element['href'])) {
@@ -175,7 +176,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
*/
public function addInlineStyle($element, $priority = 0, $location = 'head')
{
if (!is_array($element)) {
if (!\is_array($element)) {
$element = ['content' => (string) $element];
}
if (empty($element['content'])) {
@@ -206,7 +207,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
*/
public function addScript($element, $priority = 0, $location = 'head')
{
if (!is_array($element)) {
if (!\is_array($element)) {
$element = ['src' => (string) $element];
}
if (empty($element['src'])) {
@@ -243,7 +244,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
*/
public function addInlineScript($element, $priority = 0, $location = 'head')
{
if (!is_array($element)) {
if (!\is_array($element)) {
$element = ['content' => (string) $element];
}
if (empty($element['content'])) {
@@ -274,7 +275,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
*/
public function addHtml($html, $priority = 0, $location = 'bottom')
{
if (empty($html) || !is_string($html)) {
if (empty($html) || !\is_string($html)) {
return false;
}
if (!isset($this->html[$location])) {
@@ -302,7 +303,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
];
foreach ($this->blocks as $block) {
if ($block instanceof HtmlBlock) {
if ($block instanceof self) {
$blockAssets = $block->getAssetsFast();
$assets['frameworks'] += $blockAssets['frameworks'];

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\ContentBlock
*

View File

@@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @package Grav\Framework\File
*
@@ -8,7 +11,9 @@
namespace Grav\Framework\File;
class AbstractFile
use Grav\Framework\File\Interfaces\FileInterface;
class AbstractFile implements FileInterface
{
/** @var string */
private $filepath;
@@ -58,7 +63,7 @@ class AbstractFile
*
* @return string
*/
public function getFilePath()
public function getFilePath() : string
{
return $this->filepath;
}
@@ -68,7 +73,7 @@ class AbstractFile
*
* @return string
*/
public function getPath()
public function getPath() : string
{
if (null === $this->path) {
$this->setPathInfo();
@@ -82,7 +87,7 @@ class AbstractFile
*
* @return string
*/
public function getFilename()
public function getFilename() : string
{
if (null === $this->filename) {
$this->setPathInfo();
@@ -96,7 +101,7 @@ class AbstractFile
*
* @return string
*/
public function getBasename()
public function getBasename() : string
{
if (null === $this->basename) {
$this->setPathInfo();
@@ -111,7 +116,7 @@ class AbstractFile
* @param $withDot
* @return string
*/
public function getExtension($withDot = false)
public function getExtension($withDot = false) : string
{
if (null === $this->extension) {
$this->setPathInfo();
@@ -125,7 +130,7 @@ class AbstractFile
*
* @return bool
*/
public function exists()
public function exists() : bool
{
return is_file($this->filepath);
}
@@ -157,7 +162,7 @@ class AbstractFile
* @return bool
* @throws \RuntimeException
*/
public function lock($block = true)
public function lock($block = true) : bool
{
if (!$this->handle) {
if (!$this->mkdir($this->getPath())) {
@@ -179,7 +184,7 @@ class AbstractFile
*
* @return bool
*/
public function unlock()
public function unlock() : bool
{
if (!$this->handle) {
return false;
@@ -199,7 +204,7 @@ class AbstractFile
*
* @return bool True = locked, false = not locked.
*/
public function isLocked()
public function isLocked() : bool
{
return $this->locked;
}
@@ -209,7 +214,7 @@ class AbstractFile
*
* @return bool
*/
public function isWritable()
public function isWritable() : bool
{
return is_writable($this->filepath) || $this->isWritableDir($this->getPath());
}
@@ -261,7 +266,7 @@ class AbstractFile
* @param string $path
* @return bool
*/
public function rename($path)
public function rename($path) : bool
{
if ($this->exists() && !@rename($this->filepath, $path)) {
return false;
@@ -277,7 +282,7 @@ class AbstractFile
*
* @return bool
*/
public function delete()
public function delete() : bool
{
return @unlink($this->filepath);
}
@@ -288,7 +293,7 @@ class AbstractFile
* @throws \RuntimeException
* @internal
*/
protected function mkdir($dir)
protected function mkdir($dir) : bool
{
// Silence error for open_basedir; should fail in mkdir instead.
if (!@is_dir($dir)) {
@@ -309,7 +314,7 @@ class AbstractFile
* @return bool
* @internal
*/
protected function isWritableDir($dir)
protected function isWritableDir($dir) : bool
{
if ($dir && !file_exists($dir)) {
return $this->isWritableDir(dirname($dir));
@@ -318,7 +323,7 @@ class AbstractFile
return $dir && is_dir($dir) && is_writable($dir);
}
protected function setFilepath($filepath)
protected function setFilepath($filepath) : void
{
$this->filepath = $filepath;
$this->filename = null;
@@ -327,7 +332,7 @@ class AbstractFile
$this->extension = null;
}
protected function setPathInfo()
protected function setPathInfo() : void
{
$pathInfo = static::pathinfo($this->filepath);
$this->filename = $pathInfo['filename'];

View File

@@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @package Grav\Framework\File
*
@@ -51,7 +54,7 @@ class DataFile extends AbstractFile
*/
public function save($data)
{
if (is_string($data)) {
if (\is_string($data)) {
try {
$this->formatter->decode($data);
} catch (\RuntimeException $e) {

View File

@@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @package Grav\Framework\File
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\File\Formatter
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\File\Formatter
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\File\Formatter
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\File\Formatter
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\File\Formatter
*
@@ -84,9 +85,9 @@ class SerializeFormatter implements FormatterInterface
*/
protected function preserveLines($data, $search, $replace)
{
if (is_string($data)) {
if (\is_string($data)) {
$data = str_replace($search, $replace, $data);
} elseif (is_array($data)) {
} elseif (\is_array($data)) {
foreach ($data as &$value) {
$value = $this->preserveLines($value, $search, $replace);
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\File\Formatter
*
@@ -80,7 +81,7 @@ class YamlFormatter implements FormatterInterface
public function decode($data)
{
// Try native PECL YAML PHP extension first if available.
if ($this->config['native'] && function_exists('yaml_parse')) {
if (\function_exists('yaml_parse') && $this->config['native']) {
// Safely decode YAML.
$saved = @ini_get('yaml.decode_php');
@ini_set('yaml.decode_php', 0);

View File

@@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @package Grav\Framework\File
*

View File

@@ -0,0 +1,153 @@
<?php
declare(strict_types=1);
/**
* @package Grav\Framework\File
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\File\Interfaces;
interface FileInterface
{
public function __construct($filepath);
/**
* Unlock file when the object gets destroyed.
*/
public function __destruct();
/**
* Get full path to the file.
*
* @return string
*/
public function getFilePath() : string;
/**
* Get path to the file.
*
* @return string
*/
public function getPath() : string;
/**
* Get filename.
*
* @return string
*/
public function getFilename() : string;
/**
* Return name of the file without extension.
*
* @return string
*/
public function getBasename() : string;
/**
* Return file extension.
*
* @param $withDot
* @return string
*/
public function getExtension($withDot = false) : string;
/**
* Check if file exits.
*
* @return bool
*/
public function exists() : bool;
/**
* Return file modification time.
*
* @return int|bool Timestamp or false if file doesn't exist.
*/
public function getCreationTime();
/**
* Return file modification time.
*
* @return int|bool Timestamp or false if file doesn't exist.
*/
public function getModificationTime();
/**
* Lock file for writing. You need to manually unlock().
*
* @param bool $block For non-blocking lock, set the parameter to false.
* @return bool
* @throws \RuntimeException
*/
public function lock($block = true) : bool;
/**
* Unlock file.
*
* @return bool
*/
public function unlock() : bool;
/**
* Returns true if file has been locked for writing.
*
* @return bool True = locked, false = not locked.
*/
public function isLocked() : bool;
/**
* Check if file can be written.
*
* @return bool
*/
public function isWritable() : bool;
/**
* (Re)Load a file and return RAW file contents.
*
* @return string
*/
public function load();
/**
* Save file.
*
* @param mixed $data
* @throws \RuntimeException
*/
public function save($data);
/**
* Rename file in the filesystem if it exists.
*
* @param string $path
* @return bool
*/
public function rename($path) : bool;
/**
* Delete file from filesystem.
*
* @return bool
*/
public function delete() : bool;
/**
* Multi-byte-safe pathinfo replacement.
* Replacement for pathinfo(), but stream, multibyte and cross-platform safe.
*
* @see http://www.php.net/manual/en/function.pathinfo.php
*
* @param string $path A filename or path, does not need to exist as a file
* @param int|string $options Either a PATHINFO_* constant,
* or a string name to return only the specified piece
*
* @return string|array
*/
public static function pathinfo($path, $options = null);
}

View File

@@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @package Grav\Framework\File
*

View File

@@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @package Grav\Framework\File
*

View File

@@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @package Grav\Framework\File
*

View File

@@ -1,4 +1,12 @@
<?php
/**
* @package Grav\Framework\Media
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Media\Interfaces;
/**

View File

@@ -1,4 +1,12 @@
<?php
/**
* @package Grav\Framework\Media
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Media\Interfaces;
/**

View File

@@ -2,6 +2,13 @@
declare(strict_types=1);
/**
* @package Grav\Framework\Media
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Media\Interfaces;
use Grav\Common\Media\Interfaces\MediaInterface;

View File

@@ -1,4 +1,12 @@
<?php
/**
* @package Grav\Framework\Media
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Media\Interfaces;
/**

View File

@@ -58,9 +58,9 @@ trait NestedPropertyTrait
$offset = array_shift($path);
if ((is_array($current) || is_a($current, 'ArrayAccess')) && isset($current[$offset])) {
if ((\is_array($current) || is_a($current, 'ArrayAccess')) && isset($current[$offset])) {
$current = $current[$offset];
} elseif (is_object($current) && isset($current->{$offset})) {
} elseif (\is_object($current) && isset($current->{$offset})) {
$current = $current->{$offset};
} else {
return $default;
@@ -98,7 +98,7 @@ trait NestedPropertyTrait
// Handle arrays and scalars.
if ($current === null) {
$current = [$offset => []];
} elseif (is_array($current)) {
} elseif (\is_array($current)) {
if (!isset($current[$offset])) {
$current[$offset] = [];
}
@@ -142,7 +142,7 @@ trait NestedPropertyTrait
if ($current === null) {
return $this;
}
if (is_array($current)) {
if (\is_array($current)) {
if (!isset($current[$offset])) {
return $this;
}

View File

@@ -30,7 +30,7 @@ trait ObjectCollectionTrait
{
$list = [];
foreach ($this->getIterator() as $key => $value) {
$list[$key] = is_object($value) ? clone $value : $value;
$list[$key] = \is_object($value) ? clone $value : $value;
}
return $this->createFrom($list);
@@ -132,7 +132,7 @@ trait ObjectCollectionTrait
foreach ($this->getIterator() as $id => $element) {
$list[$id] = method_exists($element, $method)
? call_user_func_array([$element, $method], $arguments) : null;
? \call_user_func_array([$element, $method], $arguments) : null;
}
return $list;

View File

@@ -44,7 +44,7 @@ trait ObjectTrait
return $type . static::$type;
}
$class = get_class($this);
$class = \get_class($this);
return $type . strtolower(substr($class, strrpos($class, '\\') + 1));
}

View File

@@ -101,7 +101,7 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
public static function sortByField($name, $orientation = 1, \Closure $next = null)
{
if (!$next) {
$next = function() {
$next = function($a, $b) {
return 0;
};
}
@@ -175,7 +175,7 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
case Comparison::MEMBER_OF:
return function ($object) use ($field, $value) {
$fieldValues = static::getObjectFieldValue($object, $field);
if (!is_array($fieldValues)) {
if (!\is_array($fieldValues)) {
$fieldValues = iterator_to_array($fieldValues);
}
return \in_array($value, $fieldValues, true);

View File

@@ -111,7 +111,7 @@ trait ObjectPropertyTrait
if ($doCreate === true) {
$this->_definedProperties[$property] = true;
$this->{$property} = null;
} elseif (is_callable($doCreate)) {
} elseif (\is_callable($doCreate)) {
$this->_definedProperties[$property] = true;
$this->{$property} = $this->offsetLoad($property, $doCreate());
} else {
@@ -153,7 +153,7 @@ trait ObjectPropertyTrait
protected function initObjectProperties()
{
$this->_definedProperties = [];
foreach (get_object_vars($this) as $property => $value) {
foreach (\get_object_vars($this) as $property => $value) {
if ($property[0] !== '_') {
$this->_definedProperties[$property] = ($value !== null);
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Psr7
*
@@ -156,10 +157,10 @@ abstract class AbstractUri implements UriInterface
* @inheritdoc
* @throws \InvalidArgumentException
*/
public function withUserInfo($user, $password = '')
public function withUserInfo($user, $password = null)
{
$user = UriPartsFilter::filterUserInfo($user);
$password = UriPartsFilter::filterUserInfo($password);
$password = UriPartsFilter::filterUserInfo($password ?? '');
if ($this->user === $user && $this->password === $password) {
return $this;

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Route
*
@@ -101,7 +102,7 @@ class Route
$parts = explode('/', $this->route);
if ($offset !== 0 || $length !== null) {
$parts = array_slice($parts, $offset, $length);
$parts = \array_slice($parts, $offset, $length);
}
return $parts;
@@ -159,7 +160,7 @@ class Route
*/
public function getGravParam($param)
{
return isset($this->gravParams[$param]) ? $this->gravParams[$param] : null;
return $this->gravParams[$param] ?? null;
}
/**
@@ -168,7 +169,7 @@ class Route
*/
public function getQueryParam($param)
{
return isset($this->queryParams[$param]) ? $this->queryParams[$param] : null;
return $this->queryParams[$param] ?? null;
}
/**
@@ -221,7 +222,7 @@ class Route
*/
protected function withParam($type, $param, $value)
{
$oldValue = isset($this->{$type}[$param]) ? $this->{$type}[$param] : null;
$oldValue = $this->{$type}[$param] ?? null;
if ($oldValue === $value) {
return $this;
@@ -284,7 +285,7 @@ class Route
$this->root = RouteFactory::getRoot();
$this->language = RouteFactory::getLanguage();
$path = isset($parts['path']) ? $parts['path'] : '/';
$path = $parts['path'] ?? '/';
if (isset($parts['params'])) {
$this->route = trim(rawurldecode($path), '/');
$this->gravParams = $parts['params'];

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Route
*
@@ -108,7 +109,7 @@ class RouteFactory
return $path;
}
$path = dirname(substr($path, 0, $pos));
$path = \dirname(substr($path, 0, $pos));
if ($path === '.') {
return '';
}
@@ -122,7 +123,7 @@ class RouteFactory
*/
public static function getParams($path)
{
$params = ltrim(substr($path, strlen(static::stripParams($path))), '/');
$params = ltrim(substr($path, \strlen(static::stripParams($path))), '/');
return $params !== '' ? static::parseParams($params) : [];
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Session
*
@@ -158,7 +159,7 @@ class Session implements SessionInterface
];
foreach ($options as $key => $value) {
if (is_array($value)) {
if (\is_array($value)) {
// Allow nested options.
foreach ($value as $key2 => $value2) {
$ckey = "{$key}.{$key2}";
@@ -293,7 +294,7 @@ class Session implements SessionInterface
*/
public function __get($name)
{
return isset($_SESSION[$name]) ? $_SESSION[$name] : null;
return $_SESSION[$name] ?? null;
}
/**
@@ -328,8 +329,8 @@ class Session implements SessionInterface
*/
protected function ini_set($key, $value)
{
if (!is_string($value)) {
if (is_bool($value)) {
if (!\is_string($value)) {
if (\is_bool($value)) {
$value = $value ? '1' : '0';
}
$value = (string)$value;

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Session
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Uri
*
@@ -81,7 +82,7 @@ class Uri extends AbstractUri
{
$queryParams = $this->getQueryParams();
return isset($queryParams[$key]) ? $queryParams[$key] : null;
return $queryParams[$key] ?? null;
}
/**

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Uri
*
@@ -57,13 +58,13 @@ class UriFactory
if (isset($env['REQUEST_SCHEME'])) {
$scheme = strtolower($env['REQUEST_SCHEME']);
} else {
$https = isset($env['HTTPS']) ? $env['HTTPS'] : '';
$https = $env['HTTPS'] ?? '';
$scheme = (empty($https) || strtolower($https) === 'off') ? 'http' : 'https';
}
// Build user and password.
$user = isset($env['PHP_AUTH_USER']) ? $env['PHP_AUTH_USER'] : '';
$pass = isset($env['PHP_AUTH_PW']) ? $env['PHP_AUTH_PW'] : '';
$user = $env['PHP_AUTH_USER'] ?? '';
$pass = $env['PHP_AUTH_PW'] ?? '';
// Build host.
$host = 'localhost';
@@ -79,11 +80,11 @@ class UriFactory
$port = isset($env['SERVER_PORT']) ? (int)$env['SERVER_PORT'] : null;
// Build path.
$request_uri = isset($env['REQUEST_URI']) ? $env['REQUEST_URI'] : '';
$request_uri = $env['REQUEST_URI'] ?? '';
$path = parse_url('http://example.com' . $request_uri, PHP_URL_PATH);
// Build query string.
$query = isset($env['QUERY_STRING']) ? $env['QUERY_STRING'] : '';
$query = $env['QUERY_STRING'] ?? '';
if ($query === '') {
$query = parse_url('http://example.com' . $request_uri, PHP_URL_QUERY);
}
@@ -115,7 +116,7 @@ class UriFactory
*/
public static function parseUrl($url)
{
if (!is_string($url)) {
if (!\is_string($url)) {
throw new \InvalidArgumentException('URL must be a string');
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @package Grav\Framework\Uri
*
@@ -23,7 +24,7 @@ class UriPartsFilter
*/
public static function filterScheme($scheme)
{
if (!is_string($scheme)) {
if (!\is_string($scheme)) {
throw new \InvalidArgumentException('Uri scheme must be a string');
}
@@ -39,7 +40,7 @@ class UriPartsFilter
*/
public static function filterUserInfo($info)
{
if (!is_string($info)) {
if (!\is_string($info)) {
throw new \InvalidArgumentException('Uri user info must be a string');
}
@@ -59,7 +60,7 @@ class UriPartsFilter
*/
public static function filterHost($host)
{
if (!is_string($host)) {
if (!\is_string($host)) {
throw new \InvalidArgumentException('Uri host must be a string');
}
@@ -83,7 +84,7 @@ class UriPartsFilter
*/
public static function filterPort($port = null)
{
if (null === $port || (is_int($port) && ($port >= 1 && $port <= 65535))) {
if (null === $port || (\is_int($port) && ($port >= 1 && $port <= 65535))) {
return $port;
}
@@ -103,7 +104,7 @@ class UriPartsFilter
*/
public static function filterPath($path)
{
if (!is_string($path)) {
if (!\is_string($path)) {
throw new \InvalidArgumentException('Uri path must be a string');
}
@@ -125,7 +126,7 @@ class UriPartsFilter
*/
public static function filterQueryOrFragment($query)
{
if (!is_string($query)) {
if (!\is_string($query)) {
throw new \InvalidArgumentException('Uri query string and fragment must be a string');
}