diff --git a/README.md b/README.md index 25d38433..961a46c2 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,13 @@ last tested PHP 5.6 and PHP 7.0 ### namespace The new namespace branch. This is the development area for the master branch + +## Static checks + +With phpstan +`phpstan` + +With phan +`phan --progress-bar -C --analyze-twice` + +pslam is setup but not configured diff --git a/phpstan-bootstrap.php b/phpstan-bootstrap.php index 97b17e66..de809197 100755 --- a/phpstan-bootstrap.php +++ b/phpstan-bootstrap.php @@ -3,5 +3,7 @@ // Boostrap file for PHPstand // sets the _SERVER['HTTP_HOST'] var so we can have DB detection $_SERVER['HTTP_HOST'] = 'soba.tokyo.tequila.jp'; +// so www/includes/edit_base.php works +require_once('www/lib/Smarty/SmartyBC.class.php'); // __END__ diff --git a/phpstan.neon b/phpstan.neon index b15a317a..60b8a7ea 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,7 +2,7 @@ parameters: tmpDir: /tmp/phpstan-corelibs - level: 1 + level: 5 paths: - %currentWorkingDirectory%/www bootstrapFiles: @@ -20,6 +20,8 @@ parameters: # no check admin - www/admin/qq_file_upload_front.php - www/admin/qq_file_upload_ajax.php + - www/admin/class_test*php + - www/admin/error_test.php # admin synlink files - www/admin/edit_access.php - www/admin/edit_groups.php @@ -50,7 +52,10 @@ parameters: # ignore the smartyextend - www/lib/CoreLibs/Template/SmartyExtend.php # ignore errores with - # ignoreErrors: + ignoreErrors: + # - + # message: '#Reflection error: [a-zA-Z0-9\\_]+ not found.#' + # path: www/includes/edit_base.php #- 'error regex' #- # message: 'error regex' diff --git a/www/admin/class_test.array.php b/www/admin/class_test.array.php index e2088369..df7c4c97 100644 --- a/www/admin/class_test.array.php +++ b/www/admin/class_test.array.php @@ -33,7 +33,7 @@ use CoreLibs\Combined\ArrayHandler; use CoreLibs\Debug\Support as DgS; $basic = new CoreLibs\Basic(); -// $_array= new CoreLibs\Combined\ArrayHandler(); +// $_array = new CoreLibs\Combined\ArrayHandler(); // $array_class = 'CoreLibs\Combination\ArrayHandler'; print "TEST CLASS: ARRAY HANDLER"; diff --git a/www/configs/read_env_file.php b/www/configs/read_env_file.php index 400ef7eb..22f3e28c 100644 --- a/www/configs/read_env_file.php +++ b/www/configs/read_env_file.php @@ -42,7 +42,7 @@ function readEnvFile(string $path = __DIR__, string $env_file = '.env'): int $var = ''; while ($line = fgets($fp)) { // main match for variable = value part - if (preg_match("/^\s*([\w_]+)\s*=\s*((\"?).*)/", $line, $matches)) { + if (preg_match("/^\s*([\w_.]+)\s*=\s*((\"?).*)/", $line, $matches)) { $var = $matches[1]; $value = $matches[2]; $quotes = $matches[3]; diff --git a/www/lib/CoreLibs/ACL/Login.php b/www/lib/CoreLibs/ACL/Login.php index 0516a2b5..9ecc33b2 100644 --- a/www/lib/CoreLibs/ACL/Login.php +++ b/www/lib/CoreLibs/ACL/Login.php @@ -176,7 +176,7 @@ class Login extends \CoreLibs\DB\IO // check what schema to use. if there is a login schema use this, else check // if there is a schema set in the config, or fall back to DB_SCHEMA // if this exists, if this also does not exists use public schema - if (defined('LOGIN_DB_SCHEMA') && LOGIN_DB_SCHEMA) { + if (defined('LOGIN_DB_SCHEMA') && !empty(LOGIN_DB_SCHEMA)) { $SCHEMA = LOGIN_DB_SCHEMA; } elseif (isset($db_config['db_schema']) && $db_config['db_schema']) { $SCHEMA = $db_config['db_schema']; diff --git a/www/lib/CoreLibs/Admin/Backend.php b/www/lib/CoreLibs/Admin/Backend.php index 1c2dd9b8..38032744 100644 --- a/www/lib/CoreLibs/Admin/Backend.php +++ b/www/lib/CoreLibs/Admin/Backend.php @@ -178,7 +178,7 @@ class Backend extends \CoreLibs\DB\IO } // check schema - if (defined('LOGIN_DB_SCHEMA') && LOGIN_DB_SCHEMA) { + if (defined('LOGIN_DB_SCHEMA') && !empty(LOGIN_DB_SCHEMA)) { $SCHEMA = LOGIN_DB_SCHEMA; } elseif ($this->dbGetSchema()) { $SCHEMA = $this->dbGetSchema(); @@ -475,7 +475,7 @@ class Backend extends \CoreLibs\DB\IO string $associate = null, string $file = null ): void { - if (defined('GLOBAL_DB_SCHEMA') && GLOBAL_DB_SCHEMA) { + if (defined('GLOBAL_DB_SCHEMA') && !empty(GLOBAL_DB_SCHEMA)) { $SCHEMA = GLOBAL_DB_SCHEMA; } elseif ($this->dbGetSchema()) { $SCHEMA = $this->dbGetSchema(); diff --git a/www/lib/CoreLibs/Check/Password.php b/www/lib/CoreLibs/Check/Password.php index 6f0114b6..610231e6 100644 --- a/www/lib/CoreLibs/Check/Password.php +++ b/www/lib/CoreLibs/Check/Password.php @@ -35,8 +35,6 @@ class Password } else { return false; } - // in case something strange, return false on default - return false; } /** @@ -51,8 +49,6 @@ class Password } else { return false; } - // in case of strange, force re-hash - return true; } } diff --git a/www/lib/CoreLibs/Check/PhpVersion.php b/www/lib/CoreLibs/Check/PhpVersion.php index 89ad8b14..809a8b05 100644 --- a/www/lib/CoreLibs/Check/PhpVersion.php +++ b/www/lib/CoreLibs/Check/PhpVersion.php @@ -40,14 +40,10 @@ class PhpVersion define('PHP_VERSION_ID', (int)$version[0] * 10000 + (int)$version[1] * 100 + (int)$version[2]); } // check if matching for version - if ($min_version && !$max_version) { - if (PHP_VERSION_ID >= $min_version) { - return true; - } - } elseif ($min_version && $max_version) { - if (PHP_VERSION_ID >= $min_version && PHP_VERSION_ID <= $max_version) { - return true; - } + if (!$max_version && PHP_VERSION_ID >= $min_version) { + return true; + } elseif (PHP_VERSION_ID >= $min_version && PHP_VERSION_ID <= $max_version) { + return true; } // if no previous return, fail return false; diff --git a/www/lib/CoreLibs/Combined/DateTime.php b/www/lib/CoreLibs/Combined/DateTime.php index 1684ca77..2ea37bee 100644 --- a/www/lib/CoreLibs/Combined/DateTime.php +++ b/www/lib/CoreLibs/Combined/DateTime.php @@ -214,6 +214,8 @@ class DateTime return 0; } elseif ($start_date > $end_date) { return 1; + } else { + return false; } } @@ -242,6 +244,8 @@ class DateTime return 0; } elseif ($start_timestamp > $end_timestamp) { return 1; + } else { + return false; } } diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index bd639207..ebfa21eb 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -910,7 +910,7 @@ class IO extends \CoreLibs\Basic $this->db_debug = 0; } elseif ($this->db_debug) { $this->db_debug = 0; - } elseif (!$this->db_debug) { + } else { $this->db_debug = 1; } return $this->db_debug; @@ -1789,7 +1789,7 @@ class IO extends \CoreLibs\Basic ); $this->insert_id_ext = $this->insert_id; $this->insert_id_arr[] = $this->insert_id; - } elseif ($result) { + } elseif (!empty($result)) { $this->insert_id = []; $this->insert_id_ext = []; $this->insert_id_arr = []; @@ -1988,8 +1988,6 @@ class IO extends \CoreLibs\Basic return 'f'; } } - // if neither, just return data as is - return $string; } // ** REMARK ** @@ -2018,9 +2016,6 @@ class IO extends \CoreLibs\Basic if (!is_array($not_write_array)) { $not_write_array = []; } - if (is_array($table)) { - return false; - } $not_write_update_array = []; return $this->dbWriteDataExt( $write_array, @@ -2077,8 +2072,8 @@ class IO extends \CoreLibs\Basic // loop through the write array and each field to build the query foreach ($write_array as $field) { if ( - (!$primary_key['value'] || - ($primary_key['value'] && + (empty($primary_key['value']) || + (!empty($primary_key['value']) && !in_array($field, $not_write_update_array)) ) && !in_array($field, $not_write_array) diff --git a/www/lib/CoreLibs/DB/SQL/PgSQL.php b/www/lib/CoreLibs/DB/SQL/PgSQL.php index bd0ad478..02626e35 100644 --- a/www/lib/CoreLibs/DB/SQL/PgSQL.php +++ b/www/lib/CoreLibs/DB/SQL/PgSQL.php @@ -239,9 +239,9 @@ class PgSQL * if there is no pk_name tries to auto built it from the table name * this only works if db schema is after "no plural names. and pk name is table name + _id * detects schema prefix in table name - * @param string $query query string - * @param string $pk_name primary key name, if '' then auto detect - * @return string|int primary key value + * @param string $query query string + * @param string $pk_name primary key name, if '' then auto detect + * @return string|int|false primary key value */ public function __dbInsertId(string $query, string $pk_name) { @@ -274,6 +274,9 @@ class PgSQL $id = [-1, $q]; } return $id; + } else { + //if not insert, return false + return false; } } @@ -351,9 +354,7 @@ class PgSQL $this->dbh = pg_connect("host=" . $db_host . " port=" . $db_port . " user=" . $db_user . " password=" . $db_pass . " dbname=" . $db_name . " sslmode=" . $db_ssl); if (!$this->dbh) { - die(""); - return null; + die(""); } return $this->dbh; } diff --git a/www/lib/CoreLibs/Debug/FileWriter.php b/www/lib/CoreLibs/Debug/FileWriter.php index 25bfeea7..f5abf363 100644 --- a/www/lib/CoreLibs/Debug/FileWriter.php +++ b/www/lib/CoreLibs/Debug/FileWriter.php @@ -11,6 +11,7 @@ namespace CoreLibs\Debug; class FileWriter { + /** @var string */ private static $debug_filename = 'debug_file.log'; // where to write output /** diff --git a/www/lib/CoreLibs/Debug/Logging.php b/www/lib/CoreLibs/Debug/Logging.php index add3446c..4437de0e 100644 --- a/www/lib/CoreLibs/Debug/Logging.php +++ b/www/lib/CoreLibs/Debug/Logging.php @@ -341,7 +341,7 @@ class Logging */ public function debugFor(string $type, string $flag): void { - /** @phan-suppress-next-line PhanTypeMismatchArgumentReal */ + /** @phan-suppress-next-line PhanTypeMismatchArgumentReal @phpstan-ignore-next-line */ $this->setLogLevel(...[func_get_args()]); } diff --git a/www/lib/CoreLibs/Language/Core/GetTextReader.php b/www/lib/CoreLibs/Language/Core/GetTextReader.php index ae5d9dd3..65c7d2fb 100755 --- a/www/lib/CoreLibs/Language/Core/GetTextReader.php +++ b/www/lib/CoreLibs/Language/Core/GetTextReader.php @@ -108,13 +108,13 @@ class GetTextReader /** * Constructor * - * @param object $Reader the StreamReader object - * @param bool $enable_cache Enable or disable caching of strings (default on) + * @param object|bool $Reader the StreamReader object + * @param bool $enable_cache Enable or disable caching of strings (default on) */ public function __construct($Reader, $enable_cache = true) { // If there isn't a StreamReader, turn on short circuit mode. - if (!$Reader || $Reader->error) { + if ((!is_object($Reader) && !$Reader) || (is_object($Reader) && $Reader->error)) { $this->short_circuit = true; return; } @@ -125,7 +125,7 @@ class GetTextReader $MAGIC1 = "\x95\x04\x12\xde"; $MAGIC2 = "\xde\x12\x04\x95"; - $this->STREAM = $Reader; + $this->STREAM = (object)$Reader; $magic = $this->read(4); if ($magic == $MAGIC1) { $this->BYTEORDER = 1; @@ -351,7 +351,7 @@ class GetTextReader return $expr; } - /** + /** * Get possible plural forms from MO header * * @access private @@ -394,6 +394,7 @@ class GetTextReader $plural = 0; eval("$string"); + /** @phpstan-ignore-next-line */ if ($plural >= $total) { $plural = $total - 1; } diff --git a/www/lib/CoreLibs/Output/Form/Elements.php b/www/lib/CoreLibs/Output/Form/Elements.php index 25406a70..10aab431 100644 --- a/www/lib/CoreLibs/Output/Form/Elements.php +++ b/www/lib/CoreLibs/Output/Form/Elements.php @@ -270,6 +270,9 @@ class Elements return "mailto:" . $email; } elseif ($atag) { return $atag . $email; + } else { + // else just return email as is + return $email; } } } diff --git a/www/lib/CoreLibs/Output/Form/Generate.php b/www/lib/CoreLibs/Output/Form/Generate.php index 55b04bea..ba2e5e4b 100644 --- a/www/lib/CoreLibs/Output/Form/Generate.php +++ b/www/lib/CoreLibs/Output/Form/Generate.php @@ -267,6 +267,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO */ public function __construct(array $db_config, int $table_width = 750) { + global $table_arrays; // replace any non valid variable names // TODO extracft only alphanumeric and _ after . to _ replacement $this->my_page_name = str_replace(['.'], '_', \CoreLibs\Get\System::getPageName(1)); @@ -278,12 +279,15 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO // first check if we have a in page override as $table_arrays[page name] if ( - isset($_GLOBALS['table_arrays']) && - is_array($_GLOBALS['table_arrays']) && - isset($_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) && - is_array($_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) + /* isset($GLOBALS['table_arrays']) && + is_array($GLOBALS['table_arrays']) && + isset($GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) && + is_array($GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) */ + isset($table_arrays[\CoreLibs\Get\System::getPageName(1)]) && + is_array($table_arrays[\CoreLibs\Get\System::getPageName(1)]) ) { - $config_array = $_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]; + // $config_array = $GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]; + $config_array = $table_arrays[\CoreLibs\Get\System::getPageName(1)]; } else { // WARNING: auto spl load does not work with this as it is an array and not a function/object // check if this is the old path or the new path @@ -810,7 +814,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO (isset($this->security_level['delete']) && $this->base_acl_level >= $this->security_level['delete']) ) { - $old_school_hidden = 0; if ($this->base_acl_level >= $this->security_level['save']) { $seclevel_okay = 1; if (empty($this->table_array[$this->int_pk_name]['value'])) { @@ -819,7 +822,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $save = $this->l->__('Update'); } // print the old_school hidden if requestet - if ($old_school_hidden) { + if ($old_school_hidden == 1) { $pk_name = $this->int_pk_name; $pk_value = $this->table_array[$this->int_pk_name]['value']; } @@ -1270,7 +1273,10 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO // if mandatory && no input // $this->log->debug('form', 'A: ' . $this->table_array[$key]['type'] . ' -- ' // . $this->table_array[$key]['input_value'] . ' -- ' . $this->table_array[$key]['value']); - if (!$this->table_array[$key]['value'] && $this->table_array[$key]['type'] != 'binary') { + if ( + empty($this->table_array[$key]['value']) && + $this->table_array[$key]['type'] != 'binary' + ) { $this->msg .= sprintf( $this->l->__('Please enter something into the %s field!
'), $this->table_array[$key]['output_name'] @@ -1505,7 +1511,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO if ($order_name) { // first check out of order ... - if (!$this->table_array[$order_name]['value']) { + if (empty($this->table_array[$order_name]['value'])) { // set order (read max) $q = 'SELECT MAX(' . $order_name . ') + 1 AS max_page_order FROM ' . $this->table_name; list($this->table_array[$order_name]['value']) = $this->dbReturnRow($q); @@ -1513,7 +1519,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO if (!$this->table_array[$order_name]['value']) { $this->table_array[$order_name]['value'] = 1; } - } elseif ($this->table_array[$this->int_pk_name]['value']) { + } elseif (!empty($this->table_array[$this->int_pk_name]['value'])) { $q = 'SELECT ' . $order_name . ' FROM ' . $this->table_name . ' WHERE ' . $this->int_pk_name . ' = ' . $this->table_array[$this->int_pk_name]['value']; @@ -2377,7 +2383,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $this->element_list[$table_name]['max_empty'] = 10; } // check if we need to fill fields - $element_count = (isset($data['content']) && is_array($data['content'])) ? count($data['content']) : 0; + $element_count = count($data['content'] ?? []); $missing_empty_count = $this->element_list[$table_name]['max_empty'] - $element_count; $this->log->debug('CFG MAX', 'Max empty: ' . $this->element_list[$table_name]['max_empty'] . ', Missing: ' . $missing_empty_count diff --git a/www/lib/CoreLibs/Output/Image.php b/www/lib/CoreLibs/Output/Image.php index b64d2710..39b9f51d 100644 --- a/www/lib/CoreLibs/Output/Image.php +++ b/www/lib/CoreLibs/Output/Image.php @@ -130,10 +130,10 @@ class Image array_map('unlink', glob($delete_filename . '*')); } } else { - if ($dummy && strstr($dummy, '/') === false) { + if (!empty($dummy) && strstr($dummy, '/') === false) { // check if we have the "dummy" image flag set $filename = PICTURES . ICONS . strtoupper($dummy) . ".png"; - if ($dummy && file_exists($filename) && is_file($filename)) { + if (!empty($dummy) && file_exists($filename) && is_file($filename)) { $return_data = $filename; } else { $return_data = false; diff --git a/www/lib/CoreLibs/Output/Progressbar.php b/www/lib/CoreLibs/Output/Progressbar.php index ead3e987..db6cbb7f 100644 --- a/www/lib/CoreLibs/Output/Progressbar.php +++ b/www/lib/CoreLibs/Output/Progressbar.php @@ -22,9 +22,13 @@ class ProgressBar { // private vars + /** @var string */ public $code; // unique code + /** @var string */ public $status = 'new'; // current status (new,show,hide) + /** @var int */ public $step = 0; // current step + /** @var array */ public $position = [ // current bar position 'left' => null, 'top' => null, @@ -32,27 +36,43 @@ class ProgressBar 'height' => null, ]; + /** @var int */ public $clear_buffer_size = 1; // we need to send this before the lfush to get browser output + /** @var int */ public $clear_buffer_size_init = 1024 * 1024; // if I don't send that junk, it won't send anything // public vars + /** @var int */ public $min = 0; // minimal steps + /** @var int */ public $max = 100; // maximal steps + /** @var int */ public $left = 5; // bar position from left + /** @var int */ public $top = 5; // bar position from top + /** @var int */ public $width = 300; // bar width + /** @var int */ public $height = 25; // bar height + /** @var int */ public $pedding = 0; // bar pedding + /** @var string */ public $color = '#0033ff'; // bar color + /** @var string */ public $bgr_color = '#c0c0c0'; // bar background color + /** @var string */ public $bgr_color_master = '#ffffff'; // master div background color + /** @var int */ public $border = 1; // bar border width + /** @var string */ public $brd_color = '#000000'; // bar border color + /** @var string */ public $direction = 'right'; // direction of motion (right,left,up,down) + /** @var array */ public $frame = ['show' => false]; // ProgressBar Frame /* 'show' => false, # frame show (true/false) 'left' => 200, # frame position from left @@ -64,6 +84,7 @@ class ProgressBar 'brd_color' => '#dfdfdf #404040 #404040 #dfdfdf' # frame border color */ + /** @var array */ public $label = []; // ProgressBar Labels /* 'name' => [ # label name 'type' => 'text', # label type (text,button,step,percent,crossbar) @@ -81,6 +102,7 @@ class ProgressBar ] */ + /** @var string */ // output strings public $prefix_message = ''; @@ -141,8 +163,8 @@ class ProgressBar /** * calculate position in bar step - * @param float $step percent step to do - * @return array bar position as array + * @param float $step percent step to do + * @return array bar position as array */ private function __calculatePosition(float $step): array { diff --git a/www/lib/Error.Handling.php b/www/lib/Error.Handling.php index c2e1db9b..0c9b6bb9 100644 --- a/www/lib/Error.Handling.php +++ b/www/lib/Error.Handling.php @@ -10,22 +10,24 @@ * error etc will still be written to the log/display *********************************************************************/ - declare(strict_types=1); +declare(strict_types=1); /** * will catch any error except E_ERROR and try to write them to the log file * in log/php_error-.log * if this fails, it will print the data to the window via echo - * @param int $type the error code from PHP - * @param string $message the error message from php - * @param string $file in which file the error happend. this is the source file (eg include) - * @param int $line in which line the error happened - * @param array $context array with all the variable - * @return bool true, so cought errors do not get processed by the PHP error engine + * @param int $type the error code from PHP + * @param string $message the error message from php + * @param string $file in which file the error happend. + * this is the source file (eg include) + * @param int $line in which line the error happened + * @param array $context array with all the variable + * @return bool True, so cought errors do not get processed + * by the PHP error engine */ function MyErrorHandler(int $type, string $message, string $file, int $line, array $context): bool { - if (!(error_reporting() & $type) && !SHOW_ALL_ERRORS) { + if (!(error_reporting() & $type) && empty(SHOW_ALL_ERRORS)) { // This error code is not included in error_reporting return false; } diff --git a/www/lib/autoloader.php b/www/lib/autoloader.php index 851abfcc..4ffc7570 100644 --- a/www/lib/autoloader.php +++ b/www/lib/autoloader.php @@ -10,21 +10,26 @@ if (class_exists('Autoload', false) === false) { // define the auto loader class class Autoload { - // we do it simple here - // passes on the class to load and we search here in namespace - // to load that class - public static function load($class) + /** + * we do it simple here + * passes on the class to load and we search here in namespace + * to load that class + * + * @param string $class Namespace + class to load + * @return void + */ + public static function load(string $class) { // print "(1) Class: $class / DIR: ".__DIR__."
"; // set directory seperator (we need to replace from namespace) - $DS = defined('DS') ? DS : DIRECTORY_SEPARATOR; + $DS = DIRECTORY_SEPARATOR; // base lib $LIB = defined('LIB') ? LIB : 'lib' . $DS; // if lib is in path at the end, do not add lib again // note that $LIB can have a directory seperator at the end // strip that out before we do a match $_LIB = rtrim($LIB, $DS); - if (preg_match("|$_LIB$|", __DIR__) === false) { + if (!preg_match("|$_LIB$|", __DIR__)) { $LIB .= $DS; } else { $LIB = ''; @@ -50,9 +55,7 @@ if (class_exists('Autoload', false) === false) { // we should sub that // self::loadFile($path); include $path; - return true; } - return false; } // end class define } diff --git a/www/psalm.xml b/www/psalm.xml index ecb85e0f..9b13ba60 100644 --- a/www/psalm.xml +++ b/www/psalm.xml @@ -11,12 +11,6 @@ - - - - - - @@ -58,7 +52,6 @@ -