app/Json.php
Missing class import via use statement (line '45', column '13'). Open
Open
throw new \App\Exceptions\AppException('ERR_NO_JSON_DECODE');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '68', column '13'). Open
Open
throw new \App\Exceptions\AppException('ERR_NO_JSON_ENCODE');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Argument 2 (assoc)
is int
but \json_decode()
takes bool
Open
Open
return json_decode($encodedValue, $objectDecodeType);
- Exclude checks
Argument 2 (objectDecodeType)
is true
but \App\Json::decode()
takes int
defined at /code/app/Json.php:37
Open
Open
return static::decode(file_get_contents($path), true) ?? [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const TYPE_ARRAY = 1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @see https://secure.php.net/manual/en/function.json-decode.php
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
throw new \App\Exceptions\AppException('ERR_NO_JSON_DECODE');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
throw new \App\Exceptions\AppException('ERR_NO_JSON_ENCODE');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param int $objectDecodeType Optional; When TRUE, returned objects will be converted into associative arrays
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return empty($value) || '[]' === $value || '""' === $value;
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
Open
return !(null === $value || '' === $value || null === self::decode($value) || JSON_ERROR_NONE !== \json_last_error());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param mixed $valueToEncode
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param int $options Optional; whether or not to check for object recursion; off by default
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string|null $value
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function isEmpty(?string $value)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Check that a string is a valid JSON string.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* encoded in the JSON format.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return mixed
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* NOTE: Object should not contain cycles; the JSON format
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (null === $encodedValue) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const TYPE_OBJECT = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function decode($encodedValue, $objectDecodeType = self::TYPE_ARRAY)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* NOTE: Only public variables will be encoded
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (\function_exists('json_encode')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* ext/json's functions.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Decodes the given $encodedValue string which is
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Encode the mixed $valueToEncode into the JSON format.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Encodes using ext/json's json_encode() if available.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return !(null === $value || '' === $value || null === self::decode($value) || JSON_ERROR_NONE !== \json_last_error());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* How objects should be encoded -- arrays or as StdClass. TYPE_ARRAY is 1
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Determine whether a variable is empty.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string|null $value
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* so that it is a boolean true value, allowing it to be used with
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (\function_exists('json_decode')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return string JSON encoded object
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function isJson(?string $value): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $encodedValue Encoded in JSON format
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* does not allow object reference.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Read json file to array.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @throws \App\Exceptions\AppException
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @throws \App\Exceptions\AppException
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return json_decode($encodedValue, $objectDecodeType);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return json_encode($valueToEncode, $options | JSON_UNESCAPED_UNICODE);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $path
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Uses ext/json's json_decode if available.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function encode($valueToEncode, $options = 0)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function save(string $path, array $data)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function read(string $path)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return static::decode(file_get_contents($path), true) ?? [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Save json file from array.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return \file_put_contents($path, static::encode($data, JSON_PRETTY_PRINT), LOCK_EX);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $path
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return bool|int
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param array $data
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks