-
Notifications
You must be signed in to change notification settings - Fork 47
/
getting-started.txt
136 lines (120 loc) · 3.03 KB
/
getting-started.txt
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
<?php
/**
* Please fix the items marked with "@TODO" in this class
*
* Follow the https://www.php-fig.org/psr/psr-2/ coding style guide.
*
* One exception to PSR-2: opening braces MUST always be on the same line
* for classes, methods, functions, and control structures
*/
class Singleton {
// @TODO Implement Singleton functionality
/**
* Display user name
*
* @param string $name User-provided name
*/
public function userEcho($name) {
// @TODO Validate & sanitize $name
echo "The value of 'name' is '{$name}'";
}
/**
* Query by user name
*
* @param string $name User-provided name
*/
public function userQuery($name) {
// @TODO Validate & sanitize $name
mysql_query("SELECT * FROM `test` WHERE `name` = '{$name}' LIMIT 1");
}
/**
* Output the contents of a file
*
* @param string $path User-provided file path
*/
public function userFile($path) {
// @TODO Validate & sanitize $path
readfile($path);
}
/**
* Nested conditions
*/
public function nestedConditions() {
// @TODO Untangle nested conditions
if ($conditionA) {
if ($conditionB) {
if ($conditionC) {
echo 'ABC';
} else {
echo '^C';
}
} else {
echo '^B';
}
} else {
echo '^A';
}
}
/**
* Return statements
*
* @return boolean
*/
public function returnStatements() {
// @TODO Fix
if ($conditionA) {
echo 'A';
return true;
} else {
return false;
}
}
/**
* Null coalescing
*/
public function nullCoalescing() {
// @TODO Simplify
if (isset($_GET['name'])) {
$name = $_GET['name'];
} elseif (isset($_POST['name'])) {
$name = $_POST['name'];
} else {
$name = 'nobody';
}
return $name;
}
/**
* Method chaining
*/
public function methodChained() {
// @TODO Implement method chaining
}
/**
* Immutables are hard to find
*/
public function checkValue($value) {
$result = null;
// @TODO Make all the immutable values (int, string) in this class
// easily replaceable
switch ($value) {
case 'stringA':
$result = 1;
break;
case 'stringB':
$result = 2;
break;
}
return $result;
}
/**
* Check a string is a 24 hour time
*
* @example "00:00:00", "23:59:59", "20:15"
* @return boolean
*/
public function regexTest($time24Hour) {
// @TODO Implement RegEx and return type; validate & sanitize input
return preg_match('%%', $time24Hour);
}
}
/*EOF*/