Completed
Push — feature/code-analysis ( 5e4834...031f83 )
by Jonathan
04:10
created
src/Webtrees/Functions/Functions.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @param string $text Text to display
40 40
 	 */
41
-	static public function promptAlert($text){
41
+	static public function promptAlert($text) {
42 42
 		echo '<script>';
43
-		echo 'alert("',fw\Filter::escapeHtml($text),'")';
43
+		echo 'alert("', fw\Filter::escapeHtml($text), '")';
44 44
 		echo '</script>';
45 45
 	}
46 46
 	
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 * @return float Result of the safe division
54 54
 	 */
55 55
 	public static function safeDivision($num, $denom, $default = 0) {
56
-		if($denom && $denom!=0){
56
+		if ($denom && $denom != 0) {
57 57
 			return $num / $denom;
58 58
 		}
59 59
 		return $default;
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 * @param float $default Default value if denominator null or 0
68 68
 	 * @return float Percentage
69 69
 	 */
70
-	public static function getPercentage($num, $denom, $default = 0){
70
+	public static function getPercentage($num, $denom, $default = 0) {
71 71
 		return 100 * self::safeDivision($num, $denom, $default);
72 72
 	}
73 73
 	
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @param int $target	The final max width/height
79 79
 	 * @return array array of ($width, $height). One of them must be $target
80 80
 	 */
81
-	static public function getResizedImageSize($file, $target=25){
82
-		list($width, $height, , ) = getimagesize($file);
81
+	static public function getResizedImageSize($file, $target = 25) {
82
+		list($width, $height,,) = getimagesize($file);
83 83
 		$max = max($width, $height);
84 84
 		$rapp = $target / $max;
85 85
 		$width = intval($rapp * $width);
@@ -109,21 +109,21 @@  discard block
 block discarded – undo
109 109
 	 * @param int $length Length of the token, default to 32
110 110
 	 * @return string Random token
111 111
 	 */
112
-	public static function generateRandomToken($length=32) {
112
+	public static function generateRandomToken($length = 32) {
113 113
 		$chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
114 114
 		$len_chars = count($chars);
115 115
 		$token = '';
116 116
 		
117 117
 		for ($i = 0; $i < $length; $i++)
118
-			$token .= $chars[ mt_rand(0, $len_chars - 1) ];
118
+			$token .= $chars[mt_rand(0, $len_chars - 1)];
119 119
 		
120 120
 		# Number of 32 char chunks
121
-		$chunks = ceil( strlen($token) / 32 );
121
+		$chunks = ceil(strlen($token) / 32);
122 122
 		$md5token = '';
123 123
 		
124 124
 		# Run each chunk through md5
125
-		for ( $i=1; $i<=$chunks; $i++ )
126
-			$md5token .= md5( substr($token, $i * 32 - 32, 32) );
125
+		for ($i = 1; $i <= $chunks; $i++)
126
+			$md5token .= md5(substr($token, $i * 32 - 32, 32));
127 127
 		
128 128
 			# Trim the token
129 129
 		return substr($md5token, 0, $length);		
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
 	 * @param string $data Text to encrypt
137 137
 	 * @return string Encrypted and encoded text
138 138
 	 */
139
-	public static function encryptToSafeBase64($data){
139
+	public static function encryptToSafeBase64($data) {
140 140
 		$key = 'STANDARDKEYIFNOSERVER';
141
-		if($_SERVER['SERVER_NAME'] && $_SERVER['SERVER_SOFTWARE'])
141
+		if ($_SERVER['SERVER_NAME'] && $_SERVER['SERVER_SOFTWARE'])
142 142
 			$key = md5($_SERVER['SERVER_NAME'].$_SERVER['SERVER_SOFTWARE']);
143 143
 		$iv = mcrypt_create_iv(self::ENCRYPTION_IV_SIZE, MCRYPT_RAND);
144
-		$id = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC,$iv);
144
+		$id = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);
145 145
 		$encrypted = base64_encode($iv.$id);
146 146
 		// +, / and = are not URL-compatible
147 147
 		$encrypted = str_replace('+', '-', $encrypted);
@@ -156,22 +156,22 @@  discard block
 block discarded – undo
156 156
 	 * @param string $encrypted Text to decrypt
157 157
 	 * @return string Decrypted text
158 158
 	 */
159
-	public static function decryptFromSafeBase64($encrypted){
159
+	public static function decryptFromSafeBase64($encrypted) {
160 160
 		$key = 'STANDARDKEYIFNOSERVER';
161
-		if($_SERVER['SERVER_NAME'] && $_SERVER['SERVER_SOFTWARE'])
161
+		if ($_SERVER['SERVER_NAME'] && $_SERVER['SERVER_SOFTWARE'])
162 162
 			$key = md5($_SERVER['SERVER_NAME'].$_SERVER['SERVER_SOFTWARE']);
163 163
 		$encrypted = str_replace('-', '+', $encrypted);
164 164
 		$encrypted = str_replace('_', '/', $encrypted);
165 165
 		$encrypted = str_replace('*', '=', $encrypted);
166 166
 		$encrypted = base64_decode($encrypted);
167
-		if(!$encrypted)
167
+		if (!$encrypted)
168 168
 			throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.');
169
-		if(strlen($encrypted) < self::ENCRYPTION_IV_SIZE) 
169
+		if (strlen($encrypted) < self::ENCRYPTION_IV_SIZE) 
170 170
 			throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.');
171 171
 		$iv_dec = substr($encrypted, 0, self::ENCRYPTION_IV_SIZE);
172 172
 		$encrypted = substr($encrypted, self::ENCRYPTION_IV_SIZE);
173 173
 		$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encrypted, MCRYPT_MODE_CBC, $iv_dec);
174
-		return  preg_replace('~(?:\\000+)$~','',$decrypted);
174
+		return  preg_replace('~(?:\\000+)$~', '', $decrypted);
175 175
 	}
176 176
 	
177 177
 	/**
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 	 * @param string $string Filesystem encoded string to encode
181 181
 	 * @return string UTF-8 encoded string
182 182
 	 */
183
-	public static function encodeFileSystemToUtf8($string){
183
+	public static function encodeFileSystemToUtf8($string) {
184 184
 		if (strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') {
185
-		    return iconv('cp1252', 'utf-8//IGNORE',$string);
185
+		    return iconv('cp1252', 'utf-8//IGNORE', $string);
186 186
 		}
187 187
 		return $string;
188 188
 	}
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
 	 * @param string $string UTF-8 encoded string to encode
194 194
 	 * @return string Filesystem encoded string
195 195
 	 */
196
-	public static function encodeUtf8ToFileSystem($string){
196
+	public static function encodeUtf8ToFileSystem($string) {
197 197
 		if (preg_match('//u', $string) && strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') {
198
-			return iconv('utf-8', 'cp1252//IGNORE' ,  $string);
198
+			return iconv('utf-8', 'cp1252//IGNORE', $string);
199 199
 		}
200 200
 		return $string;
201 201
 	}
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 * @return boolean True if path valid
209 209
 	 */
210 210
 	public static function isValidPath($filename, $acceptfolder = FALSE) {		
211
-		if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true;
211
+		if (strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true;
212 212
 		return false;
213 213
 	}
214 214
 	
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	 * @return array Array of month short names
221 221
 	 */
222 222
 	public static function getCalendarShortMonths($calendarId = 0) {
223
-		if(!isset(self::$calendarShortMonths[$calendarId])) {
223
+		if (!isset(self::$calendarShortMonths[$calendarId])) {
224 224
 			$calendar_info = cal_info($calendarId);
225 225
 			self::$calendarShortMonths[$calendarId] = $calendar_info['abbrevmonths'];
226 226
 		}		
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
 	 * @param int $sosa Sosa number
234 234
 	 * @return number
235 235
 	 */
236
-	public static function getGeneration($sosa){
237
-		return(int)log($sosa, 2)+1;
236
+	public static function getGeneration($sosa) {
237
+		return(int)log($sosa, 2) + 1;
238 238
 	}
239 239
 	
240 240
 	
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Tasks/HealthCheckEmailTask.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\AbstractTask::getDefaultFrequency()
43 43
 	 */
44 44
     public function getDefaultFrequency() {
45
-		return 10080;  // = 1 week = 7 * 24 * 60 min
45
+		return 10080; // = 1 week = 7 * 24 * 60 min
46 46
 	}
47 47
     
48 48
 	/**
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 		
56 56
 		// Get the number of days to take into account, either last 7 days or since last check
57 57
 		$interval_sincelast = 0;
58
-		if($this->last_updated){
58
+		if ($this->last_updated) {
59 59
 			$tmpInt = $this->last_updated->diff(new \DateTime('now'), true);
60
-			$interval_sincelast = ( $tmpInt->days * 24  + $tmpInt->h ) * 60 + $tmpInt->i;
60
+			$interval_sincelast = ($tmpInt->days * 24 + $tmpInt->h) * 60 + $tmpInt->i;
61 61
 		}
62 62
 		
63 63
 		$interval = max($this->frequency, $interval_sincelast);
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
         // Check for updates
67 67
         $latest_version_txt = Functions::fetchLatestVersion();
68 68
         if (preg_match('/^[0-9.]+\|[0-9.]+\|/', $latest_version_txt)) {
69
-        	list($latest_version, , $download_url) = explode('|', $latest_version_txt);
69
+        	list($latest_version,, $download_url) = explode('|', $latest_version_txt);
70 70
         } else {
71 71
         	// Cannot determine the latest version
72
-        	list($latest_version, , $download_url) = explode('|', '||');
72
+        	list($latest_version,, $download_url) = explode('|', '||');
73 73
         }
74 74
 		
75 75
 		// Users statistics
76 76
 		$warnusers = 0;
77 77
 		$nverusers = 0;
78 78
 		$applusers = 0;
79
-		foreach(User::all() as $user) {
79
+		foreach (User::all() as $user) {
80 80
 			if (((date("U") - (int)$user->getPreference('reg_timestamp')) > 604800) && !$user->getPreference('verified')) {
81 81
 				$warnusers++;
82 82
 			}
@@ -90,20 +90,20 @@  discard block
 block discarded – undo
90 90
 		
91 91
 		// Tree specifics checks
92 92
 		$one_tree_done = false;
93
-		foreach(Tree::getAll() as $tree){
93
+		foreach (Tree::getAll() as $tree) {
94 94
 			$isTreeEnabled = $tree->getPreference('MAJ_AT_'.$this->getName().'_ENABLED');
95
-			if((is_null($isTreeEnabled) || $isTreeEnabled) && $webmaster = User::find($tree->getPreference('WEBMASTER_USER_ID'))){
95
+			if ((is_null($isTreeEnabled) || $isTreeEnabled) && $webmaster = User::find($tree->getPreference('WEBMASTER_USER_ID'))) {
96 96
 				I18N::init($webmaster->getPreference('language'));
97 97
 				
98 98
 				$subject = I18N::translate('Health Check Report').' - '.I18N::translate('Tree %s', $tree->getTitle());
99 99
 				$message = 
100
-					I18N::translate('Health Check Report for the last %d days', $nbdays). Mail::EOL. Mail::EOL.
100
+					I18N::translate('Health Check Report for the last %d days', $nbdays).Mail::EOL.Mail::EOL.
101 101
 					I18N::translate('Tree %s', $tree->getTitle()).Mail::EOL.
102 102
 					'=========================================='.Mail::EOL.Mail::EOL;
103 103
 				
104 104
 				// News
105 105
 				$message_version = '';
106
-				if($latest_version && version_compare(WT_VERSION, $latest_version)<0){
106
+				if ($latest_version && version_compare(WT_VERSION, $latest_version) < 0) {
107 107
 					$message_version = I18N::translate('News').Mail::EOL.
108 108
 							'-------------'.Mail::EOL.
109 109
 							I18N::translate('A new version of *webtrees* is available: %s. Upgrade as soon as possible.', $latest_version).Mail::EOL.
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 						I18N::translate('Not verified by the user')."\t\t".$applusers.Mail::EOL.
120 120
 						I18N::translate('Not approved by an administrator')."\t".$nverusers.Mail::EOL.
121 121
 						Mail::EOL;
122
-				$message  .= $message_users;
122
+				$message .= $message_users;
123 123
 								
124 124
 				// Statistics tree:				
125 125
 				$stats = new Stats($tree);
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 							' AND log_time >= DATE_ADD( NOW(), INTERVAL - :nb_days DAY)'.
160 160
 							' GROUP BY log_message, gedcom_id'.
161 161
 							' ORDER BY lastoccurred DESC';
162
-				$errors=Database::prepare($sql)->execute(array(
162
+				$errors = Database::prepare($sql)->execute(array(
163 163
 					'log_type' => Log::TYPE_ERROR, 
164 164
 					'gedcom_id' => $tree->getTreeId(), 
165 165
 					'nb_days' => $nbdays
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 					$tmp_message .= str_replace("\n", "\n\t\t\t\t\t\t", $error->log_message).Mail::EOL;
176 176
 					$nb_errors += $error->nblogs;
177 177
 				}
178
-				if($nb_errors > 0){
178
+				if ($nb_errors > 0) {
179 179
 					$message .= I18N::translate('Errors [%d]', $nb_errors).Mail::EOL.
180 180
 						'-------------'.Mail::EOL.
181 181
 						WT_BASE_URL.'admin_site_logs.php'.Mail::EOL.
@@ -186,12 +186,12 @@  discard block
 block discarded – undo
186 186
 						str_repeat('-', $nb_char_count_title)."\t".str_repeat('-', $nb_char_type)."\t".str_repeat('-', 20)."\t".str_repeat('-', strlen(I18N::translate('Error'))).Mail::EOL.
187 187
 						$tmp_message.Mail::EOL;
188 188
 				}
189
-				else{
189
+				else {
190 190
 					$message .= I18N::translate('No errors', $nb_errors).Mail::EOL.Mail::EOL;
191 191
 				}
192 192
 				
193 193
 				$tmpres = true;
194
-				if($webmaster->getPreference('contactmethod') !== 'messaging' 
194
+				if ($webmaster->getPreference('contactmethod') !== 'messaging' 
195 195
 						&& $webmaster->getPreference('contactmethod') !== 'none') {
196 196
 					$tmpres = Mail::systemMessage($tree, $webmaster, $subject, $message);
197 197
 				}		
@@ -213,24 +213,24 @@  discard block
 block discarded – undo
213 213
 		$html = '
214 214
 			<div class="form-group">
215 215
     			<label class="control-label col-sm-3"> '.
216
-    				I18N::translate('Enable healthcheck emails for') .
216
+    				I18N::translate('Enable healthcheck emails for').
217 217
     			'</label>
218 218
     			<div class="col-sm-9">';
219 219
 
220
-		foreach(Tree::getAll() as $tree){
221
-			if(Auth::isManager($tree)){	
220
+		foreach (Tree::getAll() as $tree) {
221
+			if (Auth::isManager($tree)) {	
222 222
 			    $html .= '<div class="form-group row">
223 223
 			        <span class="col-sm-3 control-label">' .
224
-			             $tree->getTitle() .
224
+			             $tree->getTitle().
225 225
 					'</span>
226 226
 					 <div class="col-sm-2">';
227
-				$html .= FunctionsEdit::editFieldYesNo('HEALTHCHECK_ENABLED_' . $tree->getTreeId(), $tree->getPreference('MAJ_AT_'.$this->getName().'_ENABLED', 1), 'class="radio-inline"');
227
+				$html .= FunctionsEdit::editFieldYesNo('HEALTHCHECK_ENABLED_'.$tree->getTreeId(), $tree->getPreference('MAJ_AT_'.$this->getName().'_ENABLED', 1), 'class="radio-inline"');
228 228
 				$html .= '</div></div>';
229 229
 			}
230 230
 		}
231 231
 		
232 232
 		$html .= '	<p class="small text-muted">'.
233
-    					I18N::translate('Enable the health check emails for each of the selected trees.') .
233
+    					I18N::translate('Enable the health check emails for each of the selected trees.').
234 234
     				'</p>
235 235
     			</div>
236 236
     		</div>';
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
 	 */
245 245
 	public function saveConfig() {
246 246
 		try {
247
-			foreach(Tree::getAll() as $tree){		
248
-				if(Auth::isManager($tree)){
249
-					$tree_enabled = Filter::postInteger('HEALTHCHECK_ENABLED_' . $tree->getTreeId(), 0, 1);
247
+			foreach (Tree::getAll() as $tree) {		
248
+				if (Auth::isManager($tree)) {
249
+					$tree_enabled = Filter::postInteger('HEALTHCHECK_ENABLED_'.$tree->getTreeId(), 0, 1);
250 250
 					$tree->setPreference('MAJ_AT_'.$this->getName().'_ENABLED', $tree_enabled);
251 251
 				}
252 252
 			}
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Schema/Migration0.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@
 block discarded – undo
28 28
 		    ' majat_name 		    VARCHAR(32)                      NOT NULL,'.
29 29
 		    ' majat_status          ENUM(\'enabled\',\'disabled\') 	 NOT NULL DEFAULT \'disabled\','.
30 30
 		    ' majat_last_run 		DATETIME 					     NOT NULL DEFAULT \'2000-01-01 00:00:00\','.
31
-		    ' majat_last_result 	TINYINT(1)					     NOT NULL DEFAULT 1,'.		// 0 means error, 1 is success
32
-		    ' majat_frequency		INTEGER						     NOT NULL DEFAULT 10080,'.	// In min, Default every week
31
+		    ' majat_last_result 	TINYINT(1)					     NOT NULL DEFAULT 1,'.// 0 means error, 1 is success
32
+		    ' majat_frequency		INTEGER						     NOT NULL DEFAULT 10080,'.// In min, Default every week
33 33
 		    ' majat_nb_occur	 	SMALLINT					     NOT NULL DEFAULT 0,'.
34 34
 		    ' majat_running 		TINYINT(1)					     NOT NULL DEFAULT 0,'.
35 35
 		    ' PRIMARY KEY (majat_name)'.
Please login to merge, or discard this patch.