Skip to content
Permalink
Browse files

Fix a few static analyzer findings

  • Loading branch information...
flack committed Sep 11, 2019
1 parent 7451841 commit da2115a10e0108e1b5a0a78ff82f52ed40434953
@@ -21,7 +21,7 @@ class midcom_compat_environment
public function __construct()
{
if ( php_sapi_name() != 'cli'
if ( PHP_SAPI != 'cli'
|| !empty($_SERVER['REMOTE_ADDR'])) {
$this->_httpd_setup();
}
@@ -96,7 +96,7 @@ protected function _init()
// determine id / guid
if (isset($this->_request['params']['id'])) {
$this->_id = intval($this->_request['params']['id']);
$this->_id = (int) $this->_request['params']['id'];
}
if (isset($this->_request['params']['guid'])) {
$this->_id = $this->_request['params']['guid'];
@@ -488,7 +488,7 @@ private function _get_component_style(midcom_db_topic $topic)
} else {
$style = $topic->style ?: midcom_core_context::get()->get_inherited_style();
if ( is_string($style)
&& strpos($style, 'theme:') === 0) {
&& substr($style, 0, 6) === 'theme:') {
$theme_dir = OPENPSA2_THEME_ROOT . midcom::get()->config->get('theme') . '/style';
$parts = explode('/', str_replace('theme:/', '', $style));
@@ -415,7 +415,7 @@ public function get_search_properties()
$always_search_all = $this->_config->get('always_search_fields') ?: [];
if (!empty($always_search_all[$this->mgdschema_class])) {
$fields = array_intersect($always_search_all[$this->mgdschema_class], $properties);
$search_properties = $search_properties + array_flip($fields);
$search_properties += array_flip($fields);
}
// Exceptions - never search these fields
@@ -106,10 +106,9 @@ private function prepare_backend(array $config, $name)
$backend->setMemcached($memcached);
$memcache_operational = true;
break;
} else {
midcom::get()->debug->log_php_error(MIDCOM_LOG_ERROR);
debug_add("memcache: Failed to connect to {$host}:{$port}. Falling back to filecache", MIDCOM_LOG_ERROR);
}
midcom::get()->debug->log_php_error(MIDCOM_LOG_ERROR);
debug_add("memcache: Failed to connect to {$host}:{$port}. Falling back to filecache", MIDCOM_LOG_ERROR);
// fall-through
case 'dba':
case 'flatfile':
@@ -420,7 +420,7 @@ public function no_cache(Response $response = null)
if ($response) {
$response->headers->set('Cache-Control', $settings);
} else if (!$this->_no_cache) {
} elseif (!$this->_no_cache) {
if (headers_sent()) {
debug_add('Warning, we should move to no_cache but headers have already been sent, skipping header transmission.', MIDCOM_LOG_ERROR);
} else {
@@ -267,11 +267,10 @@ private function convert_to_config(array $values) : array
$config_array = [];
foreach ($this->_request_data['config']->get_all() as $key => $val) {
if (isset($values[$key])) {
$newval = $values[$key];
} else {
if (!isset($values[$key])) {
continue;
}
$newval = $values[$key];
if ($newval === '') {
continue;
@@ -30,7 +30,7 @@ public function render_invoice_actions(org_openpsa_invoices_invoice_dba $invoice
// sending per mail enabled in billing data?
$billing_data = org_openpsa_invoices_billing_data_dba::get_by_object($invoice);
// only show if mail was chosen as option
if (intval($billing_data->sendingoption) == 2) {
if ((int) $billing_data->sendingoption === 2) {
$action = 'send_by_mail';
$icon = '<i class="fa fa-paper-plane"></i>';
} else {
@@ -84,9 +84,9 @@ public function get_history()
usort($entries, function ($a, $b) {
if ($a['timestamp'] == $b['timestamp']) {
return $b['order'] <=> $b['order'];
return $b['order'] <=> $a['order'];
}
return ($b['timestamp'] <=> $a['timestamp']);
return $b['timestamp'] <=> $a['timestamp'];
});
return $entries;
@@ -138,7 +138,7 @@ private function _replace_callback($matches)
if (is_object($value)) {
if (empty($matches[2])) {
if (method_exists($value, '__toString')) {
return $value->__toString();
return (string) $value;
}
throw new midcom_error("__toString method not found on " . get_class($value));
}
@@ -123,7 +123,7 @@ public static function list_groups($up, $prefix, $keyproperty, $order_by_score =
$ret[$key] .= "{$field_val} ";
}
$ret = $ret + self::list_groups($result['id'], "{$prefix} > ", $keyproperty, $order_by_score, $label_fields);
$ret += self::list_groups($result['id'], "{$prefix} > ", $keyproperty, $order_by_score, $label_fields);
}
return $ret;
@@ -64,7 +64,7 @@ private function get_salesproject($person_guid)
public function handle_create()
{
$person_guid = $this->_request['params']['person_guid'] ?? false;
$product_id = isset($this->_request['params']['product_id']) ? intval($this->_request['params']['product_id']) : false;
$product_id = isset($this->_request['params']['product_id']) ? (int) $this->_request['params']['product_id'] : false;
$run_cycle = $this->_request['params']['run_cycle'] ?? false;
// check param
@@ -86,7 +86,7 @@ public function handle_create()
// is a subscription?
if ($product->delivery == org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION) {
$continuous = isset($this->_request['params']['continuous']) ? ((bool) $this->_request['params']['continuous']) : false;
$continuous = isset($this->_request['params']['continuous']) ? (bool) $this->_request['params']['continuous'] : false;
$deliverable->continuous = $continuous;
// setting schema parameter to subscription
$deliverable->set_parameter('midcom.helper.datamanager2', 'schema_name', 'subscription');
@@ -114,7 +114,7 @@ public function calculate_price()
$value += $deliverable->price;
$cost += $deliverable->cost;
if ($deliverable->invoiceByActualUnits) {
$value = $value + $deliverable->invoiced;
$value += $deliverable->invoiced;
}
}
}
@@ -231,7 +231,7 @@ function get_members()
$mc = org_openpsa_contacts_role_dba::new_collector('objectGuid', $this->guid);
$mc->add_constraint('role', '=', self::ROLE_MEMBER);
$this->_contacts = $this->_contacts + array_fill_keys($mc->get_values('person'), true);
$this->_contacts += array_fill_keys($mc->get_values('person'), true);
}
}
@@ -29,8 +29,7 @@ protected function configure()
$this->setName('midcom:purgedeleted')
->setAliases(['purgedeleted'])
->setDescription('Purge deleted objects')
->addOption('days', 'd', InputOption::VALUE_REQUIRED, 'Grace period in days', $config->get('cron_purge_deleted_after'))
->addOption('chunksize', 'c', InputOption::VALUE_REQUIRED, 'Maximum number of objects purged per class at once (use 0 to disable limit)', '50');
->addOption('days', 'd', InputOption::VALUE_REQUIRED, 'Grace period in days', $config->get('cron_purge_deleted_after'));
}
protected function interact(InputInterface $input, OutputInterface $output)
@@ -43,7 +42,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$handler = new \midcom_cron_purgedeleted;
$handler->set_cutoff((int) $input->getOption('days'));
$chunk_size = (int) $input->getOption('chunksize');
$output->writeln('Purging entries deleted before ' . gmdate('Y-m-d H:i:s', $handler->get_cutoff()));
@@ -54,18 +52,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln("\n\nProcessing class <info>{$mgdschema}</info>");
$purged = 0;
$errors = 0;
do {
$stats = $handler->process_class($mgdschema, $chunk_size);
foreach ($stats['errors'] as $error) {
$output->writeln(' <error>' . $error . '</error>');
}
if ($purged > 0) {
$output->write("\x0D");
}
$purged += $stats['purged'];
$errors += count($stats['errors']);
$output->write(" Purged <info>{$purged}</info> deleted objects, <comment>" . $errors . " failures</comment>");
} while ($stats['found'] == $chunk_size);
$stats = $handler->process_class($mgdschema);
foreach ($stats['errors'] as $error) {
$output->writeln(' <error>' . $error . '</error>');
}
if ($purged > 0) {
$output->write("\x0D");
}
$purged += $stats['purged'];
$errors += count($stats['errors']);
$output->write(" Purged <info>{$purged}</info> deleted objects, <comment>" . $errors . " failures</comment>");
$total_purged += $purged;
$total_errors += $errors;
}
@@ -70,7 +70,8 @@ public function reverseTransform($array)
if ($this->config['type_config']['storage_type'] === jsdateType::UNIXTIME) {
return $array['date']->format('U');
} elseif ($this->config['type_config']['storage_type'] === jsdateType::ISO) {
}
if ($this->config['type_config']['storage_type'] === jsdateType::ISO) {
return $array['date']->format('Y-m-d H:i:s');
}
}
@@ -55,8 +55,7 @@ public function form_rows(FormView $view, array $data)
continue;
}
if ( array_key_exists('start_fieldset', $child->vars)
&& $child->vars['start_fieldset'] !== null) {
if (isset($child->vars['start_fieldset'])) {
$string .= '<div class="fieldset">';
if (!empty($child->vars['start_fieldset']['title'])) {
$string .= '<h2>' . $this->renderer->humanize($child->vars['start_fieldset']['title']) . '</h2>';
@@ -66,8 +65,7 @@ public function form_rows(FormView $view, array $data)
|| ($child->vars['data'] !== '' && $child->vars['data'] !== null && $child->vars['data'] !== [])) {
$string .= $this->renderer->row($child);
}
if ( array_key_exists('end_fieldset', $child->vars)
&& $child->vars['end_fieldset'] !== null) {
if (isset($child->vars['end_fieldset'])) {
$end_fieldsets = max(1, (int) $child->vars['end_fieldset']);
$string .= str_repeat('</div>', $end_fieldsets);
}
@@ -105,7 +105,7 @@ public function list_parameters($domain = null)
return [];
}
if (!is_null($domain)) {
if ($domain !== null) {
return $this->list_parameters_domain($domain);
}
@@ -300,7 +300,7 @@ public function render($entries = false)
$this->_provider->set_grid($this);
}
}
echo $this->__toString();
echo (string) $this;
}
public function __toString()
@@ -153,7 +153,7 @@ public function set_rows(array $rows)
public function get_rows()
{
if (is_null($this->_rows)) {
if ($this->_rows === null) {
$this->_get_rows();
}
return $this->_rows;
@@ -175,7 +175,7 @@ public function get_query()
$this->_parse_query($_GET);
}
$field = $this->_sort_field;
if (!is_null($field)) {
if ($field !== null) {
$field = str_replace('index_', '', $field);
}
@@ -184,7 +184,7 @@ public function get_query()
public function count_rows()
{
if (is_null($this->_total_rows)) {
if ($this->_total_rows === null) {
$qb = $this->_prepare_query();
$this->_total_rows = $qb->count();
}
@@ -245,7 +245,7 @@ private function _convert_to_localdata()
private function _render_json()
{
$rows = $this->get_rows();
if (is_null($this->_total_rows)) {
if ($this->_total_rows === null) {
$this->_total_rows = count($rows);
}
@@ -285,7 +285,7 @@ private function _parse_query(array $query)
private function _prepare_query()
{
if (is_null($this->_query)) {
if ($this->_query === null) {
$this->_query = $this->get_query();
}
return $this->_query;
@@ -59,8 +59,6 @@ public function __construct(midcom_core_context $context)
}
}
}
$this->url = '';
}
/**

0 comments on commit da2115a

Please sign in to comment.
You can’t perform that action at this time.