Skip to content

Commit

Permalink
issue: Undefined Key, Var, Prop
Browse files Browse the repository at this point in the history
This addresses the `Undefined array key`, `Undefined variable`, and
`Undefined property` errors.
  • Loading branch information
JediKev committed Feb 7, 2022
1 parent e261a5f commit 6974734
Show file tree
Hide file tree
Showing 23 changed files with 77 additions and 71 deletions.
2 changes: 1 addition & 1 deletion include/class.auth.php
Expand Up @@ -960,7 +960,7 @@ static function authTimeout() {
$cfg = $ost->getConfig();

$authsession = &$_SESSION['_auth']['staff'];
if (!$authsession['laststrike'])
if (!isset($authsession['laststrike']))
return;

//Veto login due to excessive login attempts.
Expand Down
2 changes: 1 addition & 1 deletion include/class.csrf.php
Expand Up @@ -60,7 +60,7 @@ function rotate() {

function getToken() {

if (!$this->csrf['token'] || $this->isExpired()) {
if ((!is_array($this->csrf) || !$this->csrf['token']) || $this->isExpired()) {
$this->rotate();
} else {
//Reset the timer
Expand Down
4 changes: 2 additions & 2 deletions include/class.forms.php
Expand Up @@ -604,7 +604,7 @@ static function allTypes() {
foreach (static::$more_types as $group => $entries)
foreach ($entries as $c)
static::$types[$group] = array_merge(
static::$types[$group] ?: array(), call_user_func($c));
static::$types[$group] ?? array(), call_user_func($c));

static::$more_types = array();
}
Expand Down Expand Up @@ -1234,7 +1234,7 @@ function getConfigurationOptions() {
* the default value will be reflected in the returned configuration.
*/
function getConfiguration() {
if (!$this->_config) {
if (!isset($this->_config)) {
$this->_config = $this->get('configuration');
if (is_string($this->_config))
$this->_config = JsonDataParser::parse($this->_config);
Expand Down
14 changes: 7 additions & 7 deletions include/class.i18n.php
Expand Up @@ -240,7 +240,7 @@ static function availableLanguages($base=I18N_DIR) {
'code' => $base,
);
$installed[strtolower($base)]['flag'] = strtolower(
$langs[$code]['flag'] ?: $locale ?: $code
($langs[$code]['flag'] ?? $locale) ?: $code
);
}
}
Expand Down Expand Up @@ -382,7 +382,7 @@ static function getCurrentLanguage($user=false) {
return $lang;

// Support the flag buttons for guests
if ((!$user || $user != $thisstaff) && $_SESSION['::lang'])
if ((!$user || $user != $thisstaff) && isset($_SESSION['::lang']))
return $_SESSION['::lang'];

return self::getDefaultLanguage();
Expand Down Expand Up @@ -465,11 +465,11 @@ static function getIntDateFormatter($options) {
// Create formatter && cache
$cache[$k] = $formatter = new IntlDateFormatter(
$options['locale'],
$options['daytype'] ?: null,
$options['timetype'] ?: null,
$options['timezone'] ?: null,
$options['calendar'] ?: IntlDateFormatter::GREGORIAN,
$options['pattern'] ?: null
$options['daytype'] ?? null,
$options['timetype'] ?? null,
$options['timezone'] ?? null,
$options['calendar'] ?? IntlDateFormatter::GREGORIAN,
$options['pattern'] ?? null
);

return $formatter;
Expand Down
4 changes: 2 additions & 2 deletions include/class.list.php
Expand Up @@ -927,9 +927,9 @@ function getItems($criteria = array()) {
$items = TicketStatus::objects();
if ($filters)
$items->filter($filters);
if ($criteria['limit'])
if (isset($criteria['limit']))
$items->limit($criteria['limit']);
if ($criteria['offset'])
if (isset($criteria['offset']))
$items->offset($criteria['offset']);

$items->order_by($this->getListOrderBy());
Expand Down
4 changes: 2 additions & 2 deletions include/class.nav.php
Expand Up @@ -125,7 +125,7 @@ function getSubNavInfo() {
function getTabs(){
global $thisstaff;

if(!$this->tabs) {
if(!isset($this->tabs)) {
$this->tabs = array();
$this->tabs['dashboard'] = array(
'desc'=>__('Dashboard'),'href'=>'dashboard.php','title'=>__('Agent Dashboard'), "class"=>"no-pjax"
Expand Down Expand Up @@ -210,7 +210,7 @@ function getRegisteredApps() {

function getTabs(){

if(!$this->tabs){
if(!isset($this->tabs)){

$tabs=array();
$tabs['dashboard']=array('desc'=>__('Dashboard'),'href'=>'logs.php','title'=>__('Admin Dashboard'));
Expand Down
34 changes: 18 additions & 16 deletions include/class.orm.php
Expand Up @@ -197,15 +197,15 @@ function processJoin(&$j) {
= is_array($foreign) ? $foreign : explode('.', $foreign);
}
}
if ($j['list'] && !isset($j['broker'])) {
if (isset($j['list']) && !isset($j['broker'])) {
$j['broker'] = 'InstrumentedList';
}
if ($j['broker'] && !class_exists($j['broker'])) {
if (isset($j['broker']) && !class_exists($j['broker'])) {
throw new OrmException($j['broker'] . ': List broker does not exist');
}
foreach ($constraint as $local => $foreign) {
list($class, $field) = $foreign;
if ($local[0] == "'" || $field[0] == "'" || !class_exists($class))
if ((isset($local[0]) && $local[0] == "'") || $field[0] == "'" || !class_exists($class))
continue;
$j['fkey'] = $foreign;
$j['local'] = $local;
Expand Down Expand Up @@ -351,7 +351,7 @@ function get($field, $default=false) {
foreach ($j['constraint'] as $local=>$foreign) {
list($_klas,$F) = $foreign;
$fkey[$F ?: $_klas] = ($local[0] == "'")
? trim($local, "'") : $this->ht[$local];
? trim($local, "'") : $this->ht[$local] ?? null;
}
$v = $this->ht[$field] = new $j['broker'](
// Send Model, [Foriegn-Field => Local-Id]
Expand Down Expand Up @@ -444,7 +444,7 @@ function set($field, $value) {
$joins = static::getMeta('joins');
if (isset($joins[$field])) {
$j = $joins[$field];
if ($j['list'] && ($value instanceof InstrumentedList)) {
if (isset($j['list']) && ($value instanceof InstrumentedList)) {
// Magic list property
$this->ht[$field] = $value;
return;
Expand Down Expand Up @@ -773,6 +773,7 @@ static function wrap(VerySimpleModel $model, $extras=array(), $class=false) {
if ($extras instanceof VerySimpleModel) {
$extra = "Writeable";
}
$extra = $extra ?? null;
if (!isset($classes[$class])) {
$classes[$class] = eval(<<<END_CLASS
class {$extra}AnnotatedModel___{$class}
Expand Down Expand Up @@ -1244,7 +1245,7 @@ function order_by($order, $direction=false) {
}
function getSortFields() {
$ordering = $this->ordering;
if ($this->extra['order_by'])
if (isset($this->extra['order_by']))
$ordering = array_merge($ordering, $this->extra['order_by']);
return $ordering;
}
Expand All @@ -1265,7 +1266,7 @@ function offset($at) {
}

function isWindowed() {
return $this->limit || $this->offset || (count($this->values) + count($this->annotations) + @count($this->extra['select'])) > 1;
return $this->limit || $this->offset || (count($this->values) + count($this->annotations) + @count($this->extra['select'] ?? array())) > 1;
}

/**
Expand Down Expand Up @@ -1618,7 +1619,7 @@ function getQuery($options=array()) {
$meta = $model::getMeta();
$query = clone $this;
$options += $this->options;
if ($options['nosort'])
if (isset($options['nosort']))
$query->ordering = array();
elseif (!$query->ordering && $meta['ordering'])
$query->ordering = $meta['ordering'];
Expand All @@ -1627,7 +1628,7 @@ function getQuery($options=array()) {
if (!$query->defer && $meta['defer'])
$query->defer = $meta['defer'];

$class = $options['compiler'] ?: $this->compiler;
$class = $options['compiler'] ?? $this->compiler;
$compiler = new $class($options);
$this->query = $compiler->compileSelect($query);

Expand Down Expand Up @@ -1992,6 +1993,7 @@ function buildModel($row, $cache=true) {
function getIterator() {
$func = ($this->map) ? 'getRow' : 'getArray';
$func = array($this->resource, $func);
$cache = true;

return new CallbackSimpleIterator(function() use ($func, $cache) {
global $StopIteration;
Expand Down Expand Up @@ -2293,7 +2295,7 @@ static function splitCriteria($criteria) {
$field = array_pop($path);
}
}
return array($field, $path, $operator ?: 'exact');
return array($field, $path, $operator ?? 'exact');
}

/**
Expand Down Expand Up @@ -2454,7 +2456,7 @@ function getField($field, $model, $options=array()) {
foreach ($joins as $i=>$A) {
// Add the conststraint as the last arg to the last join
if ($i == $last)
$constraint = $options['constraint'];
$constraint = $options['constraint'] ?? null;
$alias = $this->pushJoin($A[0], $A[1], $A[2], $A[3], $constraint);
}

Expand Down Expand Up @@ -2627,7 +2629,7 @@ function getParams() {
function getJoins($queryset) {
$sql = '';
foreach ($this->joins as $path => $j) {
if (!$j['sql'])
if (!isset($j['sql']))
continue;
list($base, $constraints) = $j['sql'];
// Add in path-specific constraints, if any
Expand Down Expand Up @@ -2811,8 +2813,8 @@ function __regex($a, $b) {
function __range($a, $b) {
return sprintf('%s BETWEEN %s AND %s',
$a,
$b[2] ? $b[0] : $this->input($b[0]),
$b[2] ? $b[1] : $this->input($b[1]));
isset($b[2]) ? $b[0] : $this->input($b[0]),
isset($b[2]) ? $b[1] : $this->input($b[1]));
}

function compileJoin($tip, $model, $alias, $info, $extra=false) {
Expand Down Expand Up @@ -3102,7 +3104,7 @@ function compileSelect($queryset) {
if ($A instanceof SqlAggregate)
$need_group_by = true;
$T = $A->toSql($this, $model, $alias);
if ($fieldMap) {
if (isset($fieldMap)) {
array_splice($fields, count($fieldMap[0][0]), 0, array($T));
$fieldMap[0][0][] = $alias;
}
Expand Down Expand Up @@ -3179,7 +3181,7 @@ function($m) use ($self, $q) {
break;
}

return new MysqlExecutor($sql, $this->params, $fieldMap);
return new MysqlExecutor($sql, $this->params, $fieldMap ?? array());
}

function __compileUpdateSet($model, array $pk) {
Expand Down
4 changes: 2 additions & 2 deletions include/class.osticket.php
Expand Up @@ -183,7 +183,7 @@ function setErrors($errors) {
}

function getError() {
return $this->system['err'];
return $this->system['err'] ?? null;
}

function setError($error) {
Expand All @@ -208,7 +208,7 @@ function clearWarning() {


function getNotice() {
return $this->system['notice'];
return $this->system['notice'] ?? null;
}

function setNotice($notice) {
Expand Down
2 changes: 2 additions & 0 deletions include/class.pagenate.php
Expand Up @@ -61,6 +61,8 @@ function setURL($url='',$vars='') {
$url = THISPAGE.'?';
}

if (is_array($vars) && empty($vars))
$vars = '';
if ($vars && is_array($vars))
$vars = Http::build_query($vars);

Expand Down
7 changes: 4 additions & 3 deletions include/class.plugin.php
Expand Up @@ -171,9 +171,10 @@ static function allInstalled() {
$info = static::getInfoForPath(
INCLUDE_DIR . $ht['install_path'], $ht['isphar']);

list($path, $class) = explode(':', $info['plugin']);
if (!$class)
$class = $path;
if (is_array($info) && isset($info['plugin']))
list($path, $class) = explode(':', $info['plugin']);
if (!isset($class))
$class = $path ?? null;
elseif ($ht['isphar'])
@include_once('phar://' . INCLUDE_DIR . $ht['install_path']
. '/' . $path);
Expand Down
10 changes: 5 additions & 5 deletions include/class.queue.php
Expand Up @@ -385,8 +385,8 @@ static function getSearchableFields($base, $recurse=2,
$exclude[$base] = 1;
foreach ($base::getMeta('joins') as $path=>$j) {
$fc = $j['fkey'][0];
if (isset($exclude[$fc]) || $j['list']
|| (isset($j['searchable']) && !$j['searchable']))
if (isset($exclude[$fc]) || isset($j['list'])
|| (isset($j['searchable']) && !isset($j['searchable'])))
continue;
foreach (static::getSearchableFields($fc, $recurse-1,
true, $exclude)
Expand Down Expand Up @@ -2278,7 +2278,7 @@ function getFields() {
$secondary = CustomQueue::getOrmPath($this->secondary);
if (($F = $fields[$primary]) && (list(,$field) = $F))
$this->_fields[$primary] = $field;
if (($F = $fields[$secondary]) && (list(,$field) = $F))
if ((isset($fields[$secondary]) && ($F = $fields[$secondary])) && (list(,$field) = $F))
$this->_fields[$secondary] = $field;
}
return $this->_fields;
Expand Down Expand Up @@ -2368,7 +2368,7 @@ function renderBasicValue($row) {
) {
return new LazyDisplayWrapper($F, $T);
}
if (($F = $fields[$secondary])
if (isset($fields[$secondary]) && ($F = $fields[$secondary])
&& ($T = $F->from_query($row, $secondary))
) {
return new LazyDisplayWrapper($F, $T);
Expand Down Expand Up @@ -2434,7 +2434,7 @@ function mangleQuery($query, $root=null) {
$query = $this->addToQuery($query, $field,
CustomQueue::getOrmPath($this->primary, $query));
}
if ($field = $fields[$this->secondary]) {
if (isset($fields[$this->secondary]) && ($field = $fields[$this->secondary])) {
$query = $this->addToQuery($query, $field,
CustomQueue::getOrmPath($this->secondary, $query));
}
Expand Down
4 changes: 2 additions & 2 deletions include/class.search.php
Expand Up @@ -204,7 +204,7 @@ function bootstrap() {
if (defined('SEARCH_BACKEND'))
$bk = SearchBackend::getInstance(SEARCH_BACKEND);

if (!$bk && !($bk = SearchBackend::getInstance('mysql')))
if (!isset($bk) && !($bk = SearchBackend::getInstance('mysql')))
// No backend registered or defined
return false;

Expand Down Expand Up @@ -793,7 +793,7 @@ function getCriteria($include_parent=true) {

if (!isset($this->_criteria)) {
$this->getSettings();
$this->_criteria = $this->_settings['criteria'] ?: array();
$this->_criteria = $this->_settings['criteria'] ?? array();
}

$criteria = $this->_criteria;
Expand Down
2 changes: 1 addition & 1 deletion include/class.thread.php
Expand Up @@ -1328,7 +1328,7 @@ function saveEmailInfo($vars) {
function logEmailHeaders($id, $mid, $header=false) {
$headerInfo = Mail_Parse::splitHeaders($header);

if (!$id || !$mid)
if (is_null($id) || !$mid)
return false;

$this->email_info = new ThreadEntryEmailInfo(array(
Expand Down
3 changes: 2 additions & 1 deletion include/class.translation.php
Expand Up @@ -540,6 +540,7 @@ function close() {
class Translation extends gettext_reader implements Serializable {

var $charset;
var $encode;

const META_HEADER = 0;

Expand Down Expand Up @@ -798,7 +799,7 @@ static function get_list_of_locales($locale) {
$locale, $m)
) {

if ($m['modifier']) {
if (isset($m['modifier'])) {
// TODO: Confirm if Crowdin uses the modifer flags
if ($m['country']) {
$locale_names[] = "{$m['lang']}_{$m['country']}@{$m['modifier']}";
Expand Down
2 changes: 1 addition & 1 deletion include/staff/header.inc.php
Expand Up @@ -106,7 +106,7 @@
<?php include STAFFINC_DIR . "templates/sub-navigation.tmpl.php"; ?>

<div id="content">
<?php if($errors['err']) { ?>
<?php if(isset($errors['err'])) { ?>
<div id="msg_error"><?php echo $errors['err']; ?></div>
<?php }elseif($msg) { ?>
<div id="msg_notice"><?php echo $msg; ?></div>
Expand Down
2 changes: 1 addition & 1 deletion include/staff/login.tpl.php
Expand Up @@ -43,7 +43,7 @@
<input type="hidden" name="do" value="scplogin">
<fieldset>
<input type="text" name="userid" id="name" value="<?php
echo $info['userid']; ?>" placeholder="<?php echo __('Email or Username'); ?>"
echo $info['userid'] ?? null; ?>" placeholder="<?php echo __('Email or Username'); ?>"
autofocus autocorrect="off" autocapitalize="off">
<input type="password" name="passwd" id="pass" placeholder="<?php echo __('Password'); ?>" autocorrect="off" autocapitalize="off">
<h3 style="display:inline"><a id="reset-link" class="<?php
Expand Down

0 comments on commit 6974734

Please sign in to comment.