Conditions | 13 |
Total Lines | 114 |
Code Lines | 98 |
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" |
||
60 | |||
61 | render() { |
||
62 | if (this.matchId === null) { |
||
63 | return ( |
||
64 | <Layout> |
||
65 | <section className="grid-container site-content"> |
||
66 | Geen match beschikbaar... |
||
67 | </section> |
||
68 | </Layout> |
||
69 | ) |
||
70 | } |
||
71 | |||
72 | moment.locale("nl-be") |
||
73 | |||
74 | if (this.state.loading === false && this.state.data) { |
||
75 | const { |
||
76 | general = {}, |
||
77 | substitutes = {}, |
||
78 | lineup = {}, |
||
79 | events = [], |
||
80 | } = this.state.data |
||
81 | const homeTeamId = general.homeClub.id |
||
82 | const ogImage = { |
||
83 | src: general?.homeClub.logo, |
||
84 | width: 180, |
||
85 | height: 180, |
||
86 | } |
||
87 | |||
88 | const { home: homeLineup = [], away: awayLineup = [] } = lineup || {} |
||
89 | const { home: homeSubs = [], away: awaySubs = [] } = substitutes || {} |
||
90 | |||
91 | const matchTime = moment(general.date) |
||
92 | |||
93 | return ( |
||
94 | <Layout> |
||
95 | <SEO |
||
96 | lang="nl-BE" |
||
97 | title={`Matchverslag ${general?.homeClub?.name} - ${general?.awayClub?.name}`} |
||
98 | description={`Matchverslag ${general?.homeClub?.name} - ${general?.awayClub?.name}`} |
||
99 | path={`/game/${general?.id}`} |
||
100 | image={ogImage} |
||
101 | /> |
||
102 | |||
103 | <section className="grid-container game-stats"> |
||
104 | <div className="grid-x grid-margin-x"> |
||
105 | <div className={"cell large-12 center game__details"}> |
||
106 | <div className="game__teams"> |
||
107 | <div className={"game__teams-inner"}> |
||
108 | <LazyLoad debounce={false}> |
||
109 | <img |
||
110 | src={general.homeClub.logo} |
||
111 | alt={general.homeClub.name} |
||
112 | title={general.homeClub.name} |
||
113 | /> |
||
114 | </LazyLoad> |
||
115 | </div> |
||
116 | {this.renderScore( |
||
117 | general.goalsHomeTeam, |
||
118 | general.goalsAwayTeam |
||
119 | )} |
||
120 | <div className={"game__teams-inner"}> |
||
121 | <LazyLoad debounce={false}> |
||
122 | <img |
||
123 | src={general.awayClub.logo} |
||
124 | alt={general.awayClub.name} |
||
125 | title={general.awayClub.name} |
||
126 | /> |
||
127 | </LazyLoad> |
||
128 | </div> |
||
129 | </div> |
||
130 | <h1>{`${general.homeClub.name} - ${general.awayClub.name}`}</h1> |
||
131 | <h4>{general.competitionType}</h4> |
||
132 | <time dateTime={matchTime.format("YYYY-MM-DD - H:mm")}> |
||
133 | {matchTime.format("dddd DD MMMM YYYY - H:mm")} |
||
134 | </time> |
||
135 | <br /> |
||
136 | {general.status !== 0 && mapPsdStatus(general.status)} |
||
137 | <br /> |
||
138 | </div> |
||
139 | |||
140 | {(homeLineup.length !== 0 || awayLineup.length !== 0) && ( |
||
141 | <div |
||
142 | className={ |
||
143 | "lineup__wrapper grid-x grid-margin-x cell large-12" |
||
144 | } |
||
145 | > |
||
146 | <div className={"cell large-6 lineup__wrapper--home"}> |
||
147 | <h3>{general.homeClub.name}</h3> |
||
148 | {homeLineup && this.renderLineup(homeLineup, homeSubs)} |
||
149 | </div> |
||
150 | <div className={"cell large-6 lineup__wrapper--away"}> |
||
151 | <h3>{general.awayClub.name}</h3> |
||
152 | {awayLineup && this.renderLineup(awayLineup, awaySubs)} |
||
153 | </div> |
||
154 | </div> |
||
155 | )} |
||
156 | |||
157 | {events.length !== 0 && ( |
||
158 | <div className={"cell large-12 event__wrapper"}> |
||
159 | <h3>Gebeurtenissen</h3> |
||
160 | {events && this.renderEvents(events, homeTeamId)} |
||
161 | </div> |
||
162 | )} |
||
163 | </div> |
||
164 | </section> |
||
165 | </Layout> |
||
166 | ) |
||
167 | } else { |
||
168 | return ( |
||
169 | <Layout> |
||
170 | <section className="grid-container site-content"> |
||
171 | Matchverslag inladen... |
||
172 | </section> |
||
173 | </Layout> |
||
174 | ) |
||
394 |