Passed
Push — task/relative-resources ( 6eadd5...aef1bd )
by Tristan
06:08 queued 13s
created

resources/assets/js/helpers/routes.ts   A

Complexity

Total Complexity 40
Complexity/F 1.29

Size

Lines of Code 159
Function Count 31

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 40
eloc 120
mnd 9
bc 9
fnc 31
dl 0
loc 159
rs 9.2
bpm 0.2903
cpm 1.2903
noi 0
c 0
b 0
f 0

29 Functions

Rating   Name   Duplication   Size   Complexity  
A routes.ts ➔ basePathname 0 3 1
A routes.ts ➔ baseApiUrl 0 3 1
A routes.ts ➔ baseUrl 0 7 4
A routes.ts ➔ jobBuilderTasks 0 3 1
A routes.ts ➔ managerApplicationShow 0 7 1
A routes.ts ➔ hrScreeningPlan 0 2 1
A routes.ts ➔ jobBuilderIntro 0 6 2
A routes.ts ➔ managerScreeningPlan 0 3 1
A routes.ts ➔ managerJobPreview 0 3 1
A routes.ts ➔ managerApplicantShow 0 7 1
A routes.ts ➔ jobBuilderImpact 0 3 1
A routes.ts ➔ hrJobReview 0 2 1
A routes.ts ➔ jobBuilderSkills 0 3 1
A routes.ts ➔ hrJobApplications 0 2 1
A routes.ts ➔ accountSettings 0 3 1
A routes.ts ➔ applicationReviewUpdate 0 6 1
A routes.ts ➔ hrJobIndex 0 3 1
A routes.ts ➔ managerJobSummary 0 3 1
A routes.ts ➔ applicationShow 0 8 1
A routes.ts ➔ managerJobIndex 0 3 1
A routes.ts ➔ managerFaq 0 7 2
A routes.ts ➔ applicantShow 0 8 1
A routes.ts ➔ jobBuilderDetails 0 3 1
A routes.ts ➔ jobBuilderReview 0 3 1
A routes.ts ➔ managerJobApplications 0 3 1
A routes.ts ➔ hrJobSummary 0 2 1
A routes.ts ➔ hrJobPreview 0 2 1
A routes.ts ➔ managerEditProfile 0 3 1
A routes.ts ➔ jobBuilderEnv 0 3 1

How to fix   Complexity   

Complexity

Complex classes like resources/assets/js/helpers/routes.ts often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
function stripTrailingSlash(str: string): string {
2
  return str.endsWith("/") ? str.slice(0, -1) : str;
3
}
4
5
export function baseUrl(): string {
6
  const base = document.querySelector("head base");
7
  if (base !== null) {
8
    return stripTrailingSlash(base.getAttribute("href") ?? "");
9
  }
10
  return "";
11
}
12
13
export function basePathname(): string {
14
  return (new URL(baseUrl())).pathname;
15
}
16
17
export function baseApiUrl(version = 1): string {
18
  return `${baseUrl()}/api/v${version}`;
19
}
20
21
function applicationShow(
22
  locale: string,
23
  prefix: string,
24
  applicationId: number,
25
  jobId: number,
26
): string {
27
  return `/${locale}/${prefix}/jobs/${jobId}/applications/${applicationId}`;
28
}
29
30
function applicantShow(
31
  locale: string,
32
  prefix: string,
33
  applicantId: number,
34
  jobId: number,
35
): string {
36
  return `/${locale}/${prefix}/jobs/${jobId}/applicants/${applicantId}`;
37
}
38
39
export function managerApplicationShow(
40
  locale: string,
41
  applicationId: number,
42
  jobId: number,
43
): string {
44
  return applicationShow(locale, "manager", applicationId, jobId);
45
}
46
47
export function managerApplicantShow(
48
  locale: string,
49
  applicantId: number,
50
  jobId: number,
51
): string {
52
  return applicantShow(locale, "manager", applicantId, jobId);
53
}
54
55
export function managerEditProfile(locale: string): string {
56
  return `/${locale}/manager/profile`;
57
}
58
59
export function managerJobIndex(locale: string): string {
60
  return `/${locale}/manager/jobs`;
61
}
62
63
export function managerJobSummary(locale: string, jobId: number): string {
64
  return `/${locale}/manager/jobs/${jobId}`;
65
}
66
67
export function managerJobPreview(locale: string, jobId: number): string {
68
  return `/${locale}/manager/jobs/${jobId}/preview`;
69
}
70
71
export function managerJobApplications(locale: string, jobId: number): string {
72
  return `/${locale}/manager/jobs/${jobId}/applications`;
73
}
74
75
export function managerScreeningPlan(locale: string, jobId: number): string {
76
  return `/${locale}/manager/jobs/${jobId}/assessment-plan`;
77
}
78
79
export function applicationReviewUpdate(
80
  locale: string,
81
  applicationId: number,
82
): string {
83
  return `${baseApiUrl()}/applications/${applicationId}/review`;
84
}
85
86
export function jobBuilderIntro(locale: string, jobId?: number): string {
87
  if (jobId) {
88
    return `/${locale}/manager/jobs/${jobId}/builder/intro`;
89
  }
90
  return `/${locale}/manager/job-builder/intro`;
91
}
92
93
export function jobBuilderDetails(locale: string, jobId: number): string {
94
  return `/${locale}/manager/jobs/${jobId}/builder/details`;
95
}
96
97
export function jobBuilderEnv(locale: string, jobId: number): string {
98
  return `/${locale}/manager/jobs/${jobId}/builder/environment`;
99
}
100
101
export function jobBuilderImpact(locale: string, jobId: number): string {
102
  return `/${locale}/manager/jobs/${jobId}/builder/impact`;
103
}
104
105
export function jobBuilderTasks(locale: string, jobId: number): string {
106
  return `/${locale}/manager/jobs/${jobId}/builder/tasks`;
107
}
108
109
export function jobBuilderSkills(locale: string, jobId: number): string {
110
  return `/${locale}/manager/jobs/${jobId}/builder/skills`;
111
}
112
113
export function jobBuilderReview(locale: string, jobId: number): string {
114
  return `/${locale}/manager/jobs/${jobId}/builder/review`;
115
}
116
117
type FaqSection = "manager-who";
118
119
export function managerFaq(locale: string, faqSection?: FaqSection): string {
120
  const base = `/${locale}/manager/faq`;
121
  if (faqSection) {
122
    return `${base}#${faqSection}`;
123
  }
124
  return base;
125
}
126
127
export function hrJobIndex(locale: string): string {
128
  return `/${locale}/hr/jobs`;
129
}
130
export function hrJobSummary(locale: string, jobId: number): string {
131
  return `/${locale}/hr/jobs/${jobId}`;
132
}
133
export function hrJobReview(locale: string, jobId: number): string {
134
  return `/${locale}/hr/jobs/${jobId}/review`;
135
}
136
export function hrJobPreview(locale: string, jobId: number): string {
137
  return `/${locale}/hr/jobs/${jobId}/preview`;
138
}
139
export function hrScreeningPlan(locale: string, jobId: number): string {
140
  return `/${locale}/hr/jobs/${jobId}/assessment-plan`;
141
}
142
export function hrJobApplications(locale: string, jobId: number): string {
143
  return `/${locale}/hr/jobs/${jobId}/applications`;
144
}
145
export const hrApplicationShow = (
146
  locale: string,
147
  applicationId: number,
148
  jobId: number,
149
): string => applicationShow(locale, "hr", applicationId, jobId);
150
export const hrApplicantShow = (
151
  locale: string,
152
  applicantId: number,
153
  jobId: number,
154
): string => applicantShow(locale, "hr", applicantId, jobId);
155
156
export function accountSettings(locale: string): string {
157
  return `/${locale}/settings`;
158
}
159