Showing 248 of 248 total issues
File chessboard-0.3.0.js
has 1067 lines of code (exceeds 275 allowed). Consider refactoring. Open
/*!
* chessboard.js v0.3.0
*
* Copyright 2013 Chris Oakman
* Released under the MIT license
Similar blocks of code found in 2 locations. Consider refactoring. Open
function mouseleaveSquare(e) {
// do not fire this event if we are dragging a piece
// NOTE: this should never happen, but it's a safeguard
if (DRAGGING_A_PIECE !== false) return;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 154.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
function mouseenterSquare(e) {
// do not fire this event if we are dragging a piece
// NOTE: this should never happen, but it's a safeguard
if (DRAGGING_A_PIECE !== false) return;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 154.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function queens_under_attack
has a Cognitive Complexity of 25 (exceeds 11 allowed). Consider refactoring. Open
function queens_under_attack($board)
{
global $attacked; // for display outside of this function
if (!is_array($board)) {
return '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
Function expandConfig
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
function expandConfig() {
if (typeof cfg === 'string' || validPositionObject(cfg) === true) {
cfg = {
position: cfg
};
Function calculateAnimations
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
function calculateAnimations(pos1, pos2) {
// make copies of both
pos1 = deepCopy(pos1);
pos2 = deepCopy(pos2);
Function buildBoard
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
function buildBoard(orientation) {
if (orientation !== 'black') {
orientation = 'white';
}
Function checkDeps
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
function checkDeps() {
// if containerId is a string, it must be the ID of a DOM node
if (typeof containerElOrId === 'string') {
// cannot be empty
if (containerElOrId === '') {
Method queens_under_attack
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
function queens_under_attack($board)
{
global $attacked; // for display outside of this function
if (!is_array($board)) {
return 'ERROR';
Function stopDraggedPiece
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
function stopDraggedPiece(location) {
// determine what the action should be
var action = 'drop';
if (location === 'offboard' && cfg.dropOffBoard === 'snapback') {
action = 'snapback';
Function doAnimations
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function doAnimations(a, oldPos, newPos) {
ANIMATION_HAPPENING = true;
var numFinished = 0;
function onFinish() {
Avoid using undefined variables such as '$result' which will lead to PHP notices. Open
$result[$name] = $value + $arrayB[$name];
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$result' which will lead to PHP notices. Open
return $result;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$tmp' which will lead to PHP notices. Open
$tmp[strlen(decbin($row[$checkRow])) - 1] = 1 << ($board - $checkRow - 1);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Method findRotation
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function findRotation($row, $board, $solutions)
{
$tmp = rotateBoard($row, $board); // Rotated 90
if (!in_array($tmp, $solutions)) {
$solutions[] = $tmp;
Function position
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
widget.position = function(position, useAnimation) {
// no arguments, return the current position
if (arguments.length === 0) {
return deepCopy(CURRENT_POSITION);
}
Function objToFen
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function objToFen(obj) {
if (validPositionObject(obj) !== true) {
return false;
}
Function animateSquareToSquare
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function animateSquareToSquare(src, dest, piece, completeFn) {
// get information about the source and destination squares
var srcSquareEl = $('#' + SQUARE_ELS_IDS[src]);
var srcSquarePosition = srcSquareEl.offset();
var destSquareEl = $('#' + SQUARE_ELS_IDS[dest]);
Function beginDraggingPiece
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function beginDraggingPiece(source, piece, x, y) {
// run their custom onDragStart function
// their custom onDragStart function can cancel drag start
if (typeof cfg.onDragStart === 'function' &&
cfg.onDragStart(source, piece,
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 33 and the first side effect is on line 3. Open
<?php
- Exclude checks