Showing 211 of 211 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
x.SubjectCode === y.SubjectCode &&
x.Type === y.Type &&
x.Day === y.Day &&
x.TimePeriod === y.TimePeriod
- 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 61.
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
x.Uid !== y.Uid &&
x.SubjectCode === y.SubjectCode &&
x.Type === y.Type &&
x.Day === y.Day &&
- 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 61.
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 GenerateNewState
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected GenerateNewState(state: IMasterState): IMasterState {
const newClickedTimeConstraint =
state.SetTimeConstraintState.ClickedTimeConstraint.slice();
newClickedTimeConstraint[this.clickedBox.Day] ^= this.clickedBox.TimePeriod;
const newUidsOfClickedBox =
Function mapDispatchToProps
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
const mapDispatchToProps = (dispatch: any): ITimetableListViewDispatchProps => {
const triggerfulDispatch = (action: MasterStateAction) => {
dispatch(action);
dispatch(new FindAlternativeSlotsOfCurrentSlots());
};
Function SelectSubject
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function SelectSubject(
subjectToBeSelected: Subject,
allSubjects: Subject[],
state: IMasterState
): IMasterState {
Function ParseRawSlotToSubject
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function ParseRawSlotToSubject(slots: RawSlot[]): Subject[] {
const result = Array<Subject>();
const dic = new Array<IKeyValue<string, RawSlot[]>>();
slots
.filter((x) => IsReasonable(x) && IsParsable(x))
Function CreateEvent
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function CreateEvent(slot: RawSlot, semesterStartDate: Date) {
const semStartDate = new Date(semesterStartDate.getTime());
if (semStartDate.getDay() !== 1) {
throw new Error(
"Expected semesterStartDay to be Monday but was " +
Function correctBounds
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function correctBounds(layout, bounds) {
var collidesWith = getStatics(layout);
for (var _i4 = 0, len = layout.length; _i4 < len; _i4++) {
var l = layout[_i4];
// Overflows right
- 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 GenerateSlotAndDayLayouts
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function GenerateSlotAndDayLayouts(
rawSlots: ISlotViewModel[],
xOffset: number,
yOffset: number
): [ReactGridLayout.Layout[], ReactGridLayout.Layout[]] {
Function GetTimeRow
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
private GetTimeRow(): JSX.Element[] {
const divStyle: React.CSSProperties = {
borderBottom: "1px solid",
borderRight: "1px solid",
height: "20.5px",
Function placeholder
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
ReactGridLayout.prototype.placeholder = function placeholder() {
var activeDrag = this.state.activeDrag;
if (!activeDrag) return null;
var _props3 = this.props,
Function slotViews
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
const slotViews = slots.map((x, index) => {
return (
// "s" means "Slot"
<div key={"s" + index}>
<SlotView
Function GeneralizeSlot
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function GeneralizeSlot(originalSlots: RawSlot[]): RawSlot[] {
const slots = originalSlots.map(clone) as IRawSlot[];
const results = new Array<RawSlot>();
results.push(slots[0]);
let generalized: boolean;
Function DeselectSubject
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function DeselectSubject(
subjectToBeDeselected: Subject,
allSubjects: Subject[],
state: IMasterState
): IMasterState {
Function GenerateNewState
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected GenerateNewState(state: IMasterState): IMasterState {
const targetSubject = find(state.SubjectListState.Subjects, {
Code: this.subjectCode,
}) as Subject;
let selectedSlotsCount = 0;
Function findSisterSlots
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function findSisterSlots(
slotsOfCurrentTimetable: IRawSlot[],
allSlots: IRawSlot[]
): IRawSlot[] {
const currentSlotsAsBigSlots = slotsOfCurrentTimetable.map((x) =>
Function moveElement
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function moveElement(layout, l, x, y, isUserAction, preventCollision, compactType, cols) {
if (l.static) return layout;
// Short-circuit if nothing to do.
if (l.y === y && l.x === x) return layout;
Function GenerateNewState
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected GenerateNewState(state: IMasterState): IMasterState {
const [filtrate, residue] = Filter(
state.TimetableListState.FiltrateTimetables,
this.clickedState
);
Function Legend
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
const Legend = (props: ILegendProps) => {
const background = () => {
switch (props.type) {
case "red":
return ColorOfDefinitelyOccupied;
Function LoadSlotsFromUrl
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
export const LoadSlotsFromUrl = (
downloadUrl: string,
fileType: string,
started: () => void,
successed: (loadedSlots: IRawSlot[]) => void,