forked from zachisit/oop-cat_creator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classCat.php
296 lines (262 loc) · 8.31 KB
/
classCat.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php
/**
* class Cat
* parent class for Cat
*
*
* @comment From Max:
* All of your pre-function comment blocks should include "@return type" where type is a pipe separated list of return
* types, e.g. getName() should include "@return string|null"
*/
namespace Cat;
class Cat {
//main variables
private $catName;//string
private $catWeight;//number
private $catGender;//male or female
/** @comment Shouldn't these be the value for the current cat, not array? */
private $catColoring;//array of approved colors
private $catCurrentMood;//array of approved moods
private $catHairLength;//array of approved hair lengths
/********************************/
/** @comment bool vars should only be true/false (not 0/1) */
private $catCattitude = 0;//bool
/**
* Cat constructor.
* @param $name
*/
public function __construct($name)
{
//if name of cat passed in, then run the following
/** @comment If you remove the echos, this entire if/else block can be shortened to:
* $this->catName = $name ?? null;
*/
if (isset($name)) {
$this->catName = $name;
/** @comment echoing inside a constructor is bad practice. */
echo "New Cat created, the name of the cat is $this->catName.<br />";
} else {
echo "New Cat created, but does not have a name. Poor little dude. What will you call this new fluffy creature?<br />";
}
}
/**
* Return name of cat
* @param none
*/
public function getName() {
/** consider changing this to:
* return $this->catName ?? ''
* You might do this because you want to be sure that you are always returning a string. If catName was never
* set you might return null.
*/
return $this->catName;
}
/**
* Set weight of cat
* @param $weight
*/
public function setWeight($weight) {
//check input to make sure it is numeric
if ( !is_numeric($weight) ) {
echo "ERROR 34343: Your input is not numeric. Please fix.";
} //check if input is exactly zero
elseif ( $weight == 0 ) {
echo "ERROR 98998: The weight of your cat should be more than zero. Please update.";
} //if input is ok, then set the input to the variable
else {
$this->catWeight = $weight;
}
}
/**
* Return weight of cat
*/
public function getWeight() {
return $this->catWeight;
}
/**
* Set gender of the cat
* @param $gender
*/
public function setGender($gender) {
/** @comment Don't you want to validate $gender? */
$this->catGender = strtolower($gender);
/** @comment, please try to keep all lines <= 120 characters */
//note: it will not be needed to use strtolower in later phases of this application, since when user will fill out the input form to create the cat the gender options will be radio buttons and not text input fields. but good to test and use this phase of the app
}
/**
* Return gender of the cat
*/
public function getGender() {
return $this->catGender;
}
/**
* Set list approved genders
* @comment Consider replacing this method with a private static class variable.
* @return array
*/
public function setAllowedGenders() {
//list approved genders
$approved_gender = array (
'male' => 0,
'female' => 1,
'gender fluid' => 2
);
return $approved_gender;
}
/**
* Check current Gender to return pronoun to be used
* @return null|string
*/
public function returnGenderPronounUsage() {
/** @comment - Your note here is spot on :) */
//note: i guess instead of writing a switch to determine proper pronoun usage, i could change the setAllowedGender $approved_gender array to be 'male' => 'him' - but for now i am happy with this implementation
//var to get the current gender
$existing_pronoun = $this->getGender();
//var to be used in our switch and to be returned
$current_gender = NULL;
switch ($existing_pronoun) {
case 'female':
$current_gender = "her";
return $current_gender;
break;
case 'male':
$current_gender = "him";
return $current_gender;
break;
case 'gender fluid': /** @comment instead of case 'gender fluid':, consider just saying default: */
$current_gender = "it";
return $current_gender;
break;
}
}
/**
* Check if the supplied gender matches approved genders
* @comment Validation methods should generally be private and run inside the setter.
* @return bool
*/
public function checkIsGenderApproved() {
return isset( $this->setAllowedGenders()[$this->catGender] );
}
/**
* Set color of cat
* @param $coloring
*/
public function setColoring($coloring) {
/** @comment You should validate the coloring before setting it */
$this->catColoring = $coloring;
}
/**
* Set list of allowed cat colorings
*/
public function setAllowedColorings() {
//list of approved cat colors
//related to hex colors
$allowed_colorings = array (
'black' => '#000000',
'gray' => '#808080',
'brown' => '#A5682A',
'calico' => '#D5B185',
'white' => '#FFFFFF'
);
return $allowed_colorings;
}
/**
* Return color of cat
* @comment consider adding a parameter to this function, something like:
* getColoring($context = 'name')
* Then accept name or color_code as the context and you can do getColoring('color_code') to return the hex code
* By default you'd still return the name
*/
public function getColoring() {
return $this->catColoring;
}
/**
* Check if the supplied color matches the approved cat colors
* @comment Same comment as on line 152
* @return bool
*/
public function checkIsColorApproved() {
return isset( $this->setAllowedColorings()[$this->catColoring] );
}
/**
* Set the mood of the cat
* @param $mood
*/
public function setMood($mood) {
$this->catCurrentMood = $mood;
}
/**
* Set list of approved moods
* @return array
*/
public function setApprovedMood() {
//list of approved moods
$approved_moods = array(
'grumpy' => '0',
'sleepy' => '1',
'rowdy' => '2',
'thirsty' => '3',
'hungry' => '4'
);
return $approved_moods;
}
/**
* Return current mood of cat
* @return mixed
*/
public function getMood() {
return $this->catCurrentMood;
}
/**
* Check if supplied mood matches approved mood list
* @return bool
*/
public function checkIsMoodApproved() {
return isset( $this->setApprovedMood()[$this->catCurrentMood] );
}
/**
* Set length of hair for cat
* @param $hairlength
* @return mixed
*/
public function setHairLength($hairlength) {
/** @comment this will always return true, was that intentional? */
return $this->catHairLength = $hairlength;
}
/**
* Check if supplied hair length is approved
* @return array
*/
public function checkIsHairLengthApproved() {
$approved_hairlength = array (
'short',
'long',
'hairless'
);
return $approved_hairlength;
}
/**
* Return hair length
* @return mixed
*/
public function getHairLength() {
return $this->catHairLength;
}
/**
* Set if cat has catitude or not
* @param $catitude
* @return mixed
* @reference http://pink73.tripod.com/cats/catitude2.jpg
* @comment Same comment as on line 252
*/
public function setHasCatitude($catitude) {
return $this->catCattitude = $catitude;
}
/**
* Return if cat has catitude
* @return int
*/
public function getCatitudeStatus() {
return $this->catCattitude;
}
}