File Repl.php
has 423 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Quack Compiler and toolkit
* Copyright (C) 2015-2017 Quack and CONTRIBUTORS
*
Repl
has 32 functions (exceeds 20 allowed). Consider refactoring. Open
class Repl extends Component
{
private $console;
private $croak;
private $modules = [];
The class Repl has an overall complexity of 77 which is very high. The configured complexity threshold is 50. Open
class Repl extends Component
{
private $console;
private $croak;
private $modules = [];
- Exclude checks
The class Repl has 31 non-getter- and setter-methods. Consider refactoring Repl to keep number of methods under 25. Open
class Repl extends Component
{
private $console;
private $croak;
private $modules = [];
- Read upRead up
- Exclude checks
TooManyMethods
Since: 0.1
A class with too many 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'.
The default was changed from 10 to 25 in PHPMD 2.3.
Example
Source https://phpmd.org/rules/codesize.html#toomanymethods
Method compile
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function compile($source, $silent = false)
{
if ('' === $source) {
$this->resetState();
return;
Method handleListDefinitions
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleListDefinitions()
{
$renderer = new CliColorizer();
$context = $this->state('scope')->child;
Method render
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
Function compile
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function compile($source, $silent = false)
{
if ('' === $source) {
$this->resetState();
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 handleListDefinitions
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function handleListDefinitions()
{
$renderer = new CliColorizer();
$context = $this->state('scope')->child;
- 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
Remove error control operator '@' on line 165. Open
private function handleDownArrow()
{
list ($history, $index) = $this->state('history', 'history_index');
$line = @$history[count($history) - ($index - 1)];
if (null !== $line) {
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
The method compile has a boolean flag argument $silent, which is a certain sign of a Single Responsibility Principle violation. Open
private function compile($source, $silent = false)
- 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
Remove error control operator '@' on line 152. Open
private function handleUpArrow()
{
list ($history, $index) = $this->state('history', 'history_index');
$line = @$history[count($history) - ($index + 1)];
if (null !== $line) {
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
The method handleShowType uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->console->setColor(Console::FG_RED);
$this->console->writeln("I don't know what `$variable' is. Sorry!");
$this->console->resetColor();
}
- 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 '\QuackCompiler\Intl\Localization' in method 'intercept'. Open
$this->console->writeln(Localization::message('QUA010', [$command]));
- 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 start uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->compile($line);
}
- 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 '\QuackCompiler\Intl\Localization' in method 'intercept'. Open
$this->console->writeln(Localization::message('QUA020', []));
- 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 compile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (!$silent) {
$this->console->write($parser->beautify());
}
$this->state('ast')->attachValidAST($parser->ast);
- 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 unused private methods such as 'handleCtrlRightArrow'. Open
private function handleCtrlRightArrow()
{
$boundaries = $this->getBoundaries();
list ($line, $column) = $this->state('line', 'column');
$next_boundary = reset(array_filter($boundaries, function ($boundary) use ($column) {
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleUpArrow'. Open
private function handleUpArrow()
{
list ($history, $index) = $this->state('history', 'history_index');
$line = @$history[count($history) - ($index + 1)];
if (null !== $line) {
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleDownArrow'. Open
private function handleDownArrow()
{
list ($history, $index) = $this->state('history', 'history_index');
$line = @$history[count($history) - ($index - 1)];
if (null !== $line) {
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleListDefinitionsKey'. Open
private function handleListDefinitionsKey()
{
$context = $this->state('scope')->child;
if (0 !== sizeof($context->table)) {
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleLeftArrow'. Open
private function handleLeftArrow()
{
$column = $this->state('column');
$this->setState(['column' => max(0, $column - 1)]);
}
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleDelete'. Open
private function handleDelete()
{
list ($line, $column) = $this->state('line', 'column');
if ($column === count($line)) {
return;
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleCtrlA'. Open
private function handleCtrlA()
{
$this->setState(['column' => 0]);
}
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleInsert'. Open
private function handleInsert()
{
$insert = $this->state('insert');
$this->setState(['insert' => !$insert]);
}
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleHome'. Open
private function handleHome()
{
$this->setState(['column' => 0]);
}
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleBackspace'. Open
private function handleBackspace()
{
list ($line, $column) = $this->state('line', 'column');
if (0 === $column) {
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleCtrlLeftArrow'. Open
private function handleCtrlLeftArrow()
{
$boundaries = $this->getBoundaries();
$column = $this->state('column');
$previous_boundary = end(array_filter($boundaries, function ($boundary) use ($column) {
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
The method handleQuit() contains an exit expression. Open
exit;
- 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
Avoid unused private methods such as 'handleEnd'. Open
private function handleEnd()
{
$this->setState(['column' => count($this->state('line'))]);
}
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
Avoid unused private methods such as 'handleRightArrow'. Open
private function handleRightArrow()
{
list ($line, $column) = $this->state('line', 'column');
$this->setState(['column' => min(count($line), $column + 1)]);
}
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
TODO found Open
// TODO: We can give color after embedding the tokenizer here
- Exclude checks
The variable $previous_boundary is not named in camelCase. Open
private function handleCtrlLeftArrow()
{
$boundaries = $this->getBoundaries();
$column = $this->state('column');
$previous_boundary = end(array_filter($boundaries, function ($boundary) use ($column) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $text_size is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $next_char is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $previous_boundary is not named in camelCase. Open
private function handleCtrlLeftArrow()
{
$boundaries = $this->getBoundaries();
$column = $this->state('column');
$previous_boundary = end(array_filter($boundaries, function ($boundary) use ($column) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $next_boundary is not named in camelCase. Open
private function handleCtrlRightArrow()
{
$boundaries = $this->getBoundaries();
list ($line, $column) = $this->state('line', 'column');
$next_boundary = reset(array_filter($boundaries, function ($boundary) use ($column) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $line_string is not named in camelCase. Open
private function handleKeyPress($input)
{
if (ctype_cntrl($input)) {
return;
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $prompt_color is not named in camelCase. Open
private function renderPrompt($color = Console::FG_YELLOW)
{
$prompt = $this->state('complete') ? 'Quack> ' : '.....> ';
$prompt_color = $this->state('complete') ? $color : Console::FG_BOLD_GREEN;
$this->console->setColor($prompt_color);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $next_buffer is not named in camelCase. Open
private function handleKeyPress($input)
{
if (ctype_cntrl($input)) {
return;
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $line_string is not named in camelCase. Open
private function handleKeyPress($input)
{
if (ctype_cntrl($input)) {
return;
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $next_char is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $show_left_scroll is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $next_buffer is not named in camelCase. Open
private function handleKeyPress($input)
{
if (ctype_cntrl($input)) {
return;
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $text_size is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $previous_boundary is not named in camelCase. Open
private function handleCtrlLeftArrow()
{
$boundaries = $this->getBoundaries();
$column = $this->state('column');
$previous_boundary = end(array_filter($boundaries, function ($boundary) use ($column) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $prompt_color is not named in camelCase. Open
private function renderPrompt($color = Console::FG_YELLOW)
{
$prompt = $this->state('complete') ? 'Quack> ' : '.....> ';
$prompt_color = $this->state('complete') ? $color : Console::FG_BOLD_GREEN;
$this->console->setColor($prompt_color);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $colored_line is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $text_size is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $next_boundary is not named in camelCase. Open
private function handleCtrlRightArrow()
{
$boundaries = $this->getBoundaries();
list ($line, $column) = $this->state('line', 'column');
$next_boundary = reset(array_filter($boundaries, function ($boundary) use ($column) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $next_boundary is not named in camelCase. Open
private function handleCtrlRightArrow()
{
$boundaries = $this->getBoundaries();
list ($line, $column) = $this->state('line', 'column');
$next_boundary = reset(array_filter($boundaries, function ($boundary) use ($column) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $text_size is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $show_left_scroll is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $text_size is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $colored_line is not named in camelCase. Open
public function render()
{
$line = implode('', $this->state('line'));
$column = $this->state('column');
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}