Wave of code cleanup / formatting

* Some code cleanup

* More code cleanup / formatting

Now I'm gonna go to bed

* Fix typo

This is why we have tests

* Cleanup literal booleans

* Some more general code cleanup

* Github's GUI for merge conflicts is not very clear..

* Update PDF_ImageAlpha.php

* Revert potentially behavior changing changes that aren't tested
This commit is contained in:
Benjamin Aerni authored and GitHub committed 2021-08-25 10:35:00 -07:00
1 parent 515fe56ad3
commit 91f914ab2c
17 files changed
+129 -80

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@ echo sprintf("Connecting to database %s@%s/%s", $user, $host, $dbname) . PHP_EOL
$iter = 30;
$connected = false;
while ($connected == false && $iter > 0) {
while (!$connected && $iter > 0) {
try {
$dbh = new PDO($type . ':host=' . $host, $user, $password, array(
+6 -2
View File
@@ -79,7 +79,9 @@ final class Api_Handler implements InjectionAwareInterface
if($this->_acl_exception) {
throw new \Box_Exception('You do not have access to :mod module', array(':mod'=>$mod), 725);
} else {
if(BB_DEBUG) error_log('You do not have access to '.$mod. ' module');
if(BB_DEBUG) {
error_log('You do not have access to '.$mod. ' module');
}
return null;
}
}
@@ -110,7 +112,9 @@ final class Api_Handler implements InjectionAwareInterface
}
}
$res = $api->{$method_name}($arguments);
if($this->_enable_cache) $this->_cache[$cache_key] = $res;
if($this->_enable_cache){
$this->_cache[$cache_key] = $res;
}
return $res;
}
}
+3 -1
View File
@@ -55,7 +55,9 @@ class Box_AppClient extends Box_App
try {
return $this->render($tpl, array('post'=>$_POST), $ext);
} catch(Exception $e) {
if(BB_DEBUG) error_log($e);
if(BB_DEBUG){
error_log($e);
}
}
// throw new \Box_Exception('Page :url not found', array(':url'=>$page), 404);
$e = new \Box_Exception('Page :url not found', array(':url'=>$this->url), 404);
+2 -1
View File
@@ -74,8 +74,9 @@ class Box_Curl {
public function useAuth($use) {
$this->authentication = 0;
if ($use == true)
if ($use){
$this->authentication = 1;
}
}
public function setName($name) {
+12 -4
View File
@@ -38,7 +38,9 @@ class Box_Database implements InjectionAwareInterface
{
$type = $this->_getTypeFromModelName($modelName);
$bean = $this->orm->dispense($type);
if($type == $modelName) return $bean;
if($type == $modelName){
return $bean;
}
return $bean->box();
}
@@ -76,7 +78,9 @@ class Box_Database implements InjectionAwareInterface
{
$type = $this->_getTypeFromModelName($modelName);
$bean = $this->orm->findOne($type, $sql, $values);
if($type == $modelName) return $bean;
if($type == $modelName) {
return $bean;
}
if($bean && $bean->id) {
return $bean->box();
}
@@ -87,7 +91,9 @@ class Box_Database implements InjectionAwareInterface
{
$type = $this->_getTypeFromModelName($modelName);
$beans = $this->orm->find($type, $sql, $values);
if($type == $modelName) return $beans;
if($type == $modelName){
return $beans;
}
foreach ($beans as &$bean) {
$bean = $bean->box();
}
@@ -110,7 +116,9 @@ class Box_Database implements InjectionAwareInterface
$type = $this->_getTypeFromModelName($modelName);
$bean = $this->orm->load($type, $id);
if ($type == $modelName) return $bean;
if ($type == $modelName){
return $bean;
}
if ($bean && $bean->id) {
return $bean->box();
}
+79 -44
View File
@@ -35,41 +35,48 @@ class Box_Ftp
}
// Set defaults:
if ( empty($opt['port']) )
if ( empty($opt['port']) ) {
$this->options['port'] = 21;
else
} else {
$this->options['port'] = $opt['port'];
}
if ( empty($opt['hostname']) )
if ( empty($opt['hostname']) ) {
throw new \Box_Exception('FTP hostname is required');
else
} else {
$this->options['hostname'] = $opt['hostname'];
}
if ( isset($opt['root']) && ! empty($opt['root']) )
if ( isset($opt['root']) && ! empty($opt['root']) ) {
$this->bb_root = $opt['root'];
}
// Check if the options provided are OK.
if ( empty($opt['username']) )
if ( empty($opt['username']) ) {
throw new \Box_Exception('FTP username is required');
else
} else {
$this->options['username'] = $opt['username'];
}
if ( empty($opt['password']) )
if ( empty($opt['password']) ) {
throw new \Box_Exception('FTP password is required');
else
} else {
$this->options['password'] = $opt['password'];
}
$this->options['ssl'] = false;
if ( isset($opt['connection_type']) && 'ftps' == $opt['connection_type'] )
if ( isset($opt['connection_type']) && 'ftps' == $opt['connection_type'] ) {
$this->options['ssl'] = true;
}
}
public function connect()
{
if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') )
if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') ) {
$this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], $this->timeout);
else
} else {
$this->link = @ftp_connect($this->options['hostname'], $this->options['port'], $this->timeout);
}
if ( ! $this->link ) {
throw new \Box_Exception('Failed to connect to FTP Server :host : :port',array(':host'=>$this->options['hostname'], ':port'=>$this->options['port']));
@@ -97,21 +104,25 @@ class Box_Ftp
public function get_contents($file, $type = '', $resumepos = 0 )
{
if( empty($type) )
if( empty($type) ) {
$type = FTP_BINARY;
}
$temp = tmpfile();
if ( ! $temp )
if ( ! $temp ) {
return false;
}
if( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )
if( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) ) {
return false;
}
fseek($temp, 0); //Skip back to the start of the file being written to
$contents = '';
while ( ! feof($temp) )
while ( ! feof($temp) ) {
$contents .= fread($temp, 8192);
}
fclose($temp);
return $contents;
@@ -127,12 +138,14 @@ class Box_Ftp
*/
public function put_contents($file, $contents, $type = '' )
{
if( empty($type) )
if( empty($type) ) {
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
}
$temp = tmpfile();
if ( ! $temp )
if ( ! $temp ) {
return false;
}
fwrite($temp, $contents);
fseek($temp, 0); //Skip back to the start of the file being written to
@@ -198,15 +211,19 @@ class Box_Ftp
public function chmod($file, $mode = false, $recursive = false)
{
if( ! $mode )
if( ! $mode ) {
$mode = $this->permission;
if( ! $mode )
return false;
if ( ! $this->exists($file) && ! $this->is_dir($file) )
}
if ( ! $this->exists($file) && ! $this->is_dir($file) ) {
return false;
}
if ( ! $recursive || ! $this->is_dir($file) ) {
if ( ! function_exists('ftp_chmod') )
if ( ! function_exists('ftp_chmod') ) {
return @ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file));
}
return @ftp_chmod($this->link, $mode, $file);
}
//Is a directory, and we want recursive
@@ -254,8 +271,9 @@ class Box_Ftp
*/
public function copyDir($source, $destination, $overwrite = false )
{
if( ! $overwrite && !$this->is_dir($destination) )
if( ! $overwrite && !$this->is_dir($destination) ) {
return false;
}
if( $overwrite && !$this->is_dir($destination) ) {
if(!$this->mkdir($destination)) {
@@ -270,7 +288,9 @@ class Box_Ftp
$res = false;
$this->chdir($source);
$dir_contents = $this->dirlist($source, false, true);
if (empty($dir_contents)) { return true; }
if (empty($dir_contents)) {
return true;
}
foreach($dir_contents as $name=>$params) {
if ($params['isdir']) {
@@ -289,11 +309,13 @@ class Box_Ftp
*/
public function copy($source, $destination, $overwrite = false )
{
if( ! $overwrite && $this->exists($destination) )
if( ! $overwrite && $this->exists($destination) ) {
return false;
}
$content = $this->get_contents($source);
if( false === $content)
if( false === $content) {
return false;
}
return $this->put_contents($destination, $content);
}
@@ -304,17 +326,22 @@ class Box_Ftp
public function delete($file, $recursive = false )
{
if ( empty($file) )
if ( empty($file) ) {
return false;
if ( $this->is_file($file) )
}
if ( $this->is_file($file) ) {
return @ftp_delete($this->link, $file);
if ( !$recursive )
}
if ( !$recursive ) {
return @ftp_rmdir($this->link, $file);
}
$filelist = $this->dirlist( $this->trailingslashit($file) );
if ( !empty($filelist) )
foreach ( $filelist as $delete_file )
if ( !empty($filelist) ) {
foreach ( $filelist as $delete_file ) {
$this->delete( $this->trailingslashit($file) . $delete_file['name'], $recursive);
}
}
return @ftp_rmdir($this->link, $file);
}
@@ -376,14 +403,18 @@ class Box_Ftp
*/
public function mkdir($path, $chmod = false, $chown = false, $chgrp = false)
{
if( !ftp_mkdir($this->link, $path) )
if( !ftp_mkdir($this->link, $path) ) {
return false;
if( $chmod )
}
if( $chmod ) {
$this->chmod($path, $chmod);
if( $chown )
}
if( $chown ) {
$this->chown($path, $chown);
if( $chgrp )
}
if( $chgrp ) {
$this->chgrp($path, $chgrp);
}
return true;
}
@@ -397,8 +428,9 @@ class Box_Ftp
static $is_windows;
$b = array();
if ( is_null($is_windows) )
if ( is_null($is_windows) ) {
$is_windows = strpos( strtolower(ftp_systype($this->link)), 'win') !== false;
}
if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line, $lucifer)) {
if ($lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
@@ -470,25 +502,29 @@ class Box_Ftp
$list = ftp_rawlist($this->link, '-a ' . $path, false);
if ( $list === false )
if ( $list === false ) {
return false;
}
$dirlist = array();
foreach ( $list as $k => $v ) {
$entry = $this->parselisting($v);
if ( empty($entry) )
if ( empty($entry) ) {
continue;
if ( '.' == $entry["name"] || '..' == $entry["name"] )
}
if ( '.' == $entry["name"] || '..' == $entry["name"] ) {
continue;
}
$dirlist[ $entry['name'] ] = $entry;
}
if ( ! $dirlist )
if ( ! $dirlist ) {
return false;
if ( empty($dirlist) )
}
if ( empty($dirlist) ) {
return array();
}
$ret = array();
foreach ( $dirlist as $struc ) {
@@ -519,8 +555,7 @@ class Box_Ftp
*/
public function dirContents()
{
$contents = ftp_nlist($this->link, ".");
return $contents;
return ftp_nlist($this->link, ".");
}
protected function trailingslashit($string)
+3 -2
View File
@@ -160,9 +160,10 @@ class Box_Mail
$mail->Host = $host;
$mail->SMTPDebug = 0;
if($port)
if($port) {
$mail->Port = (int)$port;
}
if($user) {
$mail->SMTPAuth = true;
$mail->SMTPSecure = $security;
+2 -5
View File
@@ -179,8 +179,7 @@ class Box_Tools
*/
public function getReferer($default = '/')
{
$r = empty($_SERVER['HTTP_REFERER']) ? $default : $_SERVER['HTTP_REFERER'];
return $r;
return empty($_SERVER['HTTP_REFERER']) ? $default : $_SERVER['HTTP_REFERER'];
}
/**
@@ -242,9 +241,7 @@ class Box_Tools
}
shuffle($passOrder);
$password = implode('', $passOrder);
return $password;
return implode('', $passOrder);
}
public function autoLinkText($text)
+9 -3
View File
@@ -71,8 +71,12 @@ class Box_Translate implements \Box\InjectionAwareInterface
@putenv('LANG='.$locale.'.'.$codeset);
@putenv('LANGUAGE='.$locale.'.'.$codeset);
// set locale
if (!defined('LC_MESSAGES')) define('LC_MESSAGES', 5);
if (!defined('LC_TIME')) define('LC_TIME', 2);
if (!defined('LC_MESSAGES')) {
define('LC_MESSAGES', 5);
}
if (!defined('LC_TIME')) {
define('LC_TIME', 2);
}
setlocale(LC_MESSAGES, $locale.'.'.$codeset);
setlocale(LC_TIME, $locale.'.'.$codeset);
bindtextdomain($this->domain, BB_PATH_LANGS);
@@ -82,7 +86,9 @@ class Box_Translate implements \Box\InjectionAwareInterface
if (!function_exists('__')) {
function __($msgid, array $values = NULL)
{
if (empty($msgid)) return null;
if (empty($msgid)) {
return null;
}
$string = gettext($msgid);
return empty($values) ? $string : strtr($string, $values);
}
+2 -1
View File
@@ -27,8 +27,9 @@ function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='', $isMask=
$type=strtolower($type);
if($type=='png'){
$info=$this->_parsepng($file);
if($info=='alpha')
if($info=='alpha'){
return $this->ImagePngWithAlpha($file,$x,$y,$w,$h,$link);
}
}
else
{
+2 -5
View File
@@ -708,11 +708,8 @@ class Whois2 {
return false;
}
}else {
if(preg_match("/".$not_found_string."/i",$whois_string)) {
return true;
}else {
return false;
}
return preg_match("/".$not_found_string."/i",$whois_string);
}
}
}
}
+4 -6
View File
@@ -1072,7 +1072,6 @@ class xmlapi {
// Set the $auth string
$authstr;
if ( $this->auth_type == 'hash' ) {
$authstr = 'Authorization: WHM ' . $this->user . ':' . $this->auth . "\r\n";
} elseif ($this->auth_type == 'pass' ) {
@@ -1087,7 +1086,6 @@ class xmlapi {
// Perform the query (or pass the info to the functions that actually do perform the query)
$response;
if ( $this->http_client == 'curl' ) {
$response = $this->curl_query($url, $args, $authstr);
} elseif ( $this->http_client == 'fopen' ) {
@@ -1114,12 +1112,12 @@ class xmlapi {
// The only time a response should contain <html> is in the case of authentication error
// cPanel 11.25 fixes this issue, but if <html> is in the response, we'll error out.
if (stristr($response, '<html>') == true) {
if (stristr($response, 'Login Attempt Failed') == true) {
if (stristr($response, '<html>')) {
if (stristr($response, 'Login Attempt Failed')) {
error_log("Login Attempt Failed");
return;
}
if (stristr($response, 'action="/login/"') == true) {
if (stristr($response, 'action="/login/"')) {
error_log("Authentication Error");
return;
}
@@ -1180,7 +1178,7 @@ class xmlapi {
curl_setopt($curl, CURLOPT_POSTFIELDS, "");
$result = curl_exec($curl);
if ($result == false) {
if (!$result) {
throw new Exception("curl_exec threw error \"" . curl_error($curl) . "\" for " . $url . "?" . $postdata );
}
curl_close($curl);
+1 -1
View File
@@ -121,7 +121,7 @@ class Service implements InjectionAwareInterface
$params[':search2'] = $search;
}
if (count ($where) > 0){
if (!empty($where)){
$whereStatment = implode(' and ', $where);
$sql .= ' WHERE '.$whereStatment;
}
@@ -13,7 +13,7 @@ namespace Box\Mod\Servicecentovacast;
* requests are supported.
*
* This can be used in place of something like CURL or WGET for HTTP requests.
* Native SSL (HTTPS) requests are also supported if the OpenSSL extension is 0
* Native SSL (HTTPS) requests are also supported if the OpenSSL extension is
* installed under PHP v4.3.0 or greater.
*
* If native SSL support is not available, the class will also check for the
+1 -1
View File
@@ -41,7 +41,7 @@ class Service implements \Box\InjectionAwareInterface
foreach ($form['fields'] as $field) {
if ($field['required'] == 1) {
$field_name = $field['name'];
if ((!isset($data[$field_name]) || empty($data[$field_name]))) {
if (!isset($data[$field_name]) || empty($data[$field_name])) {
throw new \Box_Exception("You must fill in all required fields. " . $field['label'] . " is missing", null, 9684);
}
}
+1 -1
View File
@@ -182,7 +182,7 @@ class Theme
preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
$tags = array_unique($tags[1]);
if(is_array($tags) && count($tags) > 0) {
if(is_array($tags) && !empty($tags)) {
if($invert === FALSE) {
return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
}
@@ -229,7 +229,6 @@ class ServiceTest extends \BBTestCase
$di['db'] = $db;
$service->setDi($di);
$code = $code;
$result = $service->getRateByCode($code);
$this->assertEquals($expected, $result);