diff --git a/system/src/Grav/Framework/Cache/AbstractCache.php b/system/src/Grav/Framework/Cache/AbstractCache.php index de749a1c6..82ba8cc9d 100644 --- a/system/src/Grav/Framework/Cache/AbstractCache.php +++ b/system/src/Grav/Framework/Cache/AbstractCache.php @@ -1,4 +1,5 @@ caches = array_values($caches); - $this->count = count($caches); + $this->count = \count($caches); } /** diff --git a/system/src/Grav/Framework/Cache/Adapter/DoctrineCache.php b/system/src/Grav/Framework/Cache/Adapter/DoctrineCache.php index 3a69c1ff9..5282bbdf0 100644 --- a/system/src/Grav/Framework/Cache/Adapter/DoctrineCache.php +++ b/system/src/Grav/Framework/Cache/Adapter/DoctrineCache.php @@ -1,4 +1,5 @@ driver, 'deleteMultiple')) { - $success = true; - foreach ($keys as $key) { - $success = $this->delete($key) && $success; - } - - return $success; - } - return $this->driver->deleteMultiple($keys); } diff --git a/system/src/Grav/Framework/Cache/Adapter/FileCache.php b/system/src/Grav/Framework/Cache/Adapter/FileCache.php index 389b626e1..799051d60 100644 --- a/system/src/Grav/Framework/Cache/Adapter/FileCache.php +++ b/system/src/Grav/Framework/Cache/Adapter/FileCache.php @@ -1,4 +1,5 @@ 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]); diff --git a/system/src/Grav/Framework/Cache/CacheInterface.php b/system/src/Grav/Framework/Cache/CacheInterface.php index 54af40c69..f72c5d7eb 100644 --- a/system/src/Grav/Framework/Cache/CacheInterface.php +++ b/system/src/Grav/Framework/Cache/CacheInterface.php @@ -1,4 +1,5 @@ 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; } diff --git a/system/src/Grav/Framework/Cache/Exception/CacheException.php b/system/src/Grav/Framework/Cache/Exception/CacheException.php index 71caff7f6..5fae9ef32 100644 --- a/system/src/Grav/Framework/Cache/Exception/CacheException.php +++ b/system/src/Grav/Framework/Cache/Exception/CacheException.php @@ -1,4 +1,5 @@ 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); diff --git a/system/src/Grav/Framework/ContentBlock/ContentBlock.php b/system/src/Grav/Framework/ContentBlock/ContentBlock.php index 672dba4cc..ea24f4017 100644 --- a/system/src/Grav/Framework/ContentBlock/ContentBlock.php +++ b/system/src/Grav/Framework/ContentBlock/ContentBlock.php @@ -1,4 +1,5 @@ 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']); diff --git a/system/src/Grav/Framework/ContentBlock/ContentBlockInterface.php b/system/src/Grav/Framework/ContentBlock/ContentBlockInterface.php index fff8f2e73..45f4c29c1 100644 --- a/system/src/Grav/Framework/ContentBlock/ContentBlockInterface.php +++ b/system/src/Grav/Framework/ContentBlock/ContentBlockInterface.php @@ -1,4 +1,5 @@ (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']; diff --git a/system/src/Grav/Framework/ContentBlock/HtmlBlockInterface.php b/system/src/Grav/Framework/ContentBlock/HtmlBlockInterface.php index 204e199e5..37eea0cd7 100644 --- a/system/src/Grav/Framework/ContentBlock/HtmlBlockInterface.php +++ b/system/src/Grav/Framework/ContentBlock/HtmlBlockInterface.php @@ -1,4 +1,5 @@ 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']; diff --git a/system/src/Grav/Framework/File/DataFile.php b/system/src/Grav/Framework/File/DataFile.php index db773c4dd..e1250652b 100644 --- a/system/src/Grav/Framework/File/DataFile.php +++ b/system/src/Grav/Framework/File/DataFile.php @@ -1,4 +1,7 @@ formatter->decode($data); } catch (\RuntimeException $e) { diff --git a/system/src/Grav/Framework/File/File.php b/system/src/Grav/Framework/File/File.php index 60e556b8a..bcac43941 100644 --- a/system/src/Grav/Framework/File/File.php +++ b/system/src/Grav/Framework/File/File.php @@ -1,4 +1,7 @@ preserveLines($value, $search, $replace); } diff --git a/system/src/Grav/Framework/File/Formatter/YamlFormatter.php b/system/src/Grav/Framework/File/Formatter/YamlFormatter.php index d59f9e7d4..53652c2b9 100644 --- a/system/src/Grav/Framework/File/Formatter/YamlFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/YamlFormatter.php @@ -1,4 +1,5 @@ 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); diff --git a/system/src/Grav/Framework/File/IniFile.php b/system/src/Grav/Framework/File/IniFile.php index 2b3dadbc4..6a81a1751 100644 --- a/system/src/Grav/Framework/File/IniFile.php +++ b/system/src/Grav/Framework/File/IniFile.php @@ -1,4 +1,7 @@ {$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; } diff --git a/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php b/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php index d3bc3792a..2fbf3faeb 100644 --- a/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php +++ b/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php @@ -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; diff --git a/system/src/Grav/Framework/Object/Base/ObjectTrait.php b/system/src/Grav/Framework/Object/Base/ObjectTrait.php index 67a5bf5b5..c4dfaa293 100644 --- a/system/src/Grav/Framework/Object/Base/ObjectTrait.php +++ b/system/src/Grav/Framework/Object/Base/ObjectTrait.php @@ -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)); } diff --git a/system/src/Grav/Framework/Object/Collection/ObjectExpressionVisitor.php b/system/src/Grav/Framework/Object/Collection/ObjectExpressionVisitor.php index 80d5cee77..775da50b1 100644 --- a/system/src/Grav/Framework/Object/Collection/ObjectExpressionVisitor.php +++ b/system/src/Grav/Framework/Object/Collection/ObjectExpressionVisitor.php @@ -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); diff --git a/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php b/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php index 6dcd7f42f..920630739 100644 --- a/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php +++ b/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php @@ -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); } diff --git a/system/src/Grav/Framework/Psr7/AbstractUri.php b/system/src/Grav/Framework/Psr7/AbstractUri.php index 5ddda9bf4..d0c4cc085 100644 --- a/system/src/Grav/Framework/Psr7/AbstractUri.php +++ b/system/src/Grav/Framework/Psr7/AbstractUri.php @@ -1,4 +1,5 @@ user === $user && $this->password === $password) { return $this; diff --git a/system/src/Grav/Framework/Route/Route.php b/system/src/Grav/Framework/Route/Route.php index 63f6f7ec3..9492b0c01 100644 --- a/system/src/Grav/Framework/Route/Route.php +++ b/system/src/Grav/Framework/Route/Route.php @@ -1,4 +1,5 @@ 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']; diff --git a/system/src/Grav/Framework/Route/RouteFactory.php b/system/src/Grav/Framework/Route/RouteFactory.php index 830d7c75c..6890043c4 100644 --- a/system/src/Grav/Framework/Route/RouteFactory.php +++ b/system/src/Grav/Framework/Route/RouteFactory.php @@ -1,4 +1,5 @@ $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; diff --git a/system/src/Grav/Framework/Session/SessionInterface.php b/system/src/Grav/Framework/Session/SessionInterface.php index 74c5f2aca..be3462015 100644 --- a/system/src/Grav/Framework/Session/SessionInterface.php +++ b/system/src/Grav/Framework/Session/SessionInterface.php @@ -1,4 +1,5 @@ getQueryParams(); - return isset($queryParams[$key]) ? $queryParams[$key] : null; + return $queryParams[$key] ?? null; } /** diff --git a/system/src/Grav/Framework/Uri/UriFactory.php b/system/src/Grav/Framework/Uri/UriFactory.php index c6bd4289d..15bf0cbdd 100644 --- a/system/src/Grav/Framework/Uri/UriFactory.php +++ b/system/src/Grav/Framework/Uri/UriFactory.php @@ -1,4 +1,5 @@ = 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'); }