mirror of
https://github.com/getgrav/grav.git
synced 2026-07-19 23:50:43 +02:00
Fixed some phpstan level 2 issues
This commit is contained in:
@@ -190,7 +190,7 @@ class Truncator {
|
||||
* Clean extra code
|
||||
*
|
||||
* @param DOMDocument $doc
|
||||
* @param $container
|
||||
* @param DOMDocument $container
|
||||
* @return string
|
||||
*/
|
||||
private static function getCleanedHTML(DOMDocument $doc, $container)
|
||||
@@ -203,8 +203,7 @@ class Truncator {
|
||||
$doc->appendChild($container->firstChild);
|
||||
}
|
||||
|
||||
$html = trim($doc->saveHTML());
|
||||
return $html;
|
||||
return trim($doc->saveHTML());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,17 +241,20 @@ class Truncator {
|
||||
$ending = '...',
|
||||
$exact = false,
|
||||
$considerHtml = true
|
||||
) {
|
||||
)
|
||||
{
|
||||
if ($considerHtml) {
|
||||
// if the plain text is shorter than the maximum length, return the whole text
|
||||
if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
// splits all html-tags to scanable lines
|
||||
preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
|
||||
$total_length = strlen($ending);
|
||||
$open_tags = array();
|
||||
$truncate = '';
|
||||
$open_tags = [];
|
||||
|
||||
foreach ($lines as $line_matchings) {
|
||||
// if there is any html-tag in this line, handle it and add it (uncounted) to the output
|
||||
if (!empty($line_matchings[1])) {
|
||||
@@ -308,22 +310,22 @@ class Truncator {
|
||||
} else {
|
||||
if (strlen($text) <= $length) {
|
||||
return $text;
|
||||
} else {
|
||||
$truncate = substr($text, 0, $length - strlen($ending));
|
||||
}
|
||||
|
||||
$truncate = substr($text, 0, $length - strlen($ending));
|
||||
}
|
||||
// if the words shouldn't be cut in the middle...
|
||||
if (!$exact) {
|
||||
// ...search the last occurance of a space...
|
||||
$spacepos = strrpos($truncate, ' ');
|
||||
if (isset($spacepos)) {
|
||||
if (false !== $spacepos) {
|
||||
// ...and cut the text in this position
|
||||
$truncate = substr($truncate, 0, $spacepos);
|
||||
}
|
||||
}
|
||||
// add the defined ending to the text
|
||||
$truncate .= $ending;
|
||||
if($considerHtml) {
|
||||
if (isset($open_tags)) {
|
||||
// close all unclosed html-tags
|
||||
foreach ($open_tags as $tag) {
|
||||
$truncate .= '</' . $tag . '>';
|
||||
|
||||
@@ -109,7 +109,7 @@ class ImageFile extends Image
|
||||
* Gets the hash.
|
||||
* @param string $type
|
||||
* @param int $quality
|
||||
* @param [] $extras
|
||||
* @param array $extras
|
||||
* @return null
|
||||
*/
|
||||
public function getHash($type = 'guess', $quality = 80, $extras = [])
|
||||
|
||||
@@ -455,9 +455,9 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a human readable output for cron sytnax
|
||||
* Gets a human readable output for cron syntax
|
||||
*
|
||||
* @param $at
|
||||
* @param string $at
|
||||
* @return string
|
||||
*/
|
||||
public function niceCronFilter($at)
|
||||
|
||||
@@ -1340,7 +1340,7 @@ class Uri
|
||||
/**
|
||||
* Check if this is a valid Grav extension
|
||||
*
|
||||
* @param $extension
|
||||
* @param string $extension
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidExtension($extension)
|
||||
@@ -1357,7 +1357,7 @@ class Uri
|
||||
/**
|
||||
* Allow overriding of any element (be careful!)
|
||||
*
|
||||
* @param $data
|
||||
* @param array $data
|
||||
* @return Uri
|
||||
*/
|
||||
public function setUriProperties($data)
|
||||
|
||||
@@ -1406,16 +1406,16 @@ abstract class Utils
|
||||
/**
|
||||
* Parse a readable file size and return a value in bytes
|
||||
*
|
||||
* @param string|int $size
|
||||
* @param string|int|float $size
|
||||
* @return int
|
||||
*/
|
||||
public static function parseSize($size)
|
||||
{
|
||||
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
|
||||
$size = preg_replace('/[^0-9\.]/', '', $size);
|
||||
$size = (float)preg_replace('/[^0-9\.]/', '', $size);
|
||||
|
||||
if ($unit) {
|
||||
$size = $size * pow(1024, stripos('bkmgtpezy', $unit[0]));
|
||||
$size *= 1024 ** stripos('bkmgtpezy', $unit[0]);
|
||||
}
|
||||
|
||||
return (int) abs(round($size));
|
||||
@@ -1502,7 +1502,7 @@ abstract class Utils
|
||||
}
|
||||
|
||||
// Packed representation of IP
|
||||
$ip = inet_pton($ip);
|
||||
$ip = (string)inet_pton($ip);
|
||||
|
||||
// Maximum netmask length = same as packed address
|
||||
$len = 8*strlen($ip);
|
||||
|
||||
@@ -32,7 +32,7 @@ trait FormTrait
|
||||
{
|
||||
/** @var string */
|
||||
public $status = 'success';
|
||||
/** @var string */
|
||||
/** @var string|null */
|
||||
public $message;
|
||||
/** @var string[] */
|
||||
public $messages = [];
|
||||
@@ -45,7 +45,7 @@ trait FormTrait
|
||||
private $uniqueid;
|
||||
/** @var bool */
|
||||
private $submitted;
|
||||
/** @var Data|object|null */
|
||||
/** @var \ArrayAccess|Data|object|null */
|
||||
private $data;
|
||||
/** @var array|UploadedFileInterface[] */
|
||||
private $files;
|
||||
@@ -485,11 +485,11 @@ trait FormTrait
|
||||
/**
|
||||
* Validate data and throw validation exceptions if validation fails.
|
||||
*
|
||||
* @param \ArrayAccess $data
|
||||
* @param \ArrayAccess|Data $data
|
||||
* @throws ValidationException
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function validateData(\ArrayAccess $data): void
|
||||
protected function validateData($data): void
|
||||
{
|
||||
if ($data instanceof Data) {
|
||||
$data->validate();
|
||||
@@ -499,7 +499,7 @@ trait FormTrait
|
||||
/**
|
||||
* Filter validated data.
|
||||
*
|
||||
* @param \ArrayAccess $data
|
||||
* @param \ArrayAccess|Data $data
|
||||
*/
|
||||
protected function filterData(\ArrayAccess $data): void
|
||||
{
|
||||
|
||||
@@ -65,64 +65,64 @@ trait UriDecorationTrait
|
||||
|
||||
public function withScheme($scheme): UriInterface
|
||||
{
|
||||
/** @var UriInterface|UriDecorationTrait $new */
|
||||
$new = clone $this;
|
||||
$new->uri = $this->uri->withScheme($scheme);
|
||||
|
||||
/** @var UriInterface $new */
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function withUserInfo($user, $password = null): UriInterface
|
||||
{
|
||||
/** @var UriInterface|UriDecorationTrait $new */
|
||||
$new = clone $this;
|
||||
$new->uri = $this->uri->withUserInfo($user, $password);
|
||||
|
||||
/** @var UriInterface $new */
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function withHost($host): UriInterface
|
||||
{
|
||||
/** @var UriInterface|UriDecorationTrait $new */
|
||||
$new = clone $this;
|
||||
$new->uri = $this->uri->withHost($host);
|
||||
|
||||
/** @var UriInterface $new */
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function withPort($port): UriInterface
|
||||
{
|
||||
/** @var UriInterface|UriDecorationTrait $new */
|
||||
$new = clone $this;
|
||||
$new->uri = $this->uri->withPort($port);
|
||||
|
||||
/** @var UriInterface $new */
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function withPath($path): UriInterface
|
||||
{
|
||||
/** @var UriInterface|UriDecorationTrait $new */
|
||||
$new = clone $this;
|
||||
$new->uri = $this->uri->withPath($path);
|
||||
|
||||
/** @var UriInterface $new */
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function withQuery($query): UriInterface
|
||||
{
|
||||
/** @var UriInterface|UriDecorationTrait $new */
|
||||
$new = clone $this;
|
||||
$new->uri = $this->uri->withQuery($query);
|
||||
|
||||
/** @var UriInterface $new */
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function withFragment($fragment): UriInterface
|
||||
{
|
||||
/** @var UriInterface|UriDecorationTrait $new */
|
||||
$new = clone $this;
|
||||
$new->uri = $this->uri->withFragment($fragment);
|
||||
|
||||
/** @var UriInterface $new */
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user