Lint PHP code psr-12, add GH action
This commit is contained in:
@@ -53,13 +53,12 @@ class JsonFixer
|
||||
/**
|
||||
* Set/unset silent mode.
|
||||
*
|
||||
* @param bool $silent
|
||||
*
|
||||
* @param bool $silent
|
||||
* @return $this
|
||||
*/
|
||||
public function silent($silent = true)
|
||||
{
|
||||
$this->silent = (bool)$silent;
|
||||
$this->silent = (bool) $silent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -67,8 +66,7 @@ class JsonFixer
|
||||
/**
|
||||
* Set missing value.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return $this
|
||||
*/
|
||||
public function missingValue($value)
|
||||
@@ -87,16 +85,15 @@ class JsonFixer
|
||||
/**
|
||||
* Fix the truncated JSON.
|
||||
*
|
||||
* @param string $json The JSON string to fix.
|
||||
*
|
||||
* @param string $json The JSON string to fix.
|
||||
* @return string Fixed JSON. If failed with silent then original JSON.
|
||||
* @throws InvalidJsonException When fixing fails.
|
||||
*
|
||||
* @throws InvalidJsonException When fixing fails.
|
||||
*/
|
||||
public function fix($json)
|
||||
{
|
||||
$json = preg_replace('/(?<!\\\\)(?:\\\\{2})*\p{C}+/u', '', $json);
|
||||
list($head, $json, $tail) = $this->trim($json);
|
||||
[$head, $json, $tail] = $this->trim($json);
|
||||
|
||||
if (empty($json) || $this->isValid($json)) {
|
||||
return $json;
|
||||
@@ -108,7 +105,7 @@ class JsonFixer
|
||||
|
||||
$this->reset();
|
||||
|
||||
return $head . $this->doFix($json) . $tail;
|
||||
return $head.$this->doFix($json).$tail;
|
||||
}
|
||||
|
||||
protected function trim($json)
|
||||
@@ -125,15 +122,15 @@ class JsonFixer
|
||||
|
||||
protected function isValid($json)
|
||||
{
|
||||
\json_decode($json,true,512,JSON_INVALID_UTF8_SUBSTITUTE);
|
||||
\json_decode($json, true, 512, JSON_INVALID_UTF8_SUBSTITUTE);
|
||||
|
||||
return \JSON_ERROR_NONE === \json_last_error();
|
||||
return \json_last_error() === \JSON_ERROR_NONE;
|
||||
}
|
||||
|
||||
protected function quickFix($json)
|
||||
{
|
||||
if (\strlen($json) === 1 && isset($this->pairs[$json])) {
|
||||
return $json . $this->pairs[$json];
|
||||
return $json.$this->pairs[$json];
|
||||
}
|
||||
|
||||
if ($json[0] !== '"') {
|
||||
@@ -153,7 +150,7 @@ class JsonFixer
|
||||
|
||||
protected function maybeLiteral($json)
|
||||
{
|
||||
if (!\in_array($json[0], ['t', 'f', 'n'])) {
|
||||
if (! \in_array($json[0], ['t', 'f', 'n'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -170,14 +167,14 @@ class JsonFixer
|
||||
|
||||
protected function doFix($json)
|
||||
{
|
||||
list($index, $char) = [-1, ''];
|
||||
[$index, $char] = [-1, ''];
|
||||
|
||||
while (isset($json[++$index])) {
|
||||
list($prev, $char) = [$char, $json[$index]];
|
||||
[$prev, $char] = [$char, $json[$index]];
|
||||
|
||||
$next = isset($json[$index + 1]) ? $json[$index + 1] : '';
|
||||
|
||||
if (!\in_array($char, [' ', "\n", "\r"])) {
|
||||
if (! \in_array($char, [' ', "\n", "\r"])) {
|
||||
$this->stack($prev, $char, $index, $next);
|
||||
}
|
||||
}
|
||||
@@ -212,7 +209,7 @@ class JsonFixer
|
||||
protected function popToken($token = null)
|
||||
{
|
||||
// Last one
|
||||
if (null === $token) {
|
||||
if ($token === null) {
|
||||
return \array_pop($this->stack);
|
||||
}
|
||||
|
||||
@@ -228,7 +225,7 @@ class JsonFixer
|
||||
protected function maybeStr($prev, $char, $index)
|
||||
{
|
||||
if ($prev !== '\\' && $char === '"') {
|
||||
$this->inStr = !$this->inStr;
|
||||
$this->inStr = ! $this->inStr;
|
||||
}
|
||||
|
||||
if ($this->inStr && $this->lastToken() !== '"') {
|
||||
@@ -267,7 +264,7 @@ class JsonFixer
|
||||
}
|
||||
|
||||
\Log::debug('Broken json received: ', [
|
||||
'json' => $json
|
||||
'json' => $json,
|
||||
]);
|
||||
|
||||
throw new InvalidJsonException(
|
||||
|
||||
@@ -16,7 +16,7 @@ trait PadsJson
|
||||
{
|
||||
public function pad($tmpJson)
|
||||
{
|
||||
if (!$this->inStr) {
|
||||
if (! $this->inStr) {
|
||||
$tmpJson = \rtrim($tmpJson, ',');
|
||||
while ($this->lastToken() === ',') {
|
||||
$this->popToken();
|
||||
@@ -37,11 +37,11 @@ trait PadsJson
|
||||
|
||||
$match = \preg_match('/(tr?u?e?|fa?l?s?e?|nu?l?l?)$/', $tmpJson, $matches);
|
||||
|
||||
if (!$match || null === $literal = $this->maybeLiteral($matches[1])) {
|
||||
if (! $match || null === $literal = $this->maybeLiteral($matches[1])) {
|
||||
return $tmpJson;
|
||||
}
|
||||
|
||||
return \substr($tmpJson, 0, 0 - \strlen($matches[1])) . $literal;
|
||||
return \substr($tmpJson, 0, 0 - \strlen($matches[1])).$literal;
|
||||
}
|
||||
|
||||
protected function padStack($tmpJson)
|
||||
@@ -57,7 +57,7 @@ trait PadsJson
|
||||
|
||||
protected function padObject($tmpJson)
|
||||
{
|
||||
if (!$this->objectNeedsPadding($tmpJson)) {
|
||||
if (! $this->objectNeedsPadding($tmpJson)) {
|
||||
return $tmpJson;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ trait PadsJson
|
||||
}
|
||||
|
||||
$tmpJson = $this->padIf($tmpJson, ':');
|
||||
$tmpJson = $tmpJson . $this->missingValue;
|
||||
$tmpJson = $tmpJson.$this->missingValue;
|
||||
|
||||
if ($this->lastToken() === '"') {
|
||||
$this->popToken();
|
||||
@@ -82,19 +82,19 @@ trait PadsJson
|
||||
|
||||
protected function objectNeedsPadding($tmpJson)
|
||||
{
|
||||
$last = \substr($tmpJson, -1);
|
||||
$empty = $last === '{' && !$this->inStr;
|
||||
$last = \substr($tmpJson, -1);
|
||||
$empty = $last === '{' && ! $this->inStr;
|
||||
|
||||
return !$empty && $this->arrayPos < $this->objectPos;
|
||||
return ! $empty && $this->arrayPos < $this->objectPos;
|
||||
}
|
||||
|
||||
protected function padString($string)
|
||||
{
|
||||
$last = \substr($string, -1);
|
||||
$last = \substr($string, -1);
|
||||
$last2 = \substr($string, -2);
|
||||
|
||||
if ($last2 === '\"' || $last !== '"') {
|
||||
return $string . '"';
|
||||
return $string.'"';
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
@@ -105,7 +105,7 @@ trait PadsJson
|
||||
protected function padIf($string, $substr)
|
||||
{
|
||||
if (\substr($string, 0 - \strlen($substr)) !== $substr) {
|
||||
return $string . $substr;
|
||||
return $string.$substr;
|
||||
}
|
||||
|
||||
return $string;
|
||||
|
||||
Reference in New Issue
Block a user