Function emit
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public function emit()
{
$contentTypeSent = false;
foreach ($this->headers as $header) {
if (!$contentTypeSent && 0 === stripos($header, 'content-type')) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method emit
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function emit()
{
$contentTypeSent = false;
foreach ($this->headers as $header) {
if (!$contentTypeSent && 0 === stripos($header, 'content-type')) {
Function emitText
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function emitText()
{
if (null === $this->result) {
if (\is_string($this->error)) {
echo $this->error;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The method emit() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public function emit()
{
$contentTypeSent = false;
foreach ($this->headers as $header) {
if (!$contentTypeSent && 0 === stripos($header, 'content-type')) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Refactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed. Open
public function emit()
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
The method setError has a boolean flag argument $trace, which is a certain sign of a Single Responsibility Principle violation. Open
public function setError($code = 500, $message = null, $trace = false): void
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method emitText uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (\is_string($this->result)) {
echo $this->result;
} else {
echo \App\Json::encode($this->prepareResponse());
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\App\Language' in method 'setException'. Open
$reasonPhrase = $error['message'] = $show ? $message : \App\Language::translate('ERR_OCCURRED_ERROR');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method prepareResponse uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$response['success'] = true;
$response['result'] = $this->result;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method emitText uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
echo \App\Json::encode($this->prepareResponse());
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method emitText uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
echo \App\Json::encode($this->prepareResponse());
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\App\Json' in method 'emitText'. Open
echo \App\Json::encode($this->prepareResponse());
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Request' in method 'setException'. Open
$this->setHeader(\App\Request::_getServer('SERVER_PROTOCOL') . ' ' . $statusCode . ' ' . str_ireplace(["\r\n", "\r", "\n"], ' ', $reasonPhrase));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Json' in method 'emitJSON'. Open
echo \App\Json::encode($this->prepareResponse());
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Json' in method 'emitText'. Open
echo \App\Json::encode($this->prepareResponse());
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "message" 3 times. Open
$error = ['code' => $code, 'message' => $message, 'trace' => $trace];
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Suspicious type false
of a variable or expression used to build a string. (Expected type to be able to cast to a string) Open
echo $this->emitJSONPFn . '(';
- Exclude checks
array to string
conversion Open
echo $this->error;
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Vtiger_Response
- Exclude checks
The class Vtiger_Response is not named in CamelCase. Open
class Vtiger_Response
{
// Constants
/**
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The property $EMIT_RAW is not named in camelCase. Open
class Vtiger_Response
{
// Constants
/**
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $EMIT_JSONTEXT is not named in camelCase. Open
class Vtiger_Response
{
// Constants
/**
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $EMIT_JSON is not named in camelCase. Open
class Vtiger_Response
{
// Constants
/**
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Avoid variables with short names like $fn. Configured minimum length is 3. Open
public function setEmitJSONP($fn)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The property $EMIT_HTML is not named in camelCase. Open
class Vtiger_Response
{
// Constants
/**
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $EMIT_JSONP is not named in camelCase. Open
class Vtiger_Response
{
// Constants
/**
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Avoid variables with short names like $e. Configured minimum length is 3. Open
public function setException(Throwable $e): void
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Spaces must be used to indent lines; tabs are not allowed Open
private $emitJSONPFn = false; // for EMIT_JSONP
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = $e->getMessage();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($show && ($e instanceof \App\Exceptions\AppException)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $type
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $code
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setError($code = 500, $message = null, $trace = false): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$reasonPhrase = $error['message'] = $show ? $message : \App\Language::translate('ERR_OCCURRED_ERROR');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static $EMIT_JSONP = 4;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setHeader($header)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set headers to send.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Throwable $e
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$show = \Config\Debug::$EXCEPTION_ERROR_TO_SHOW || 0 === strpos($message, 'ERR_');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set emit type.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setEmitType($type)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $result
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static $EMIT_HTML = 2;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Emit response wrapper as padded-json.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set error data to send.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set exception error to send.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->setHeader(\App\Request::_getServer('SERVER_PROTOCOL') . ' ' . $statusCode . ' ' . str_ireplace(["\r\n", "\r", "\n"], ' ', $reasonPhrase));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static $EMIT_RAW = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Result data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// List of response headers
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\Config\Debug::$DISPLAY_EXCEPTION_BACKTRACE) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error['message'] = $e->getDisplayMessage();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->error = $error;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return null !== $this->error;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Update the result data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $key
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Error data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->headers[] = $header;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed|null $message
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $message) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'code' => $e->getCode(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Constants
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Emit response wrapper as json string.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $trace
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (is_numeric($code)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statusCode = \is_int($e->getCode()) ? $e->getCode() : 500;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error['trace'] = str_replace(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR, '', $e->getTraceAsString());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setResult($result)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Emit response wrapper as string/jsonstring.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $headers = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->error = $error;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->emitJSONPFn = $fn;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Is emit type configured to JSON?
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set the result data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Emit response wrapper as html string.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->error;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $error;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->emitType = $type;
- Exclude checks
Line exceeds 120 characters; contains 153 characters Open
$this->setHeader(\App\Request::_getServer('SERVER_PROTOCOL') . ' ' . $statusCode . ' ' . str_ireplace(["\r\n", "\r", "\n"], ' ', $reasonPhrase));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->result = $result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static $EMIT_JSONTEXT = 3;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Emit response wrapper as raw string.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static $EMIT_JSON = 1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error = ['code' => $code, 'message' => $message, 'trace' => $trace];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $emitType = 1; // EMIT_JSON
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $header
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get the error data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setException(Throwable $e): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set padding method name for JSONP emit type.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setEmitJSONP($fn)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->emitType == self::$EMIT_JSON;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getError()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
http_response_code($code);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $fn
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->setEmitType(self::$EMIT_JSONP);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check the presence of error data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Active emit type
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// JSONP padding
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = $code;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
http_response_code($statusCode);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function isJSON()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function hasError()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$contentTypeSent) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->emitText();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($this->emitType == self::$EMIT_RAW) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$contentTypeSent) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('content-type: application/javascript; charset=UTF-8');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $this->result) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\is_string($this->error)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $this->result) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo $this->result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null !== $this->error) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('content-type: text/plain; charset=UTF-8');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Prepare the response wrapper.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response['success'] = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($this->emitType == self::$EMIT_HTML) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo $this->emitJSONPFn . '(';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Emit response wrapper as String/JSONString.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\is_string($this->result)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected function emitRaw()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$contentTypeSent && 0 === stripos($header, 'content-type')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->emitType == self::$EMIT_JSON) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('content-type: text/json; charset=UTF-8');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Emit response wrapper as String.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header($header);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->emitRaw();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($this->emitType == self::$EMIT_JSONP) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected function emitText()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $value
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$contentTypeSent) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo ')';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo \App\Json::encode($this->prepareResponse());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo $this->result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected function prepareResponse()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response['success'] = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->headers as $header) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('content-type: text/html; charset=UTF-8');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->emitRaw();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->result[$key] = $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Send response to client.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$contentTypeSent = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response['result'] = $this->result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->emitJSON();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get the result data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getResult()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function emit()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo $this->error;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Set right charset (UTF-8) to avoid IE complaining about c00ce56e error
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$contentTypeSent) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->emitJSON();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($this->emitType == self::$EMIT_JSONTEXT) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('content-type: text/json; charset=UTF-8');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response['error'] = $this->error;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Emit response wrapper as JSONString.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo \App\Json::encode($this->prepareResponse());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo (\is_string($this->error)) ? $this->error : var_export($this->error, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function updateResult($key, $value)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $response;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$contentTypeSent = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$contentTypeSent) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected function emitJSON()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo \App\Json::encode($this->prepareResponse());
- Exclude checks
Class name "Vtiger_Response" is not in camel caps format Open
class Vtiger_Response
- Exclude checks