Reduce potential errors

This commit is contained in:
Dennis Eichhorn 2018-07-14 13:40:49 +02:00
parent 94afffec8e
commit d9ecb8400f
17 changed files with 165 additions and 121 deletions

View File

@ -189,7 +189,7 @@ class Group implements ArrayableInterface, \JsonSerializable
*/
public function __toString() : string
{
return \json_encode($this->toArray());
return (string) \json_encode($this->toArray());
}
/**

View File

@ -48,7 +48,7 @@ final class FinanceFormulas
*/
public static function getAnnualPercentageYield(float $r, int $n) : float
{
return (float) pow(1 + $r / $n, $n) - 1;
return pow(1 + $r / $n, $n) - 1;
}
/**
@ -65,7 +65,7 @@ final class FinanceFormulas
*/
public static function getStateAnnualInterestRateOfAPY(float $apy, int $n) : float
{
return (float) (pow($apy + 1, 1 / $n) - 1) * $n;
return (pow($apy + 1, 1 / $n) - 1) * $n;
}
/**
@ -922,7 +922,7 @@ final class FinanceFormulas
*/
public static function getFutureValueFactor(float $r, int $n) : float
{
return (float) pow(1 + $r, $n);
return pow(1 + $r, $n);
}
/**

View File

@ -369,6 +369,6 @@ final class StockBonds
*/
public static function getZeroCouponBondEffectiveYield(float $F, float $PV, int $n) : float
{
return (float) pow($F / $PV, 1 / $n) - 1;
return pow($F / $PV, 1 / $n) - 1;
}
}

View File

@ -64,7 +64,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
* @var string
* @since 1.0.0
*/
protected $type = CacheStatus::UNDEFINED;
protected $type = CacheType::UNDEFINED;
/**
* Database status.

View File

@ -218,7 +218,7 @@ class FileCache extends ConnectionAbstract
if ($type === CacheValueType::_INT || $type === CacheValueType::_FLOAT || $type === CacheValueType::_STRING || $type === CacheValueType::_BOOL) {
return (string) $value;
} elseif ($type === CacheValueType::_ARRAY) {
return \json_encode($value);
return (string) \json_encode($value);
} elseif ($type === CacheValueType::_SERIALIZABLE) {
return get_class($value) . self::DELIM . $value->serialize();
} elseif ($type === CacheValueType::_JSONSERIALIZABLE) {
@ -241,8 +241,8 @@ class FileCache extends ConnectionAbstract
*/
private function getExpire(string $raw) : int
{
$expireStart = \strpos($raw, self::DELIM);
$expireEnd = \strpos($raw, self::DELIM, $expireStart + 1);
$expireStart = (int) \strpos($raw, self::DELIM);
$expireEnd = (int) \strpos($raw, self::DELIM, $expireStart + 1);
return (int) \substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
}

View File

@ -178,6 +178,22 @@ class Directory extends FileAbstract implements DirectoryInterface
}
/**
* {@inheritdoc}
*/
public static function dirname(string $path) : string
{
}
/**
* {@inheritdoc}
*/
public static function dirpath(string $path) : string
{
}
/**
* {@inheritdoc}
*/

View File

@ -138,6 +138,14 @@ class File extends FileAbstract implements FileInterface
return $content;
}
/**
* {@inheritdoc}
*/
public static function count(string $path, bool $recursive = true, array $ignore = []) : int
{
}
/**
* {@inheritdoc}
*/

View File

@ -101,7 +101,7 @@ class Commit
$this->author = new Author();
$this->branch = new Branch();
$this->tag = new Tag();
$this->repository = new Repository(realpath(__DIR__ . '/../../../../../'));
$this->repository = new Repository();
}
/**

View File

@ -45,16 +45,16 @@ class Git
public static function test() : bool
{
$pipes = [];
$resource = proc_open(escapeshellarg(Git::getBin()), [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
$resource = \proc_open(\escapeshellarg(Git::getBin()), [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
$stdout = \stream_get_contents($pipes[1]);
$stderr = \stream_get_contents($pipes[2]);
foreach ($pipes as $pipe) {
fclose($pipe);
\fclose($pipe);
}
return trim(proc_close($resource)) !== 127;
return $resource !== false && \proc_close($resource) !== 127;
}
/**
@ -82,10 +82,10 @@ class Git
*/
public static function setBin(string $path) : void
{
if (realpath($path) === false) {
if (\realpath($path) === false) {
throw new PathException($path);
}
self::$bin = realpath($path);
self::$bin = \realpath($path);
}
}

View File

@ -67,9 +67,11 @@ class Repository
*
* @since 1.0.0
*/
public function __construct(string $path)
public function __construct(string $path = '')
{
$this->setPath($path);
if (\is_dir($path)) {
$this->setPath($path);
}
}
/**
@ -85,20 +87,16 @@ class Repository
*/
private function setPath(string $path) : void
{
if (!is_dir($path)) {
if (!\is_dir($path) || \realpath($path) === false) {
throw new PathException($path);
}
$this->path = realpath($path);
$this->path = \realpath($path);
if ($this->path === false) {
throw new PathException($path);
}
if (file_exists($this->path . '/.git') && \is_dir($this->path . '/.git')) {
if (\file_exists($this->path . '/.git') && \is_dir($this->path . '/.git')) {
$this->bare = false;
} elseif (is_file($this->path . '/config')) { // Is this a bare repo?
$parseIni = parse_ini_file($this->path . '/config');
} elseif (\is_file($this->path . '/config')) { // Is this a bare repo?
$parseIni = \parse_ini_file($this->path . '/config');
if ($parseIni['bare']) {
$this->bare = true;
@ -128,7 +126,7 @@ class Repository
public function getActiveBranch() : Branch
{
$branches = $this->getBranches();
$active = preg_grep('/^\*/', $branches);
$active = \preg_grep('/^\*/', $branches);
reset($active);
return new Branch(current($active));
@ -170,14 +168,14 @@ class Repository
*/
private function run(string $cmd) : array
{
if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
$cmd = 'cd ' . escapeshellarg(\dirname(Git::getBin()))
. ' && ' . basename(Git::getBin())
. ' -C ' . escapeshellarg($this->path) . ' '
if (\strtolower(\substr(PHP_OS, 0, 3)) == 'win') {
$cmd = 'cd ' . \escapeshellarg(\dirname(Git::getBin()))
. ' && ' . \basename(Git::getBin())
. ' -C ' . \escapeshellarg($this->path) . ' '
. $cmd;
} else {
$cmd = escapeshellarg(Git::getBin())
. ' -C ' . escapeshellarg($this->path) . ' '
$cmd = \escapeshellarg(Git::getBin())
. ' -C ' . \escapeshellarg($this->path) . ' '
. $cmd;
}
@ -187,15 +185,20 @@ class Repository
2 => ['pipe', 'w'],
];
$resource = proc_open($cmd, $desc, $pipes, $this->path, null);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
$resource = \proc_open($cmd, $desc, $pipes, $this->path, null);
foreach ($pipes as $pipe) {
fclose($pipe);
if ($resource === false) {
throw new \Exception();
}
$status = trim(proc_close($resource));
$stdout = \stream_get_contents($pipes[1]);
$stderr = \stream_get_contents($pipes[2]);
foreach ($pipes as $pipe) {
\fclose($pipe);
}
$status = \proc_close($resource);
if ($status == -1) {
throw new \Exception($stderr);
@ -215,11 +218,15 @@ class Repository
*/
private function parseLines(string $lines) : array
{
$lineArray = preg_split('/\r\n|\n|\r/', $lines);
$lineArray = \preg_split('/\r\n|\n|\r/', $lines);
$lines = [];
if ($lineArray === false) {
return $lines;
}
foreach ($lineArray as $key => $line) {
$temp = preg_replace('/\s+/', ' ', trim($line, ' '));
$temp = \preg_replace('/\s+/', ' ', trim($line, ' '));
if (!empty($temp)) {
$lines[] = $temp;
@ -242,7 +249,7 @@ class Repository
*/
public function create(string $source = null) : void
{
if (!is_dir($this->path) || \file_exists($this->path . '/.git')) {
if (!\is_dir($this->path) || \file_exists($this->path . '/.git')) {
throw new \Exception('Already repository');
}
@ -264,7 +271,7 @@ class Repository
*/
public function status() : string
{
return implode("\n", $this->run('status'));
return \implode("\n", $this->run('status'));
}
/**
@ -282,7 +289,7 @@ class Repository
{
$files = $this->parseFileList($files);
return implode("\n", $this->run('add ' . $files . ' -v'));
return \implode("\n", $this->run('add ' . $files . ' -v'));
}
/**
@ -299,7 +306,7 @@ class Repository
{
$files = $this->parseFileList($files);
return implode("\n", $this->run('rm ' . ($cached ? '--cached ' : '') . $files));
return \implode("\n", $this->run('rm ' . ($cached ? '--cached ' : '') . $files));
}
/**
@ -315,9 +322,9 @@ class Repository
*/
private function parseFileList($files) : string
{
if (is_array($files)) {
return '"' . implode('" "', $files) . '"';
} elseif (!is_string($files)) {
if (\is_array($files)) {
return '"' . \implode('" "', $files) . '"';
} elseif (!\is_string($files)) {
throw new \InvalidArgumentException('Wrong type for $files.');
}
@ -336,7 +343,7 @@ class Repository
*/
public function commit(Commit $commit, $all = true) : string
{
return implode("\n", $this->run('commit ' . ($all ? '-av' : '-v') . ' -m ' . escapeshellarg($commit->getMessage())));
return \implode("\n", $this->run('commit ' . ($all ? '-av' : '-v') . ' -m ' . \escapeshellarg($commit->getMessage())));
}
/**
@ -352,11 +359,11 @@ class Repository
*/
public function cloneTo(string $target) : string
{
if (!is_dir($target)) {
if (!\is_dir($target)) {
throw new PathException($target);
}
return implode("\n", $this->run('clone --local ' . $this->path . ' ' . $target));
return \implode("\n", $this->run('clone --local ' . $this->path . ' ' . $target));
}
/**
@ -372,11 +379,11 @@ class Repository
*/
public function cloneFrom(string $source) : string
{
if (!is_dir($source)) {
if (!\is_dir($source)) {
throw new PathException($source);
}
return implode("\n", $this->run('clone --local ' . $source . ' ' . $this->path));
return \implode("\n", $this->run('clone --local ' . $source . ' ' . $this->path));
}
/**
@ -390,7 +397,7 @@ class Repository
*/
public function cloneRemote(string $source) : string
{
return implode("\n", $this->run('clone ' . $source . ' ' . $this->path));
return \implode("\n", $this->run('clone ' . $source . ' ' . $this->path));
}
/**
@ -405,7 +412,7 @@ class Repository
*/
public function clean(bool $dirs = false, bool $force = false) : string
{
return implode("\n", $this->run('clean' . ($force ? ' -f' : '') . ($dirs ? ' -d' : '')));
return \implode("\n", $this->run('clean' . ($force ? ' -f' : '') . ($dirs ? ' -d' : '')));
}
/**
@ -420,7 +427,7 @@ class Repository
*/
public function createBranch(Branch $branch, bool $force = false) : string
{
return implode("\n", $this->run('branch ' . ($force ? '-D' : '-d') . ' ' . $branch->getName()));
return \implode("\n", $this->run('branch ' . ($force ? '-D' : '-d') . ' ' . $branch->getName()));
}
/**
@ -488,7 +495,7 @@ class Repository
*/
public function checkout(Branch $branch) : string
{
$result = implode("\n", $this->run('checkout ' . $branch->getName()));
$result = \implode("\n", $this->run('checkout ' . $branch->getName()));
$this->branch = $branch;
return $result;
@ -505,7 +512,7 @@ class Repository
*/
public function merge(Branch $branch) : string
{
return implode("\n", $this->run('merge ' . $branch->getName() . ' --no-ff'));
return \implode("\n", $this->run('merge ' . $branch->getName() . ' --no-ff'));
}
/**
@ -517,7 +524,7 @@ class Repository
*/
public function fetch() : string
{
return implode("\n", $this->run('fetch'));
return \implode("\n", $this->run('fetch'));
}
/**
@ -531,7 +538,7 @@ class Repository
*/
public function createTag(Tag $tag) : string
{
return implode("\n", $this->run('tag -a ' . $tag->getName() . ' -m ' . escapeshellarg($tag->getMessage())));
return \implode("\n", $this->run('tag -a ' . $tag->getName() . ' -m ' . \escapeshellarg($tag->getMessage())));
}
/**
@ -568,9 +575,9 @@ class Repository
*/
public function push(string $remote, Branch $branch) : string
{
$remote = escapeshellarg($remote);
$remote = \escapeshellarg($remote);
return implode("\n", $this->run('push --tags ' . $remote . ' ' . $branch->getName()));
return \implode("\n", $this->run('push --tags ' . $remote . ' ' . $branch->getName()));
}
/**
@ -587,7 +594,7 @@ class Repository
{
$remote = escapeshellarg($remote);
return implode("\n", $this->run('pull ' . $remote . ' ' . $branch->getName()));
return \implode("\n", $this->run('pull ' . $remote . ' ' . $branch->getName()));
}
/**
@ -613,7 +620,7 @@ class Repository
*/
public function getDescription() : string
{
return \file_get_contents($this->getDirectoryPath() . '/description');
return (string) \file_get_contents($this->getDirectoryPath() . '/description');
}
/**
@ -657,18 +664,18 @@ class Repository
return 0;
}
$fh = fopen($path, 'r');
$fh = \fopen($path, 'r');
if (!$fh) {
return 0;
}
while (!feof($fh)) {
fgets($fh);
\fgets($fh);
$loc++;
}
fclose($fh);
\fclose($fh);
}
return $loc;
@ -700,7 +707,7 @@ class Repository
foreach ($lines as $line) {
\preg_match('/^[0-9]*/', $line, $matches);
$contributor = new Author(substr($line, strlen($matches[0]) + 1));
$contributor = new Author(\substr($line, \strlen($matches[0]) + 1));
$contributor->setCommitCount($this->getCommitsCount($start, $end)[$contributor->getName()]);
$addremove = $this->getAdditionsRemovalsByContributor($contributor, $start, $end);
@ -739,7 +746,7 @@ class Repository
foreach ($lines as $line) {
\preg_match('/^[0-9]*/', $line, $matches);
$commits[substr($line, strlen($matches[0]) + 1)] = (int) $matches[0];
$commits[\substr($line, \strlen($matches[0]) + 1)] = (int) $matches[0];
}
return $commits;
@ -768,7 +775,7 @@ class Repository
$addremove = ['added' => 0, 'removed' => 0];
$lines = $this->run(
'log --author=' . escapeshellarg($author->getName())
'log --author=' . \escapeshellarg($author->getName())
. ' --since="' . $start->format('Y-m-d')
. '" --before="' . $end->format('Y-m-d')
. '" --pretty=tformat: --numstat'
@ -793,7 +800,7 @@ class Repository
*/
public function getRemote() : string
{
return implode("\n", $this->run('config --get remote.origin.url'));
return \implode("\n", $this->run('config --get remote.origin.url'));
}
/**
@ -820,7 +827,7 @@ class Repository
if ($author === null) {
$author = '';
} else {
$author = ' --author=' . escapeshellarg($author->getName()) . '';
$author = ' --author=' . \escapeshellarg($author->getName()) . '';
}
$lines = $this->run(
@ -865,7 +872,7 @@ class Repository
\preg_match('/[0-9ABCDEFabcdef]{40}/', $lines[0], $matches);
if (!isset($matches[0]) || strlen($matches[0]) !== 40) {
if (!isset($matches[0]) || \strlen($matches[0]) !== 40) {
throw new \Exception('Invalid commit id');
}
@ -875,7 +882,7 @@ class Repository
$author = \explode(':', $lines[1] ?? '');
$author = \explode('<', trim($author[1] ?? ''));
$date = substr($lines[2] ?? '', 6);
$date = \substr($lines[2] ?? '', 6);
$commit = new Commit($matches[0]);
$commit->setAuthor(new Author(trim($author[0] ?? ''), rtrim($author[1] ?? '', '>')));
@ -913,7 +920,7 @@ class Repository
\preg_match('/[0-9ABCDEFabcdef]{40}/', $lines[0], $matches);
if (!isset($matches[0]) || strlen($matches[0]) !== 40) {
if (!isset($matches[0]) || \strlen($matches[0]) !== 40) {
throw new \Exception('Invalid commit id');
}

View File

@ -47,34 +47,42 @@ class Zip implements ArchiveInterface
/** @var array $sources */
foreach ($sources as $source => $relative) {
$source = \str_replace('\\', '/', realpath($source));
$source = \realpath($source);
if ($source === false) {
continue;
}
$source = \str_replace('\\', '/', $source);
if (!\file_exists($source)) {
continue;
}
if (is_dir($source)) {
if (\is_dir($source)) {
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = \str_replace('\\', '/', $file);
/* Ignore . and .. */
if (\in_array(mb_substr($file, mb_strrpos($file, '/') + 1), ['.', '..'])) {
if (($pos = \mb_strrpos($file, '/')) === false
|| \in_array(\mb_substr($file, $pos + 1), ['.', '..'])
) {
continue;
}
$absolute = realpath($file);
$absolute = \str_replace('\\', '/', $absolute);
$absolute = \realpath($file);
$absolute = \str_replace('\\', '/', (string) $absolute);
$dir = \str_replace($source . '/', '', $relative . '/' . $absolute);
if (is_dir($absolute)) {
if (\is_dir($absolute)) {
$zip->addEmptyDir($dir . '/');
} elseif (is_file($absolute)) {
} elseif (\is_file($absolute)) {
$zip->addFile($absolute, $dir);
}
}
} elseif (is_file($source)) {
} elseif (\is_file($source)) {
$zip->addFile($source, $relative);
}
}

View File

@ -51,6 +51,6 @@ final class ImageUtils
$img = \str_replace('data:image/png;base64,', '', $img);
$img = \str_replace(' ', '+', $img);
return base64_decode($img);
return (string) base64_decode($img);
}
}

View File

@ -98,15 +98,19 @@ final class StringCompare
*/
public static function valueWords(string $s1, string $s2) : int
{
$words1 = preg_split('/[ _-]/', $s1);
$words2 = preg_split('/[ _-]/', $s2);
$words1 = \preg_split('/[ _-]/', $s1);
$words2 = \preg_split('/[ _-]/', $s2);
$total = 0;
if ($words1 === false || $words2 === false) {
return PHP_INT_MAX;
}
foreach ($words1 as $word1) {
$best = strlen($s2);
$best = \strlen($s2);
foreach ($words2 as $word2) {
$wordDist = levenshtein($word1, $word2);
$wordDist = \levenshtein($word1, $word2);
if ($wordDist < $best) {
$best = $wordDist;
@ -136,7 +140,7 @@ final class StringCompare
*/
public static function valuePhrase(string $s1, string $s2) : int
{
return levenshtein($s1, $s2);
return \levenshtein($s1, $s2);
}
/**
@ -151,7 +155,7 @@ final class StringCompare
*/
public static function valueLength(string $s1, string $s2) : int
{
return (int) abs(strlen($s1) - strlen($s2));
return abs(\strlen($s1) - \strlen($s2));
}
/**

View File

@ -40,17 +40,17 @@ final class TestUtils
/**
* Set private object member
*
* @param object|string $obj Object to modify
* @param string $name Member name to modify
* @param mixed $value Value to set
* @param object $obj Object to modify
* @param string $name Member name to modify
* @param mixed $value Value to set
*
* @return bool The function returns true after setting the member
*
* @since 1.0.0
*/
public static function setMember(/* object */ $obj, string $name, $value) : bool
public static function setMember(object $obj, string $name, $value) : bool
{
$reflectionClass = new \ReflectionClass(is_string($obj) ? $obj : get_class($obj));
$reflectionClass = new \ReflectionClass(\get_class($obj));
if (!$reflectionClass->hasProperty($name)) {
return false;
@ -74,16 +74,16 @@ final class TestUtils
/**
* Get private object member
*
* @param object|string $obj Object to read
* @param string $name Member name to read
* @param object $obj Object to read
* @param string $name Member name to read
*
* @return mixed Returns the member variable value
*
* @since 1.0.0
*/
public static function getMember($obj, string $name)
public static function getMember(object $obj, string $name)
{
$reflectionClass = new \ReflectionClass(is_string($obj) ? $obj : get_class($obj));
$reflectionClass = new \ReflectionClass(\get_class($obj));
if (!$reflectionClass->hasProperty($name)) {
return null;

View File

@ -31,8 +31,8 @@ final class Iban extends ValidatorAbstract
*/
public static function isValid($value, array $constraints = null) : bool
{
$value = \str_replace(' ', '', strtolower($value));
$enumName = 'C_' . strtoupper(substr($value, 0, 2));
$value = \str_replace(' ', '', \strtolower($value));
$enumName = 'C_' . \strtoupper(\substr($value, 0, 2));
if (!IbanEnum::isValidName($enumName)) {
self::$error = IbanErrorType::INVALID_COUNTRY;
@ -42,7 +42,7 @@ final class Iban extends ValidatorAbstract
$layout = \str_replace(' ', '', IbanEnum::getByName($enumName));
if (strlen($value) !== strlen($layout)) {
if (\strlen($value) !== \strlen($layout)) {
self::$error = IbanErrorType::INVALID_LENGTH;
return false;
@ -81,12 +81,12 @@ final class Iban extends ValidatorAbstract
*/
private static function validateZeros(string $iban, string $layout) : bool
{
if (strpos($layout, '0') === false) {
if (\strpos($layout, '0') === false) {
return true;
}
$lastPos = 0;
while (($lastPos = strpos($layout, '0', $lastPos)) !== false) {
while (($lastPos = \strpos($layout, '0', $lastPos)) !== false) {
if ($iban[$lastPos] !== '0') {
return false;
}
@ -109,13 +109,13 @@ final class Iban extends ValidatorAbstract
*/
private static function validateNumeric(string $iban, string $layout) : bool
{
if (strpos($layout, 'n') === false) {
if (\strpos($layout, 'n') === false) {
return true;
}
$lastPos = 0;
while (($lastPos = strpos($layout, 'n', $lastPos)) !== false) {
if (!is_numeric($iban[$lastPos])) {
while (($lastPos = \strpos($layout, 'n', $lastPos)) !== false) {
if (!\is_numeric($iban[$lastPos])) {
return false;
}
@ -139,18 +139,18 @@ final class Iban extends ValidatorAbstract
$chars = ['a' => 10, 'b' => 11, 'c' => 12, 'd' => 13, 'e' => 14, 'f' => 15, 'g' => 16, 'h' => 17, 'i' => 18,
'j' => 19, 'k' => 20, 'l' => 21, 'm' => 22, 'n' => 23, 'o' => 24, 'p' => 25, 'q' => 26, 'r' => 27,
's' => 28, 't' => 29, 'u' => 30, 'v' => 31, 'w' => 32, 'x' => 33, 'y' => 34, 'z' => 35,];
$moved = substr($iban, 4) . substr($iban, 0, 4);
$movedArray = str_split($moved);
$moved = \substr($iban, 4) . \substr($iban, 0, 4);
$movedArray = (array) \str_split($moved);
$new = '';
foreach ($movedArray as $key => $value) {
if (!is_numeric($movedArray[$key])) {
if (!\is_numeric($movedArray[$key])) {
$movedArray[$key] = $chars[$movedArray[$key]];
}
$new .= $movedArray[$key];
}
return bcmod($new, '97') == 1;
return \bcmod($new, '97') == 1;
}
}

View File

@ -34,6 +34,8 @@ final class Validator extends ValidatorAbstract
* @param array $constraints Constraints for validation
*
* @return bool
*
* @throws \Exception
*
* @since 1.0.0
*/
@ -44,14 +46,13 @@ final class Validator extends ValidatorAbstract
}
foreach ($constraints as $test => $settings) {
$callback = StringUtils::endsWith($test, 'Not') ? substr($test, 0, -3) : $test;
$callback = StringUtils::endsWith($test, 'Not') ? \substr($test, 0, -3) : (string) $test;
if (!empty($settings)) {
$valid = $callback($var, ...$settings);
} else {
$valid = $callback($var);
if (!\is_callable($callback)) {
throw new \Exception();
}
$valid = !empty($settings) ? $callback($var, ...$settings) : $callback($var);
$valid = (StringUtils::endsWith($test, 'Not') ? !$valid : $valid);
if (!$valid) {

View File

@ -203,7 +203,7 @@ abstract class ViewAbstract implements \Serializable
public function serialize() : string
{
if (empty($this->template)) {
return \json_encode($this->toArray());
return (string) \json_encode($this->toArray());
}
return $this->render();
@ -253,10 +253,10 @@ abstract class ViewAbstract implements \Serializable
ob_start();
/** @noinspection PhpIncludeInspection */
$includeData = include $path;
$ob = ob_get_clean();
$ob = (string) ob_get_clean();
if (is_array($includeData)) {
return \json_encode($includeData);
return (string) \json_encode($includeData);
}
} catch (\Throwable $e) {
$ob = '';