Skip to content
Permalink
Browse files

Fix some more static analyzer findings

  • Loading branch information...
flack committed Sep 11, 2019
1 parent da2115a commit dd0feb7ba08763d21b465ba0a60c3facb5673f8e
Showing with 46 additions and 62 deletions.
  1. +1 −1 lib/fi/protie/navigation/main.php
  2. +1 −1 lib/midcom/admin/folder/handler/edit.php
  3. +2 −3 lib/midcom/admin/help/help.php
  4. +1 −1 lib/midcom/baseclasses/components/handler/rest.php
  5. +1 −1 lib/midcom/core/manifest.php
  6. +1 −4 lib/midcom/db/person.php
  7. +1 −1 lib/midcom/helper/exporter.php
  8. +2 −3 lib/midcom/helper/imagefilter.php
  9. +1 −2 lib/midcom/helper/nav/main.php
  10. +2 −2 lib/midcom/helper/reflector/tree.php
  11. +1 −1 lib/midcom/services/toolbars.php
  12. +1 −2 lib/midgard/admin/asgard/handler/object/manage.php
  13. +1 −2 lib/midgard/admin/asgard/handler/object/permissions.php
  14. +1 −1 lib/midgard/admin/asgard/style/midgard_admin_asgard_object_attachments_file.php
  15. +2 −3 lib/net/nehmer/blog/handler/index.php
  16. +1 −1 lib/net/nehmer/comments/handler/moderate.php
  17. +2 −3 lib/net/nemein/tag/handler.php
  18. +1 −2 lib/org/openpsa/calendar/event/member.php
  19. +1 −2 lib/org/openpsa/contacts/group.php
  20. +1 −1 lib/org/openpsa/directmarketing/campaign.php
  21. +1 −1 lib/org/openpsa/directmarketing/campaign/ruleresolver.php
  22. +1 −1 lib/org/openpsa/directmarketing/handler/import.php
  23. +2 −2 lib/org/openpsa/documents/document.php
  24. +1 −1 lib/org/openpsa/expenses/style/hours_grid.php
  25. +2 −2 lib/org/openpsa/invoices/billing/data.php
  26. +1 −1 lib/org/openpsa/products/handler/list.php
  27. +1 −1 lib/org/openpsa/projects/task.php
  28. +1 −2 lib/org/openpsa/relatedto/handler/relatedto.php
  29. +1 −1 lib/org/openpsa/reports/handler/base.php
  30. +1 −1 lib/org/openpsa/sales/salesproject.php
  31. +2 −2 lib/org/openpsa/sales/style/show-salesproject-deliverables-grid.php
  32. +1 −1 src/midcom/datamanager/extension/transformer/imageTransformer.php
  33. +1 −2 src/midcom/datamanager/extension/transformer/multipleTransformer.php
  34. +1 −3 src/midcom/datamanager/indexer/document.php
  35. +1 −1 src/midcom/datamanager/storage/parameter.php
  36. +1 −1 src/midcom/datamanager/template/form.php
  37. +1 −1 src/midcom/routing/loader.php
  38. +1 −1 src/midcom/routing/resolver.php
@@ -340,7 +340,7 @@ private function _display_element($item, $css_classes)
{
// Finalize the class naming
$class = ($css_classes !== '') ? ' class="' . $css_classes . '"' : '';
$link_class = ($this->css_link) ? ' class="' . $this->css_link . '"' : '';
$link_class = $this->css_link ? ' class="' . $this->css_link . '"' : '';
echo "<li{$class}>";
echo "<a href=\"{$item[MIDCOM_NAV_ABSOLUTEURL]}\"{$link_class}>{$item[MIDCOM_NAV_NAME]}</a>";
@@ -54,7 +54,7 @@ private function _load_controller()
foreach ($schemadb->all() as $schema) {
if ($schema->has_field('name')) {
$schema->get_field('name')['required'] = ($this->_handler_id === 'edit');
$schema->get_field('name')['required'] = $this->_handler_id === 'edit';
}
}
$defaults = [];
@@ -325,7 +325,7 @@ private function _list_components()
$this->_request_data['libraries'] = [];
foreach (midcom::get()->componentloader->manifests as $name => $manifest) {
$type = ($manifest->purecode) ? 'libraries' : 'components';
$type = $manifest->purecode ? 'libraries' : 'components';
$component_array = $this->_load_component_data($name);
@@ -340,8 +340,7 @@ private function _prepare_breadcrumb($handler_id)
{
$this->add_breadcrumb($this->router->generate('welcome'), $this->_l10n->get('midcom.admin.help'));
if ( $handler_id == 'help'
|| $handler_id == 'component') {
if (in_array($handler_id, ['help', 'component'])) {
$this->add_breadcrumb(
$this->router->generate('component', ['component' => $this->_request_data['component']]),
sprintf($this->_l10n->get('help for %s'), midcom::get()->i18n->get_string($this->_request_data['component'], $this->_request_data['component']))
@@ -187,7 +187,7 @@ protected function _process_request()
$this->handle_get();
}
// post and put might be used for create/update
if ($this->_request['method'] == 'post' || $this->_request['method'] == 'put') {
if (in_array($this->_request['method'], ['post', 'put'])) {
if ($this->_id) {
$this->_mode = 'update';
$this->handle_update();
@@ -290,7 +290,7 @@ public function __construct($filename)
$this->$field = $value;
}
}
$this->purecode = ($this->purecode == true);
$this->purecode = (bool) $this->purecode;
if (!empty($this->privileges)) {
$this->_process_privileges();
@@ -95,10 +95,7 @@ public function __set($property, $value)
{
parent::__set($property, $value);
if ( $property == 'firstname'
|| $property == 'lastname'
|| $property == 'homepage'
|| $property == 'email') {
if (in_array($property, ['firstname', 'lastname', 'homepage', 'email'])) {
$this->_update_computed_members();
}
}
@@ -65,7 +65,7 @@ public function array2object(array $data, midcom_core_dbaobject $object)
}
// skip read_only fields
if ($field_name == 'guid' || $field_name == 'id') {
if (in_array($field_name, ['guid', 'id'])) {
continue;
}
@@ -130,7 +130,7 @@ public static function imagemagick_available()
$output = [];
$ret = null;
exec($convert_cmd, $output, $ret);
$return = ($ret === 0 || $ret === 1);
$return = in_array($ret, [0, 1], true);
if (!$return) {
debug_add("ImageMagick, '{$convert_cmd}' (part of ImageMagick suite) returned failure", MIDCOM_LOG_ERROR);
}
@@ -470,8 +470,7 @@ public function rotate($rotate = 0)
while ($rotate > 360) {
$rotate -= 360;
}
if ( $rotate == 0
|| $rotate == 360) {
if (in_array($rotate, [0, 360])) {
debug_add("Rotate is {$rotate}, we're happy as-is.");
return;
}
@@ -217,8 +217,7 @@ public function is_node_in_tree($node_id, $root_id)
if ($uplink == $root_id) {
return true;
}
if ( $uplink == false
|| $uplink == -1) {
if (in_array($uplink, [false, -1])) {
return false;
}
return $this->is_node_in_tree($uplink, $root_id);
@@ -428,7 +428,7 @@ private function _resolve_child_classes_links_back($property, $prospect_type, $s
&& $ref->get_midgard_type($property) === MGD_TYPE_GUID) {
return true;
}
return midcom_helper_reflector::is_same_class($link_class, $schema_type);
return self::is_same_class($link_class, $schema_type);
}
/**
@@ -462,7 +462,7 @@ private static function _resolve_root_classes()
$types = array_diff(midcom_connection::get_schema_types(), $root_exceptions_notroot);
foreach ($types as $schema_type) {
// Class extensions mapping
$schema_type = midcom_helper_reflector::class_rewrite($schema_type);
$schema_type = self::class_rewrite($schema_type);
// Make sure we only add classes once
if (in_array($schema_type, $root_classes)) {
@@ -368,7 +368,7 @@ public function show()
$toolbar_style = "";
$toolbar_class = "midcom_services_toolbars_simple";
if (midcom::get()->auth->can_user_do('midcom:ajax', null, midcom_services_toolbars::class)) {
if (midcom::get()->auth->can_user_do('midcom:ajax', null, __CLASS__)) {
$enable_drag = true;
$toolbar_class = "midcom_services_toolbars_fancy";
$toolbar_style = "display: none;";
@@ -214,8 +214,7 @@ public function _handler_create(Request $request, $handler_id, array $args, arra
}
$this->_new_object = new $create_type();
if ( $handler_id == 'object_create_toplevel'
|| $handler_id == 'object_create_chooser') {
if (in_array($handler_id, ['object_create_toplevel', 'object_create_chooser'])) {
midcom::get()->auth->require_user_do('midgard:create', null, $create_type);
$data['view_title'] = sprintf($this->_l10n_midcom->get('create %s'), midgard_admin_asgard_plugin::get_type_label($data['current_type']));
@@ -185,8 +185,7 @@ private function process_assignees(array $assignees, schemadb $schemadb)
}
foreach ($this->_privileges as $privilege) {
$privilege_components = explode(':', $privilege);
if ( $privilege_components[0] == 'midcom'
|| $privilege_components[0] == 'midgard') {
if (in_array($privilege_components[0], ['midcom', 'midgard'])) {
// This is one of the core privileges, we handle it
$privilege_label = $privilege;
} else {
@@ -42,7 +42,7 @@
<?php
$file_url = midcom::get()->permalinks->create_attachment_link($data['file']->guid, $data['file']->name);
if (!empty($data['file']->name)) {
$ext = pathinfo($data['file']->name, PATHINFO_EXTENSION);;
$ext = pathinfo($data['file']->name, PATHINFO_EXTENSION);
$mime_icon = '<i class="fa fa-file-o"></i><span class="extension">' . $ext . '</span>';
} else {
$mime_icon = '<span class="icon no-file"><i class="fa fa-file-o"></i></span>';
@@ -49,16 +49,15 @@ public function _handler_index($handler_id, array $args, array &$data)
$data['page_title'] = $this->_topic->extra;
// Filter by categories
if ( $handler_id == 'index-category'
|| $handler_id == 'latest-category') {
if (in_array($handler_id, ['index-category', 'latest-category'])) {
$data['category'] = trim(strip_tags($args[0]));
$this->_process_category_constraint($qb);
}
$qb->add_order('metadata.published', 'DESC');
if ($handler_id == 'latest' || $handler_id == 'ajax-latest') {
if (in_array($handler_id, ['latest', 'ajax-latest'])) {
$qb->results_per_page = $args[0];
} elseif ($handler_id == 'latest-category') {
$qb->results_per_page = $args[1];
@@ -110,7 +110,7 @@ private function load_comment($identifier, $require_moderation_privilege = true)
$this->_comment = new net_nehmer_comments_comment($identifier);
if (!$this->_comment->can_do('midgard:update')) {
$this->_comment->_sudo_requested = midcom::get()->auth->request_sudo('net.nehmer.comments');;
$this->_comment->_sudo_requested = midcom::get()->auth->request_sudo('net.nehmer.comments');
}
if ($require_moderation_privilege) {
$this->_comment->require_do('net.nehmer.comments:moderation');
@@ -29,7 +29,7 @@ public static function tag_object($object, $tags, $component = null)
if ($component === null) {
$component = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_COMPONENT);
}
$existing_tags = net_nemein_tag_handler::get_object_tags($object);
$existing_tags = self::get_object_tags($object);
// Determine operations
$add_tags = [];
@@ -499,8 +499,7 @@ public static function string2tag_array($from_string)
$quote_open = false;
continue;
}
if ( $char === '"'
|| $char === "'") {
if (in_array($char, ['"', "'"], true)) {
$quote_open = $char;
continue;
}
@@ -113,8 +113,7 @@ public function notify($type, org_openpsa_calendar_event_dba $event = null, $nl
return false;
}
if ( $type == 'cancel'
|| $type == 'remove') {
if (in_array($type, ['cancel', 'remove'])) {
// TODO: Create iCal export with correct delete commands
} else {
$encoder = new org_openpsa_calendar_vcal;
@@ -97,8 +97,7 @@ private function _get_address_extra($property)
public function __get($property)
{
if ( $property == 'invoice_label'
|| $property == 'postal_label') {
if (in_array($property, ['invoice_label', 'postal_label'])) {
if (!isset($this->_address_extras[$property])) {
$this->_get_address_extra($property);
}
@@ -86,7 +86,7 @@ public function get_testers()
private function _unserialize_rules()
{
$unserRet = @json_decode($this->rulesSerialized, true);
if ($unserRet === false || $unserRet === null) {
if (in_array($unserRet, [false, null], true)) {
debug_add('Failed to unserialize rulesSerialized', MIDCOM_LOG_WARN);
$this->rules = [];
return;
@@ -260,7 +260,7 @@ private function add_parameter_rule(array $rules)
if (count($parameter_keys) < 1) {
//TODO: better solution for constraints leading to zero results
//build constraint only if on 'LIKE' or '=' should be matched
if ($rule['match'] == 'LIKE' || $rule['match'] == '=') {
if (in_array($rule['match'], ['LIKE', '='])) {
return $this->mc->add_constraint('id', '=', -1);
}
return true;
@@ -53,7 +53,7 @@ private function _prepare_handler($guid)
'campaign_member' => schemadb::from_path($this->_config->get('schemadb_campaign_member')),
'organization' => schemadb::from_path($this->_config->get('schemadb_organization')),
'organization_member' => schemadb::from_path($this->_config->get('schemadb_organization_member')),
];;
];
$this->add_stylesheet(MIDCOM_STATIC_URL . "/midcom.datamanager/default.css");
midcom::get()->disable_limits();
@@ -30,7 +30,7 @@ class org_openpsa_documents_document_dba extends midcom_core_dbaobject
public $__mgdschema_class_name__ = 'org_openpsa_document';
public $autodelete_dependents = [
org_openpsa_documents_document_dba::class => 'nextVersion'
self::class => 'nextVersion'
];
const STATUS_DRAFT = 4000;
@@ -44,7 +44,7 @@ public function _on_loaded()
}
if (!$this->docStatus) {
$this->docStatus = org_openpsa_documents_document_dba::STATUS_DRAFT;
$this->docStatus = self::STATUS_DRAFT;
}
}
@@ -109,7 +109,7 @@
?>
<h1>&(data['view_title']);</h1>
<?php
if ($data['mode'] == 'full' || $data['mode'] == 'project') {
if (in_array($data['mode'], ['full', 'project'])) {
midcom_show_style('hours_filters');
}
?>
@@ -63,7 +63,7 @@ public static function get_by_object(org_openpsa_invoices_interfaces_customer $o
if ( !($bd = self::get_billing_data(org_openpsa_contacts_group_dba::class, $object->customer))
// check if the customerContact is set and has invoice_data
&& !($bd = self::get_billing_data(org_openpsa_contacts_person_dba::class, $object->customerContact))) {
$bd = new org_openpsa_invoices_billing_data_dba();
$bd = new self();
$due = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('default_due_days');
$vat = explode(',', midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('vat_percentages'));
@@ -86,7 +86,7 @@ private static function get_billing_data($dba_class, $contact_id)
}
try {
$contact = call_user_func([$dba_class, 'get_cached'], $contact_id);
$qb = org_openpsa_invoices_billing_data_dba::new_query_builder();
$qb = self::new_query_builder();
$qb->add_constraint('linkGuid', '=', $contact->guid);
$billing_data = $qb->execute();
if (empty($billing_data)) {
@@ -82,7 +82,7 @@ public function get_qb($field = null, $direction = 'ASC', array $search = [])
}
foreach ($search as $key => $value) {
if ($key === 'code' || $key === 'title') {
if (in_array($key, ['code', 'title'], true)) {
$qb->add_constraint($key, 'LIKE', $value . '%');
} else {
$qb->add_constraint($key, '=', $value);
@@ -92,7 +92,7 @@ public function __get($property)
if ($property == 'status_type') {
return org_openpsa_projects_workflow::get_status_type($this->status);
}
if ($property == 'status_comment' || $property == 'status_time') {
if (in_array($property, ['status_comment', 'status_time'])) {
if ($this->_status === null) {
$this->_status = $this->_get_status();
}
@@ -409,8 +409,7 @@ public static function render_line_controls(array $link, $other_obj)
{
echo "<ul class=\"relatedto_toolbar\" data-link-guid=\"{$link['guid']}\" data-other-guid=\"{$other_obj->guid}\">\n";
if ( $link['component'] == 'net.nemein.wiki'
|| $link['component'] == 'org.openpsa.calendar') {
if (in_array($link['component'], ['net.nemein.wiki', 'org.openpsa.calendar'])) {
echo "<li><input type=\"button\" class=\"button info\" value=\"" . midcom::get()->i18n->get_string('details', 'org.openpsa.relatedto') . "\" /></li>\n";
}
@@ -118,7 +118,7 @@ public function _handler_query_form(Request $request, array $args, array &$data)
protected function _generator_load_redirect(&$args)
{
$this->_request_data['query'] = new org_openpsa_reports_query_dba($args[0]);;
$this->_request_data['query'] = new org_openpsa_reports_query_dba($args[0]);
if (empty($args[1])) {
debug_add('Filename part not specified in URL, generating');
@@ -131,7 +131,7 @@ public static function generate_salesproject_number()
{
// TODO: Make configurable
$year = date('Y');
$qb = org_openpsa_sales_salesproject_dba::new_query_builder();
$qb = self::new_query_builder();
$qb->add_order('metadata.created', 'DESC');
$qb->add_constraint('metadata.created', '>=', $year . '-01-01 00:00:00');
$previous = $qb->count_unchecked();
@@ -22,9 +22,9 @@
$classes = $data['state'];
if ($data['state'] == 'declined') {
$classes .= ' bad';
} elseif ($data['state'] == 'started' || $data['state'] == 'invoiced') {
} elseif (in_array($data['state'], ['started', 'invoiced'])) {
$classes .= ' good';
} elseif ($data['state'] == 'delivered' || $data['state'] == 'ordered') {
} elseif (in_array($data['state'], ['delivered', 'ordered'])) {
$classes .= ' normal';
}
@@ -20,7 +20,7 @@ public function transform($input)
$result = ['objects' => []];
foreach ($input as $key => $value) {
if ($key === 'delete' || $key === 'description' || $key == 'title' || $key == 'score') {
if (in_array($key, ['delete', 'description', 'title', 'score'])) {
$result[$key] = $value;
} else {
$result['objects'][$key] = parent::transform($value);
@@ -41,8 +41,7 @@ public function __construct(array $config)
public function transform($input)
{
if ( $input === false
|| $input === null) {
if (in_array($input, [false, null], true)) {
return [];
}
@@ -256,9 +256,7 @@ private function add_as_date_field(FormView $field)
*/
private function resolve_auto_method($name)
{
if ( $name == 'abstract'
|| $name == 'title'
|| $name == 'author') {
if (in_array($name, ['abstract', 'title', 'author'])) {
return $name;
}
return 'content';
@@ -31,7 +31,7 @@ public function save()
{
// workaround for weird mgd API behavior where setting empty (i.e. deleting) a
// nonexistent parameter returns false
if ( ($this->value === false || $this->value === null || $this->value === "")
if ( in_array($this->value, [false, null, ""], true)
&& $this->load() === null) {
return true;
}

0 comments on commit dd0feb7

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