Conditions | 12 |
Total Lines | 119 |
Code Lines | 111 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like GamePage.render 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 | import React, { Component } from "react" |
||
42 | |||
43 | render() { |
||
44 | if (this.state.loading === false && this.state.data) { |
||
45 | const { general, substitutes, lineup, events } = this.state.data |
||
46 | const ogImage = { |
||
47 | src: general?.homeClub.logo, |
||
48 | width: 180, |
||
49 | height: 180, |
||
50 | } |
||
51 | |||
52 | console.log(lineup.home) |
||
53 | console.log(lineup.away) |
||
54 | return ( |
||
55 | <Layout> |
||
56 | <SEO |
||
57 | lang="nl-BE" |
||
58 | title={`Matchverslag ${general?.homeClub?.name} - ${general?.awayClub?.name}`} |
||
59 | description={`Matchverslag ${general?.homeClub?.name} - ${general?.awayClub?.name}`} |
||
60 | path={`/game/${general?.id}`} |
||
61 | image={ogImage} |
||
62 | /> |
||
63 | <section className="grid-container site-content"> |
||
64 | {general.date} |
||
65 | <br /> |
||
66 | {general.status} |
||
67 | <br /> |
||
68 | {general.homeClub.name} |
||
69 | <img src={general.homeClub.logo} alt={general.homeClub.name} /> |
||
70 | {general.goalsHomeTeam} - {general.goalsAwayTeam} |
||
71 | {general.awayClub.name} |
||
72 | <img src={general.awayClub.logo} alt={general.awayClub.name} /> |
||
73 | <br /> |
||
74 | {general.competitionType} |
||
75 | <br /> |
||
76 | <strong>Home lineup</strong> |
||
77 | <table> |
||
78 | <tr> |
||
79 | <th>A</th> |
||
80 | <th>Name</th> |
||
81 | <th>Minutes</th> |
||
82 | </tr> |
||
83 | {lineup.home.map((element, i) => ( |
||
84 | <tr key={i}> |
||
85 | <td>A</td> |
||
86 | <td>{element.playerName}</td> |
||
87 | <td>{element.minutesPlayed}</td> |
||
88 | </tr> |
||
89 | ))} |
||
90 | </table> |
||
91 | <strong>Away lineup</strong> |
||
92 | <table> |
||
93 | <tr> |
||
94 | <th>A</th> |
||
95 | <th>Name</th> |
||
96 | <th>Minutes</th> |
||
97 | </tr> |
||
98 | {lineup.away.map((element, i) => ( |
||
99 | <tr key={i}> |
||
100 | <td>A</td> |
||
101 | <td>{element.playerName}</td> |
||
102 | <td>{element.minutesPlayed}</td> |
||
103 | </tr> |
||
104 | ))} |
||
105 | </table> |
||
106 | <strong>Home subs</strong> |
||
107 | <table> |
||
108 | <tr> |
||
109 | <th>A</th> |
||
110 | <th>Name</th> |
||
111 | <th>Minutes</th> |
||
112 | </tr> |
||
113 | {substitutes.home.map((element, i) => ( |
||
114 | <tr key={i}> |
||
115 | <td>A</td> |
||
116 | <td>{element.playerName}</td> |
||
117 | <td>{element.minutesPlayed}</td> |
||
118 | </tr> |
||
119 | ))} |
||
120 | </table> |
||
121 | <strong>Away lineup</strong> |
||
122 | <table> |
||
123 | <tr> |
||
124 | <th>A</th> |
||
125 | <th>Name</th> |
||
126 | <th>Minutes</th> |
||
127 | </tr> |
||
128 | {substitutes.away.map((element, i) => ( |
||
129 | <tr key={i}> |
||
130 | <td>A</td> |
||
131 | <td>{element.playerName}</td> |
||
132 | <td>{element.minutesPlayed}</td> |
||
133 | </tr> |
||
134 | ))} |
||
135 | </table> |
||
136 | <strong>Events</strong> |
||
137 | <table> |
||
138 | <tr> |
||
139 | <th>Event</th> |
||
140 | <th>Name</th> |
||
141 | <th>Minute</th> |
||
142 | </tr> |
||
143 | {events.map((element, i) => ( |
||
144 | <tr key={i}> |
||
145 | <td>{element.action}</td> |
||
146 | <td>{element.playerName}</td> |
||
147 | <td>{element.minute}</td> |
||
148 | </tr> |
||
149 | ))} |
||
150 | </table> |
||
151 | </section> |
||
152 | </Layout> |
||
153 | ) |
||
154 | } else { |
||
155 | return ( |
||
156 | <Layout> |
||
157 | <section className="grid-container site-content"> |
||
158 | Matchverslag inladen... |
||
159 | </section> |
||
160 | </Layout> |
||
161 | ) |
||
179 |