kevinanielsen/flags-game

View on GitHub

Showing 7 of 13 total issues

Function LeaderBoard has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const LeaderBoard = () => {
  const { data, isLoading, error } = useQuery({
    queryKey: ["top-scores"],
    queryFn: async () => {
      const res = await axios.get<TScore[]>("/api/top-scores");
Severity: Minor
Found in components/leaderboard.tsx - About 1 hr to fix

Function POST has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export async function POST(req: NextRequest) {
  const headersList = headers();
  const ip = headersList.get("x-forwarded-for") ?? "127.0.0.1";

  const { success, reset } = await ratelimit.limit(ip);
Severity: Minor
Found in app/api/score/route.ts - About 1 hr to fix

Function handleSubmit has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
    e.preventDefault();

    if (name.length === 0) {
      toast({ title: "Missing Name", variant: "error" });
Severity: Minor
Found in components/game/end-game-input.tsx - About 1 hr to fix

Function POST has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

export async function POST(req: NextRequest) {
  const headersList = headers();
  const ip = headersList.get("x-forwarded-for") ?? "127.0.0.1";

  const { success, reset } = await ratelimit.limit(ip);
Severity: Minor
Found in app/api/score/route.ts - About 35 mins to fix

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

Avoid too many return statements within this function.
Open

    return NextResponse.json(error, { status: 500 });
Severity: Major
Found in app/api/score/route.ts - About 30 mins to fix

Avoid too many return statements within this function.
Open

    return NextResponse.json(dbEntry, { status: 200, statusText: "OK" });
Severity: Major
Found in app/api/score/route.ts - About 30 mins to fix

Function EndGameInput has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

const EndGameInput: React.FC<TEndGameInput> = ({
  final_score,
  gameStartTime,
  gameEndTime,
}) => {
Severity: Minor
Found in components/game/end-game-input.tsx - About 25 mins to fix

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

Severity
Category
Status
Source
Language