Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused imports; Use str_starts_with() function #1681

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions commonsbooking.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/

use CommonsBooking\Plugin;

defined('ABSPATH') or die("Thanks for visiting");
define('COMMONSBOOKING_VERSION', '2.10.2');
define('COMMONSBOOKING_VERSION_COMMENT', ''); // Empty for release - Used to mark development versions
Expand Down
5 changes: 2 additions & 3 deletions includes/OptionsArray.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php


use CommonsBooking\Helper;
use CommonsBooking\Service\BookingRule;
use CommonsBooking\View\Migration;
use CommonsBooking\Helper\Wordpress;
Expand All @@ -15,11 +14,11 @@

// We need static types, because german month names don't work for datepicker
$dateFormat = 'd/m/Y';
if ( strpos( get_locale(), 'de_' ) !== false ) {
if ( str_starts_with( get_locale(), 'de_' ) ) {
$dateFormat = 'd.m.Y';
}

if ( strpos( get_locale(), 'en_' ) !== false ) {
if ( str_starts_with( get_locale(), 'en_' ) ) {
$dateFormat = 'm/d/Y';
}

Expand Down
5 changes: 0 additions & 5 deletions includes/Users.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<?php

use CommonsBooking\Plugin;
use CommonsBooking\Wordpress\CustomPostType\Booking;
use CommonsBooking\Wordpress\CustomPostType\CustomPostType;
use CommonsBooking\Wordpress\CustomPostType\Item;
use CommonsBooking\Wordpress\CustomPostType\Location;
use CommonsBooking\Wordpress\CustomPostType\Restriction;
use CommonsBooking\Wordpress\CustomPostType\Timeframe;


/**
Expand Down
1 change: 0 additions & 1 deletion src/API/GBFS/SystemInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace CommonsBooking\API\GBFS;

use Exception;
use stdClass;
use WP_REST_Response;

Expand Down
1 change: 0 additions & 1 deletion src/Map/MapFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace CommonsBooking\Map;

use DateTime;

class MapFilter {

Expand Down
1 change: 0 additions & 1 deletion src/Map/MapItemAvailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use CommonsBooking\View\Calendar;
use DateInterval;
use DatePeriod;
use DateTime;
use Exception;

class MapItemAvailable {
Expand Down
1 change: 0 additions & 1 deletion src/Messages/BookingReminderMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use CommonsBooking\Model\MessageRecipient;
use CommonsBooking\Repository\Booking;
use CommonsBooking\Service\Scheduler;
use CommonsBooking\Settings\Settings;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace CommonsBooking\Repository;

use CommonsBooking\Plugin;
use Exception;
use WP_Post;

abstract class PostRepository {
Expand Down
2 changes: 0 additions & 2 deletions src/View/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace CommonsBooking\View;

use CommonsBooking\CB\CB;
use CommonsBooking\Helper\Helper;
use CommonsBooking\Helper\Wordpress;
use CommonsBooking\Model\CustomPost;
Expand All @@ -14,7 +13,6 @@
use CommonsBooking\Wordpress\CustomPostType\Item;
use CommonsBooking\Wordpress\CustomPostType\Location;
use CommonsBooking\Wordpress\CustomPostType\Timeframe;
use DateInterval;
use DateTime;
use Exception;
use WP_Post;
Expand Down
1 change: 0 additions & 1 deletion src/View/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace CommonsBooking\View;

use CommonsBooking\Map\MapAdmin;
use CommonsBooking\Plugin;

/**
* The Map shortcode. Further logic is found in @see \CommonsBooking\Map\
Expand Down
6 changes: 2 additions & 4 deletions src/Wordpress/CustomPostType/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
namespace CommonsBooking\Wordpress\CustomPostType;

use CommonsBooking\Exception\BookingDeniedException;
use CommonsBooking\Exception\BookingRuleException;
use CommonsBooking\Exception\TimeframeInvalidException;
use CommonsBooking\Helper\Helper;
use CommonsBooking\Messages\BookingMessage;
use CommonsBooking\Service\BookingRuleApplied;
use CommonsBooking\Service\iCalendar;
use CommonsBooking\Settings\Settings;
use Exception;
use function wp_verify_nonce;

Expand Down Expand Up @@ -719,11 +717,11 @@ public function registerMetabox() {
protected function getCustomFields() {
// We need static types, because german month names dont't work for datepicker
$dateFormat = 'd/m/Y';
if ( strpos( get_locale(), 'de_' ) !== false ) {
if ( str_starts_with( get_locale(), 'de_' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das ist gedoppelter Code. Lässt sich das irgendwie sinnvoll auslagern?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich persönlich würde das nicht auslagern. Ist eine sehr einfache Operation und taucht auch nur 4 mal im Code auf. Bzw. 8 mal mit den Englischen Vorkommen.

$dateFormat = 'd.m.Y';
}

if ( strpos( get_locale(), 'en_' ) !== false ) {
if ( str_starts_with( get_locale(), 'en_' ) ) {
$dateFormat = 'm/d/Y';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Wordpress/CustomPostType/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,6 @@ public function registerMetabox() {
foreach ( $cmb->meta_box['fields'] as $metabox_field ) {
$metabox_fields[ $metabox_field['id'] ] = $metabox_field['name'];
}
Settings::updateOption( 'commonsbooking_settings_metaboxfields', $this->getPostType(), $metabox_fields );
Settings::updateOption( 'commonsbooking_settings_metaboxfields', static::getPostType(), $metabox_fields );
}
}
2 changes: 1 addition & 1 deletion src/Wordpress/CustomPostType/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public function registerMetabox() {
foreach ( $cmb->meta_box['fields'] as $metabox_field ) {
$metabox_fields[ $metabox_field['id'] ] = $metabox_field['name'];
}
Settings::updateOption( 'commonsbooking_settings_metaboxfields', $this->getPostType(), $metabox_fields );
Settings::updateOption( 'commonsbooking_settings_metaboxfields', static::getPostType(), $metabox_fields );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Wordpress/CustomPostType/Restriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,11 @@ public function registerMetabox() {
protected function getCustomFields(): array {
// We need static types, because german month names dont't work for datepicker
$dateFormat = 'd/m/Y';
if ( strpos( get_locale(), 'de_' ) !== false ) {
if ( str_starts_with( get_locale(), 'de_' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gleiche Codedopplung, s.o.

$dateFormat = 'd.m.Y';
}

if ( strpos( get_locale(), 'en_' ) !== false ) {
if ( str_starts_with( get_locale(), 'en_' ) ) {
$dateFormat = 'm/d/Y';
}

Expand Down
8 changes: 3 additions & 5 deletions src/Wordpress/CustomPostType/Timeframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use CommonsBooking\Model\BookingCode;
use WP_Post;
use Exception;
use CommonsBooking\CB\CB;
use CommonsBooking\View\Calendar;
use CommonsBooking\View\Admin\Filter;
use CommonsBooking\Repository\BookingCodes;
Expand Down Expand Up @@ -308,6 +307,7 @@ public static function addAdminLocationFilter() {

/**
* Adds filter dropdown // filter by location in booking list
*
*/
public static function addAdminStatusFilter() {
$values = [];
Expand Down Expand Up @@ -475,11 +475,11 @@ public function registerMetabox() {
protected function getCustomFields() {
// We need static types, because german month names dont't work for datepicker
$dateFormat = 'd/m/Y';
if ( strpos( get_locale(), 'de_' ) !== false ) {
if ( str_starts_with( get_locale(), 'de_' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s.o.

$dateFormat = 'd.m.Y';
}

if ( strpos( get_locale(), 'en_' ) !== false ) {
if ( str_starts_with( get_locale(), 'en_' ) ) {
$dateFormat = 'm/d/Y';
}

Expand Down Expand Up @@ -1410,15 +1410,13 @@ public function initHooks() {
// Add custom cmb2 type for email booking codes by cron
add_action( 'cmb2_render_booking_codes_email_fields', [ '\CommonsBooking\View\BookingCodes','renderCronEmailFields' ], 10, 5 );
add_action( 'cmb2_save_field_' . \CommonsBooking\View\BookingCodes::CRON_EMAIL_CODES, [ '\CommonsBooking\View\BookingCodes','cronEmailCodesSaved' ], 10, 3 );

// Add Meta Boxes
add_action( 'cmb2_admin_init', array( $this, 'registerMetabox' ) );

// must be 'save_post' only because of priority in relation to cmb2
add_action( 'save_post', array( $this, 'savePost' ), 11, 2 );

add_action( 'updated_post_meta', array( $this, 'updatedPostMeta' ), 11, 4 );

// Add type filter to backend list view
add_action( 'restrict_manage_posts', array( self::class, 'addAdminTypeFilter' ) );
add_action( 'restrict_manage_posts', array( self::class, 'addAdminItemFilter' ) );
Expand Down
4 changes: 1 addition & 3 deletions src/Wordpress/Options/OptionsTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace CommonsBooking\Wordpress\Options;

use CommonsBooking\Messages\AdminMessage;
use CommonsBooking\Plugin;
use CommonsBooking\View\TimeframeExport;
use Exception;

/**
Expand Down Expand Up @@ -81,7 +79,7 @@ public function registerOptionsTab() {
public function registerOptionsGroups() {

foreach ( $this->groups as $group ) {
$group = $this->prependTitle( $group ); /* prepend title + description html */
$group = static::prependTitle( $group ); /* prepend title + description html */

// Add Fields
$fields = $group['fields'];
Expand Down
2 changes: 0 additions & 2 deletions templates/timeframe-withlocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*/


use CommonsBooking\Settings\Settings;

$button_label = \CommonsBooking\Settings\Settings::getOption( COMMONSBOOKING_PLUGIN_SLUG . '_options_templates', 'label-booking-button' );
$permalink = add_query_arg( 'cb-location', $location->ID, get_the_permalink( $item->ID ) ); // booking link set to item detail page with location ID
?>
Expand Down
1 change: 0 additions & 1 deletion tests/php/API/GBFS/StationStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace CommonsBooking\Tests\API\GBFS;

use CommonsBooking\API\GBFS\StationStatus;
use CommonsBooking\Model\Day;
use CommonsBooking\Model\Location;
use CommonsBooking\Tests\Wordpress\CustomPostTypeTest;
use SlopeIt\ClockMock\ClockMock;
Expand Down
7 changes: 2 additions & 5 deletions tests/php/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
namespace CommonsBooking\Tests;

use CommonsBooking\Model\CustomPost;
use CommonsBooking\Model\Timeframe;
use CommonsBooking\Plugin;
use CommonsBooking\Tests\Wordpress\CustomPostTypeTest;
use CommonsBooking\Wordpress\CustomPostType\CustomPostType;
use SlopeIt\ClockMock\ClockMock;

class PluginTest extends CustomPostTypeTest
{

private $postIDs = [];
public function testGetCustomPostTypes()
{
$plugin = new Plugin();
$this->assertIsArray($plugin->getCustomPostTypes());
$this->assertIsArray(Plugin::getCustomPostTypes());
//make sure, that we also have a model for each custom post type
foreach ($plugin->getCustomPostTypes() as $customPostType){
foreach (Plugin::getCustomPostTypes() as $customPostType){
//first, create a post of this type
$post = wp_insert_post([
'post_type' => $customPostType::getPostType(),
Expand Down
3 changes: 1 addition & 2 deletions tests/php/Service/BookingCodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use CommonsBooking\Model\Timeframe;
use CommonsBooking\Tests\Wordpress\CustomPostTypeTest;
use CommonsBooking\Settings\Settings;
use CommonsBooking\CB\CB;


/**
Expand Down Expand Up @@ -77,7 +76,7 @@ public function testGetCronParams() {

protected function deleteCBOptions() {
foreach ( wp_load_alloptions() as $option => $value ) {
if ( strpos( $option, COMMONSBOOKING_PLUGIN_SLUG . '_options' ) === 0 ) {
if ( str_starts_with( $option, COMMONSBOOKING_PLUGIN_SLUG . '_options' ) ) {
delete_option( $option );
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Service/TimeframeExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testCron() {
$this->assertFileIsReadable($testFile);
$content = file_get_contents($testFile);
$this->assertNotEmpty($content);
$objects = $this->csvStringToStdObjects($content);
$objects = static::csvStringToStdObjects($content);
$this->assertEquals(1, count($objects));
$exportedBooking = reset($objects);
$this->assertEquals($this->booking->ID, $exportedBooking->ID);
Expand All @@ -146,7 +146,7 @@ public function testGetCSV()
);
$export->getExportData();
$csv = $export->getCSV();
$objects = $this->csvStringToStdObjects($csv);
$objects = static::csvStringToStdObjects($csv);
$this->assertEquals(1, count($objects));
$exportedBooking = reset($objects);
$this->assertEquals($this->booking->ID, $exportedBooking->ID);
Expand Down
2 changes: 1 addition & 1 deletion tests/php/View/BookingCodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function on_wp_redirect($location, $status){

protected function deleteCBOptions() {
foreach ( wp_load_alloptions() as $option => $value ) {
if ( strpos( $option, COMMONSBOOKING_PLUGIN_SLUG . '_options' ) === 0 ) {
if ( str_starts_with( $option, COMMONSBOOKING_PLUGIN_SLUG . '_options' ) ) {
delete_option( $option );
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/php/View/BookingTest_AJAX_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace CommonsBooking\Tests\View;

use CommonsBooking\Service\TimeframeExport;
use CommonsBooking\Settings\Settings;
use CommonsBooking\Tests\Wordpress\CustomPostTypeTest;
use CommonsBooking\Wordpress\CustomPostType\Timeframe;
Expand All @@ -28,7 +27,7 @@ public function testGetBookingCode_AJAX() {
// Save timeframe post to trigger booking code generation.
// It is necessary to generate here after time has been frozen to CustomPostTypeTest::CURRENT_DATE
// because the code generation depends on the current date and codes are not generated for the past.
// (CustomPostTypeTest::CURRENT_DATE is a date in the past)
// (CustomPostTypeTest::CURRENT_DATE is a date in the past)
$timeframeCPT = new Timeframe();
$timeframeCPT->savePost( $this->timeframeID, get_post($this->timeframeID) );

Expand Down
Loading