Skip to content

Commit

Permalink
Add more rules for phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
abrain committed Nov 2, 2024
1 parent 2f626ea commit 47057ff
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,12 @@
<rule ref="Universal.CodeAnalysis.StaticInFinalClass"/>
<rule ref="Universal.ControlStructures.DisallowLonelyIf"/>
<rule ref="Universal.Files.SeparateFunctionsFromOO"/>

<rule ref="WordPress.CodeAnalysis.EscapedNotTranslated"/>
<rule ref="WordPress.NamingConventions.ValidPostTypeSlug"/>

<rule ref="WordPress.PHP.DevelopmentFunctions"/>
<rule ref="WordPress.PHP.DiscouragedPHPFunctions"/>
<rule ref="WordPress.PHP.IniSet"/>
<rule ref="WordPress.PHP.PregQuoteDelimiter"/>
</ruleset>
9 changes: 6 additions & 3 deletions src/includes/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use abrain\Einsatzverwaltung\Util\Formatter;
use function add_action;
use function add_option;
use function error_log;
use function get_option;
use function plugin_basename;
use function plugin_dir_url;
Expand Down Expand Up @@ -107,7 +106,7 @@ private function __construct()
public function addHooks()
{
if (empty($this->pluginFile)) {
error_log('einsatzverwaltung: Plugin file has not been set via setPluginFile()');
wp_trigger_error(__FUNCTION__, 'Plugin file has not been set via setPluginFile()', E_USER_WARNING);

Check warning on line 109 in src/includes/Core.php

View check run for this annotation

Codecov / codecov/patch

src/includes/Core.php#L109

Added line #L109 was not covered by tests
return;
}

Expand Down Expand Up @@ -225,7 +224,11 @@ private function maybeUpdate()
$update = new Update();
$updateResult = $update->doUpdate($currentDbVersion, self::DB_VERSION);
if (is_wp_error($updateResult)) {
error_log("Das Datenbank-Upgrade wurde mit folgendem Fehler beendet: {$updateResult->get_error_message()}");
wp_trigger_error(
__FUNCTION__,
'The database upgrade was terminated with the following error: ' . $updateResult->get_error_message(),
E_USER_WARNING
);

Check warning on line 231 in src/includes/Core.php

View check run for this annotation

Codecov / codecov/patch

src/includes/Core.php#L227-L231

Added lines #L227 - L231 were not covered by tests
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/includes/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use function current_user_can;
use function defined;
use function delete_post_meta;
use function error_log;
use function filter_input;
use function get_post_meta;
use function get_post_type;
Expand Down Expand Up @@ -286,7 +285,7 @@ private function adjustPostDate(WP_Post $post)
$updateArgs['post_date_gmt'] = get_gmt_from_date($updateArgs['post_date']);
$updateResult = wp_update_post($updateArgs);
if (is_wp_error($updateResult)) {
error_log($updateResult->get_error_message());
wp_trigger_error(__FUNCTION__, 'Error updating post date: ' . $updateResult->get_error_message(), E_USER_WARNING);

Check warning on line 288 in src/includes/Data.php

View check run for this annotation

Codecov / codecov/patch

src/includes/Data.php#L288

Added line #L288 was not covered by tests
}

// Zwischenspeicher wird nur in der Entwurfsphase benötigt
Expand Down
6 changes: 3 additions & 3 deletions src/includes/Model/IncidentReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use abrain\Einsatzverwaltung\Types\Vehicle;
use abrain\Einsatzverwaltung\Utilities;
use DateTime;
use Exception;
use WP_Post;
use WP_Term;
use function array_filter;
Expand All @@ -15,7 +16,6 @@
use function array_map;
use function get_post;
use function get_post_type;
use function error_log;
use function get_the_terms;
use function in_array;
use function intval;
Expand All @@ -42,6 +42,7 @@ class IncidentReport
* IncidentReport constructor.
*
* @param int|WP_Post $post
* @throws Exception
*/
public function __construct($post = null)
{
Expand All @@ -50,8 +51,7 @@ public function __construct($post = null)
}

if (get_post_type($post) !== 'einsatz') {
error_log('The given post object is not an incident report'); // TODO throw exception
return;
throw new Exception('The given post object is not an incident report');

Check warning on line 54 in src/includes/Model/IncidentReport.php

View check run for this annotation

Codecov / codecov/patch

src/includes/Model/IncidentReport.php#L54

Added line #L54 was not covered by tests
}

$this->post = get_post($post);
Expand Down
2 changes: 1 addition & 1 deletion src/includes/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getOption(string $key)

// Fehlenden Standardwert beklagen, außer es handelt sich um eine Rechteeinstellung
if (strpos($key, 'einsatzvw_cap_roles_') !== 0) {
error_log(sprintf('Kein Standardwert für %s gefunden!', $key));
wp_trigger_error(__FUNCTION__, sprintf('Did not find default value for option %s', $key), E_USER_WARNING);

Check warning on line 38 in src/includes/Options.php

View check run for this annotation

Codecov / codecov/patch

src/includes/Options.php#L38

Added line #L38 was not covered by tests
}

return get_option($key, false);
Expand Down
5 changes: 2 additions & 3 deletions src/includes/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use function array_map;
use function delete_option;
use function delete_term_meta;
use function error_log;
use function function_exists;
use function get_editable_roles;
use function get_option;
Expand Down Expand Up @@ -159,7 +158,7 @@ private function upgrade054()
array('%d')
);
if (false === $result) {
error_log('Problem beim Aktualisieren des GMT-Datums bei Post-ID ' . $bericht->ID);
wp_trigger_error(__FUNCTION__, 'Problem beim Aktualisieren des GMT-Datums bei Post-ID ' . $bericht->ID);

Check warning on line 161 in src/includes/Update.php

View check run for this annotation

Codecov / codecov/patch

src/includes/Update.php#L161

Added line #L161 was not covered by tests
}
}

Expand Down Expand Up @@ -565,7 +564,7 @@ public function upgrade180()
foreach ($oldUnits as $oldUnit) {
$newUnit = wp_insert_term($oldUnit->post_title, 'evw_unit');
if (is_wp_error($newUnit)) {
error_log('Could not create term for Unit: ' . $newUnit->get_error_message());
wp_trigger_error(__FUNCTION__, 'Could not create term for Unit: ' . $newUnit->get_error_message());

Check warning on line 567 in src/includes/Update.php

View check run for this annotation

Codecov / codecov/patch

src/includes/Update.php#L567

Added line #L567 was not covered by tests
continue;
}
$termId = $newUnit['term_id'];
Expand Down

0 comments on commit 47057ff

Please sign in to comment.