Skip to content

Commit

Permalink
Magic Numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
az108 committed May 29, 2024
1 parent 1e05a62 commit 707efef
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/webapp/app/course/course-access-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { LocalStorageService } from 'ngx-webstorage';
export class CourseAccessStorageService {
private static readonly STORAGE_KEY = 'artemis.courseAccess';

Check warning on line 8 in src/main/webapp/app/course/course-access-storage.service.ts

View check run for this annotation

Teamscale 2 / teamscale-findings

src/main/webapp/app/course/course-access-storage.service.ts#L8

[New] Strings must use doublequote. https://demo.teamscale.io/findings.html#details/artemis?t=feature%2Fgeneral%2Fcourse-switching%3AHEAD&id=4D566A2A09BDC6CAFAA0F53C9C0373AB
private static readonly STORAGE_KEY_DROPDOWN = 'artemis.courseAccessDropdown';

Check warning on line 9 in src/main/webapp/app/course/course-access-storage.service.ts

View check run for this annotation

Teamscale 2 / teamscale-findings

src/main/webapp/app/course/course-access-storage.service.ts#L9

[New] Strings must use doublequote. https://demo.teamscale.io/findings.html#details/artemis?t=feature%2Fgeneral%2Fcourse-switching%3AHEAD&id=9A0D5DA6496994FB9FA51AC6E7C94FFD
private static readonly MAX_RECENTLY_ACCESSED_COURSES_OVERVIEW = 3;
private static readonly MAX_RECENTLY_ACCESSED_COURSES_DROPDOWN = 5;

constructor(private localStorage: LocalStorageService) {}

Check warning on line 13 in src/main/webapp/app/course/course-access-storage.service.ts

View check run for this annotation

Teamscale 2 / teamscale-findings

src/main/webapp/app/course/course-access-storage.service.ts#L13

[New] Missing space before function parentheses. https://demo.teamscale.io/findings.html#details/artemis?t=feature%2Fgeneral%2Fcourse-switching%3AHEAD&id=0DD77EEE232E59DA19927D83D0A2EA5B

Check warning on line 13 in src/main/webapp/app/course/course-access-storage.service.ts

View check run for this annotation

Teamscale 2 / teamscale-findings

src/main/webapp/app/course/course-access-storage.service.ts#L13

[New] 'localStorage' is defined but never used. https://demo.teamscale.io/findings.html#details/artemis?t=feature%2Fgeneral%2Fcourse-switching%3AHEAD&id=197313265174DB4BB60C30E58EE8816A

Expand All @@ -15,7 +17,7 @@ export class CourseAccessStorageService {

courseAccessMap[courseId] = Date.now();

if (Object.keys(courseAccessMap).length > 3) {
if (Object.keys(courseAccessMap).length > CourseAccessStorageService.MAX_RECENTLY_ACCESSED_COURSES_OVERVIEW) {
const oldestEntry = Object.entries(courseAccessMap).reduce((prev, curr) => (prev[1] < curr[1] ? prev : curr));

Check warning on line 21 in src/main/webapp/app/course/course-access-storage.service.ts

View check run for this annotation

Teamscale 2 / teamscale-findings

src/main/webapp/app/course/course-access-storage.service.ts#L21

[New] Ternary operator used. https://demo.teamscale.io/findings.html#details/artemis?t=feature%2Fgeneral%2Fcourse-switching%3AHEAD&id=53BFA5B33A25DDE7765F1455910E7521

Check failure on line 21 in src/main/webapp/app/course/course-access-storage.service.ts

View check run for this annotation

Teamscale 2 / teamscale-findings

src/main/webapp/app/course/course-access-storage.service.ts#L21

[New] Unnecessary parentheses around expression. https://demo.teamscale.io/findings.html#details/artemis?t=feature%2Fgeneral%2Fcourse-switching%3AHEAD&id=EDFDE1D910BB02594456AD0C79E6442F

Check warning on line 21 in src/main/webapp/app/course/course-access-storage.service.ts

View check run for this annotation

Teamscale 2 / teamscale-findings

src/main/webapp/app/course/course-access-storage.service.ts#L21

[New] Unnecessary parentheses around expression. https://demo.teamscale.io/findings.html#details/artemis?t=feature%2Fgeneral%2Fcourse-switching%3AHEAD&id=F811956BAAD9D2FB32E6AC95C55528DA
delete courseAccessMap[oldestEntry[0]];
}
Expand All @@ -35,8 +37,8 @@ export class CourseAccessStorageService {
const courseAccessMap: { [key: number]: number } = this.localStorage.retrieve(CourseAccessStorageService.STORAGE_KEY_DROPDOWN) || {};

courseAccessMap[courseId] = Date.now();

if (Object.keys(courseAccessMap).length > 6) {
// we add +1 because the current course should not be displayed in the dropdown and therefore gets removed from the list later
if (Object.keys(courseAccessMap).length > CourseAccessStorageService.MAX_RECENTLY_ACCESSED_COURSES_DROPDOWN + 1) {
const oldestEntry = Object.entries(courseAccessMap).reduce((prev, curr) => (prev[1] < curr[1] ? prev : curr));

Check warning on line 42 in src/main/webapp/app/course/course-access-storage.service.ts

View check run for this annotation

Teamscale 2 / teamscale-findings

src/main/webapp/app/course/course-access-storage.service.ts#L42

[New] Ternary operator used. https://demo.teamscale.io/findings.html#details/artemis?t=feature%2Fgeneral%2Fcourse-switching%3AHEAD&id=28C04EB0744ABDC2ECE061F2E77098C4

Check failure on line 42 in src/main/webapp/app/course/course-access-storage.service.ts

View check run for this annotation

Teamscale 2 / teamscale-findings

src/main/webapp/app/course/course-access-storage.service.ts#L42

[New] Unnecessary parentheses around expression. https://demo.teamscale.io/findings.html#details/artemis?t=feature%2Fgeneral%2Fcourse-switching%3AHEAD&id=AB36F2BB36BC0267A069D4F1E00AEEFB

Check warning on line 42 in src/main/webapp/app/course/course-access-storage.service.ts

View check run for this annotation

Teamscale 2 / teamscale-findings

src/main/webapp/app/course/course-access-storage.service.ts#L42

[New] Unnecessary parentheses around expression. https://demo.teamscale.io/findings.html#details/artemis?t=feature%2Fgeneral%2Fcourse-switching%3AHEAD&id=F97CE92E4FF08930418CA2911775E352
delete courseAccessMap[oldestEntry[0]];
}
Expand Down

0 comments on commit 707efef

Please sign in to comment.