File Request.php
has 483 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Phan\Daemon;
Function accept
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
public static function accept(CodeBase $code_base, Closure $file_path_lister, Responder $responder, bool $fork): ?Request
{
FileCache::clear();
$request = $responder->getRequestData();
- 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 accept
has 88 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function accept(CodeBase $code_base, Closure $file_path_lister, Responder $responder, bool $fork): ?Request
{
FileCache::clear();
$request = $responder->getRequestData();
The class Request has 16 public methods. Consider refactoring Request to keep number of public methods under 10. Open
class Request
{
public const METHOD_ANALYZE_FILES = 'analyze_files'; // has shorthand analyze_file with param 'file'
public const PARAM_METHOD = 'method';
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class Request has an overall complexity of 96 which is very high. The configured complexity threshold is 50. Open
class Request
{
public const METHOD_ANALYZE_FILES = 'analyze_files'; // has shorthand analyze_file with param 'file'
public const PARAM_METHOD = 'method';
- Exclude checks
Request
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
class Request
{
public const METHOD_ANALYZE_FILES = 'analyze_files'; // has shorthand analyze_file with param 'file'
public const PARAM_METHOD = 'method';
Function adjustFileMappingContentsForCompletionRequest
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private static function adjustFileMappingContentsForCompletionRequest(
array $file_mapping_contents,
CompletionRequest $completion_request
): array {
$file = FileRef::getProjectRelativePathForPath($completion_request->getPath());
- 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
Function applyTemporaryFileMappingForParsePhase
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private static function applyTemporaryFileMappingForParsePhase(CodeBase $code_base, array $temporary_file_mapping_contents): void
{
if (count($temporary_file_mapping_contents) === 0) {
return;
}
- 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
Function reloadFilePathListForDaemon
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function reloadFilePathListForDaemon(CodeBase $code_base, Closure $file_path_lister, array $file_mapping_contents, array $file_names = null): void
{
$old_count = $code_base->getParsedFilePathCount();
$file_list = $file_path_lister(true);
- 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
Function childSignalHandler
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static function childSignalHandler(int $signo, $status = null, ?int $pid = null): void
{
// test
if ($signo !== SIGCHLD) {
return;
- 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 applyTemporaryFileMappingForParsePhase
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function applyTemporaryFileMappingForParsePhase(CodeBase $code_base, array $temporary_file_mapping_contents): void
{
if (count($temporary_file_mapping_contents) === 0) {
return;
}
Method reloadFilePathListForDaemon
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function reloadFilePathListForDaemon(CodeBase $code_base, Closure $file_path_lister, array $file_mapping_contents, array $file_names = null): void
{
$old_count = $code_base->getParsedFilePathCount();
$file_list = $file_path_lister(true);
Method makeLanguageServerAnalysisRequest
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
Responder $responder,
array $file_names,
CodeBase $code_base,
Closure $file_path_lister,
FileMapping $file_mapping,
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return $request_obj;
The method accept() has an NPath complexity of 792. The configured NPath complexity threshold is 200. Open
public static function accept(CodeBase $code_base, Closure $file_path_lister, Responder $responder, bool $fork): ?Request
{
FileCache::clear();
$request = $responder->getRequestData();
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method accept() has 106 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public static function accept(CodeBase $code_base, Closure $file_path_lister, Responder $responder, bool $fork): ?Request
{
FileCache::clear();
$request = $responder->getRequestData();
- Exclude checks
The method accept() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10. Open
public static function accept(CodeBase $code_base, Closure $file_path_lister, Responder $responder, bool $fork): ?Request
{
FileCache::clear();
$request = $responder->getRequestData();
- 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
The class Request has a coupling between objects value of 24. Consider to reduce the number of dependencies under 13. Open
class Request
{
public const METHOD_ANALYZE_FILES = 'analyze_files'; // has shorthand analyze_file with param 'file'
public const PARAM_METHOD = 'method';
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
The method exit() contains an exit expression. Open
exit($exit_code);
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
The method getPrinter() contains an exit expression. Open
exit(0);
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}