diff --git a/src/API/AvailabilityRoute.php b/src/API/AvailabilityRoute.php index 4ab33c780..7c25b8fab 100644 --- a/src/API/AvailabilityRoute.php +++ b/src/API/AvailabilityRoute.php @@ -3,23 +3,21 @@ namespace CommonsBooking\API; -use CommonsBooking\Helper\Wordpress; use CommonsBooking\Model\Calendar; use CommonsBooking\Model\Day; -use CommonsBooking\Model\Timeframe; -use CommonsBooking\Model\Week; use CommonsBooking\Repository\Item; -use DateTime; -use DateTimeZone; use Exception; use stdClass; use WP_Error; +use WP_REST_Request; use WP_REST_Response; /** * Endpoint exposes item availability * - * @See Calendar for computing item availability + * @see Calendar for computing item availability. + * + * @see JSON-schema-Specification {@see https://github.com/wielebenwir/commons-api/blob/master/commons-api.availability.schema.json} */ class AvailabilityRoute extends BaseRoute { @@ -40,9 +38,7 @@ class AvailabilityRoute extends BaseRoute { /** * This retrieves bookable timeframes and the different items assigned, with their respective availability. * - * @param bool $id The id of a \CommonsBooking\Wordpress\CustomPostType\Item::post_type post to search for - * @param null $startTime The start date of the calendar to get the data for - * @param null $endTime The end date of the calendar to get the data for + * @param bool $id The id of a {@see \CommonsBooking\Wordpress\CustomPostType\Item::post_type} post to search for * * @return array * @throws Exception @@ -60,6 +56,10 @@ public function getItemData( $id = false ): array { /** * Get one item from the collection + * + * @param $request WP_REST_Request + * + * @return WP_REST_Response|WP_Error */ public function get_item( $request ) { //get parameters from request @@ -72,7 +72,9 @@ public function get_item( $request ) { if ( count( $data->availability ) ) { return new WP_REST_Response( $data, 200 ); } else { - + // This was missing in previous versions. According to the availability spec, we can return a list with no items + // TODO this part and the enclosing if-clause can be removed in future version, if no problems arose ... + return new WP_REST_Response( $data, 200 ); } } catch (Exception $e) { return new WP_Error( 'code', $e->getMessage() ); @@ -83,7 +85,7 @@ public function get_item( $request ) { /** * Get a collection of items * - * @param $request Full data about the request. + * @param $request WP_REST_Request full data about the request. * * @return WP_REST_Response */ diff --git a/src/CB/CB1UserFields.php b/src/CB/CB1UserFields.php index 57dfa996e..a83eaa792 100644 --- a/src/CB/CB1UserFields.php +++ b/src/CB/CB1UserFields.php @@ -10,6 +10,31 @@ class CB1UserFields { + /** + * @var false|mixed + */ + private mixed $termsservices_url; + /** + * @var array|string[] + */ + private array $registration_fields; + /** + * @var array|array[] + */ + private array $extra_profile_fields; + /** + * @var array|string[] + */ + private array $registration_fields_required; + /** + * @var array|array[] + */ + private array $user_fields; + /** + * @var array|mixed + */ + private mixed $user_vars; + public function __construct() { // Registration: Form fields diff --git a/src/Exception/TimeframeInvalidException.php b/src/Exception/TimeframeInvalidException.php index 1955f294b..fdddbb73f 100644 --- a/src/Exception/TimeframeInvalidException.php +++ b/src/Exception/TimeframeInvalidException.php @@ -6,7 +6,7 @@ class TimeframeInvalidException extends \Exception { - public function __construct( $message = "", $code = 0, Throwable $previous = null ) { + public function __construct( $message = "", $code = 0, \Throwable $previous = null ) { //get immediate caller if ( debug_backtrace()[1]['class'] == Booking::class ) { $message .= " " . __( "Booking is saved as draft.", 'commonsbooking' ); diff --git a/src/Map/BaseShortcode.php b/src/Map/BaseShortcode.php index 21fa54817..bf8c8a99d 100644 --- a/src/Map/BaseShortcode.php +++ b/src/Map/BaseShortcode.php @@ -9,6 +9,8 @@ */ abstract class BaseShortcode { + final public function __construct() { } + /** * The shortcode handler - load all the needed assets and render the map container * diff --git a/src/Model/CustomPost.php b/src/Model/CustomPost.php index f7b8cc523..9cf48f263 100644 --- a/src/Model/CustomPost.php +++ b/src/Model/CustomPost.php @@ -11,7 +11,15 @@ * Pseudo extends WP_Post class. * * All the public methods are available as template tags. + * * In using magic methods you can retrieve data from model objects, when the model object class derive from this class. + * * All the public methods are available as template tags. + * * @package CommonsBooking\Model + * + * @property int $post_author identifier of the WordPress user. + * @property int $post_status describes whether the post is published. + * @property int $ID of the WordPress post. + * @property string $post_title */ class CustomPost { /** @@ -27,9 +35,9 @@ class CustomPost { /** * CustomPost constructor. * - * @param int|WP_Post $post + * @param int|WP_Post $post uses either int as id reference or the post object * - * @throws Exception + * @throws Exception when $post param does not reference a valid post object */ public function __construct( $post ) { if ( $post instanceof WP_Post ) { @@ -37,7 +45,7 @@ public function __construct( $post ) { } elseif ( is_int( $post ) ) { $this->post = get_post( $post ); } else { - throw new Exception( "Invalid post param. Needed WP_Post or ID (int)" ); + throw new Exception( 'Invalid post param. Needed WP_Post or ID (int)' ); } } @@ -87,6 +95,15 @@ public function __get( $name ) { } } + /** + * Enables that we can call methods of \CustomPost as template tags. + * + * @param string $name of the member function + * @param array $arguments given to the template tag. + * + * @return array|mixed|void + * @throws \ReflectionException if called template tag is not a registered method + */ public function __call( $name, $arguments ) { if ( method_exists( $this->post, $name ) ) { $reflectionMethod = new ReflectionMethod( $this->post, $name ); diff --git a/src/Model/Timeframe.php b/src/Model/Timeframe.php index e5fbb8b76..80ecc5e4a 100644 --- a/src/Model/Timeframe.php +++ b/src/Model/Timeframe.php @@ -222,7 +222,7 @@ public function getLatestPossibleBookingDateTimestamp() { $calculationBase = time(); // if meta-value not set we define a default value far in the future so that we count all possibly relevant timeframes - $advanceBookingDays = $this->getMeta( TimeFrame::META_TIMEFRAME_ADVANCE_BOOKING_DAYS ) ?: 365; + $advanceBookingDays = $this->getMeta( Timeframe::META_TIMEFRAME_ADVANCE_BOOKING_DAYS ) ?: 365; // we subtract one day to reflect the current day in calculation $advanceBookingDays --; diff --git a/src/Plugin.php b/src/Plugin.php index 9055b64a0..cce754a50 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -29,6 +29,10 @@ use CommonsBooking\Wordpress\Options\OptionsTab; use CommonsBooking\Wordpress\PostStatus\PostStatus; +/** + * @since 2.10 removed saveOptionsActions, the transient commonsbooking_options_saved which is used in + * Plugin::admin_init is set in OptionsTab class + */ class Plugin { use Cache; @@ -513,15 +517,6 @@ public static function maybeEnableCB1UserFields() { } } - /** - * run actions after plugin options are saved - * TODOD: @markus-mw I think this function is deprecated now. Would you please check this? It is only referenced by an inactive hook - */ - public static function saveOptionsActions() { - // Run actions after options update - set_transient( 'commonsbooking_options_saved', 1 ); - } - /** * Register Admin-Options */ diff --git a/src/Repository/BookingCodes.php b/src/Repository/BookingCodes.php index cbb9e9741..ba21470b6 100644 --- a/src/Repository/BookingCodes.php +++ b/src/Repository/BookingCodes.php @@ -129,14 +129,16 @@ public static function getCodes( int $timeframeId, int $startDate = null, int $e /** * Filter an array of BookingCode|s such that it contains only one BookingCode per date. + * Works by reference on the variable. + * * Function is only needed when new cb version handles database entries created by old cb version. * The filtering can be omitted in future cb versions when backward compatibility with old cb is dropped. * - * @param $bookingCodes[] array of BookingCode|s. It is assumed that they all have the same itemId. + * @param array &$bookingCodes reference of array of BookingCode|s. It is assumed that they all have the same itemId. * @param int $preferredTimeframeId timeframeId to prefer when filtering * @param int $preferredLocationId locationId to prefer when filtering * - * @return $bookingCodes[] array of BookingCode|s (only one code per day) + * @return void works by reference on param $bookingCodes */ private static function backwardCompatibilityFilter(&$bookingCodes, $preferredTimeframeId, $preferredLocationId) { $filteredCodes = []; diff --git a/src/Repository/CB1.php b/src/Repository/CB1.php index ae80fb3c2..3eb2f402c 100644 --- a/src/Repository/CB1.php +++ b/src/Repository/CB1.php @@ -243,6 +243,8 @@ public static function getCB2PostIdByCB1Id( $id ): ?int { if ( $result && count( $result ) > 0 ) { return $result[0]->cb2_id; } + + return null; } /** diff --git a/src/Service/BookingRule.php b/src/Service/BookingRule.php index 2ebc69600..7ff167443 100644 --- a/src/Service/BookingRule.php +++ b/src/Service/BookingRule.php @@ -697,7 +697,8 @@ private static function checkBookingRangeForDays( DateTime $startOfRange, DateTi * @param $appliedTerms * @param int $allowedTotalBookings * - * @return void + * @return Booking[]|null + * @throws Exception */ private static function checkBookingAmount( DateTime $startOfRange, DateTime $endOfRange, Booking $booking, $appliedTerms, int $allowedTotalBookings ) { $countedPostTypes = [ 'confirmed' ]; diff --git a/src/Service/BookingRuleApplied.php b/src/Service/BookingRuleApplied.php index 0c82cb283..ed88e9e27 100644 --- a/src/Service/BookingRuleApplied.php +++ b/src/Service/BookingRuleApplied.php @@ -286,7 +286,7 @@ public static function init( bool $ignoreErrors = false ):array{ } try { $bookingRule->setAppliedParams( - $ruleParams ?? [], + $ruleParams, $selectParam ?? null ); } catch ( BookingRuleException $e ) { diff --git a/src/Service/TimeframeExport.php b/src/Service/TimeframeExport.php index 2f0d0724d..e869a2437 100644 --- a/src/Service/TimeframeExport.php +++ b/src/Service/TimeframeExport.php @@ -186,6 +186,19 @@ public static function ajaxExportCsv() { } } + /** + * Exports a file to the given directory path. + * This functions wraps the actual logic of {@see __construct()}, {@see getExportData} and {@see getCsv}. + * + * Note: At the moment this is not a helper to be used outside its context. + * It's heavily coupled to different values set via {@see Settings} and should therefore not be used outside of it's WordPress context. + * + * @param string $exportPath writable directory. + * + * @return void + * @throws CacheException From cache layer. + * @throws InvalidArgumentException From cache layer. + */ public static function cronExport( $exportPath ) { $timerange = Settings::getOption( 'commonsbooking_options_export', 'export-timerange' ); $start = date( 'd.m.Y' ); @@ -201,16 +214,17 @@ public static function cronExport( $exportPath ) { } else { $type = 0; } - $exportObject = new self( - $type, - $start, - $end, - $configuredLocationFields ? self::convertInputFields( $configuredLocationFields ) : null, - $configuredItemFields ? self::convertInputFields( $configuredItemFields ) : null, - $configuredUserFields ? self::convertInputFields( $configuredUserFields ) : null, - ); - $exportObject->setCron(); + try { + $exportObject = new self( + $type, + $start, + $end, + $configuredLocationFields ? self::convertInputFields( $configuredLocationFields ) : null, + $configuredItemFields ? self::convertInputFields( $configuredItemFields ) : null, + $configuredUserFields ? self::convertInputFields( $configuredUserFields ) : null, + ); + $exportObject->setCron(); $exportObject->getExportData(); $exportObject->getCSV( $exportPath . $exportObject->exportFilename ); } catch ( ExportException $e ) { diff --git a/src/Wordpress/CustomPostType/Booking.php b/src/Wordpress/CustomPostType/Booking.php index e1d699ef4..445c0dd4f 100644 --- a/src/Wordpress/CustomPostType/Booking.php +++ b/src/Wordpress/CustomPostType/Booking.php @@ -670,6 +670,11 @@ public function setCustomColumnsData( $column, $post_id ) { } } + /** + * @param \WP_Query $query + * + * @return void + */ public function setCustomColumnSortOrder( \WP_Query $query ) { if (! parent::setCustomColumnSortOrder( $query ) ) { return; diff --git a/src/Wordpress/CustomPostType/CustomPostType.php b/src/Wordpress/CustomPostType/CustomPostType.php index 1d96ebf8d..c2aa5955f 100644 --- a/src/Wordpress/CustomPostType/CustomPostType.php +++ b/src/Wordpress/CustomPostType/CustomPostType.php @@ -370,13 +370,15 @@ public static function getModel( $post ) { } /** - * This is called by the inheritances of the customPosts, it will just check if we - * are processing one of our CPTs. + * Checks if we query is processing one of our CPTs. + * + * This is called by the inheritances of the customPosts. + * * @param \WP_Query $query * - * @return void + * @return bool true if query is about our CPTs, false otherwise */ - public function setCustomColumnSortOrder(\WP_Query $query) { + public function setCustomColumnSortOrder( \WP_Query $query ) { if ( ! is_admin() || ! $query->is_main_query() || $query->get( 'post_type' ) !== static::$postType ) { return false; } diff --git a/src/Wordpress/CustomPostType/Item.php b/src/Wordpress/CustomPostType/Item.php index 2e09f32b0..5b5b43096 100644 --- a/src/Wordpress/CustomPostType/Item.php +++ b/src/Wordpress/CustomPostType/Item.php @@ -62,9 +62,9 @@ public function savePost($post_id, \WP_Post $post) { /** * Filters admin list by type (e.g. bookable, repair etc. ) * - * @param (wp_query object) $query + * @param \WP_Query $query for admin list objects * - * @return Void + * @return void */ public static function filterAdminList( $query ) { global $pagenow; diff --git a/src/Wordpress/CustomPostType/Location.php b/src/Wordpress/CustomPostType/Location.php index c79d04ecd..179165d9f 100644 --- a/src/Wordpress/CustomPostType/Location.php +++ b/src/Wordpress/CustomPostType/Location.php @@ -61,9 +61,9 @@ public static function termChange($term_id, $tt_id, $taxonomy) { /** * Filters admin list by type (e.g. bookable, repair etc. ) * - * @param (wp_query object) $query + * @param \WP_Query $query for admin list objects * - * @return Void + * @return void */ public static function filterAdminList( $query ) { global $pagenow; @@ -435,6 +435,7 @@ public function registerMetabox() { } // we store registered metaboxes to options table to be able to retrieve it in export function + $metabox_fields = []; foreach ($cmb->meta_box['fields'] as $metabox_field) { $metabox_fields[$metabox_field['id']] = $metabox_field['name']; } diff --git a/src/Wordpress/CustomPostType/Map.php b/src/Wordpress/CustomPostType/Map.php index 3903c6739..885a71f43 100644 --- a/src/Wordpress/CustomPostType/Map.php +++ b/src/Wordpress/CustomPostType/Map.php @@ -8,6 +8,7 @@ use CommonsBooking\Map\MapAdmin; use CommonsBooking\Map\MapSettings; use CommonsBooking\Map\MapShortcode; +use CommonsBooking\Repository\CB1; use CommonsBooking\Repository\Item; use CommonsBooking\Repository\Timeframe; use Exception; @@ -51,8 +52,7 @@ public static function getView() { **/ public static function replace_map_link_target() { global $post; - $cb_item = 'cb_items'; - if ( is_object( $post ) && $post->post_type == $cb_item ) { + if ( is_object( $post ) && $post->post_type == CB1::$ITEM_TYPE_ID ) { //get timeframes of item $cb_data = new CB_Data(); $date_start = date( 'Y-m-d' ); // current date @@ -81,6 +81,9 @@ public static function replace_map_link_target() { * load all timeframes from db (that end in the future and it's item's status is 'publish') **/ public static function get_timeframes() { + + $result = []; + $timeframes = Timeframe::getBookableForCurrentUser( [], [], diff --git a/src/Wordpress/CustomPostType/Restriction.php b/src/Wordpress/CustomPostType/Restriction.php index 049806123..7108b286d 100644 --- a/src/Wordpress/CustomPostType/Restriction.php +++ b/src/Wordpress/CustomPostType/Restriction.php @@ -219,12 +219,12 @@ public function setCustomColumnsData( $column, $post_id ) { } } - /** + /** * Filters admin list by type, timerange, user * - * @param (wp_query object) $query + * @param \WP_Query $query for admin list objects * - * @return Void + * @return void */ public static function filterAdminList( $query ) { global $pagenow; diff --git a/src/Wordpress/CustomPostType/Timeframe.php b/src/Wordpress/CustomPostType/Timeframe.php index 6755d229b..0282cbded 100644 --- a/src/Wordpress/CustomPostType/Timeframe.php +++ b/src/Wordpress/CustomPostType/Timeframe.php @@ -227,7 +227,7 @@ public static function isOverBookable( WP_Post $timeframe ) { /** * Returns view-class. - * @return \CommonsBooking\View\Timeframe + * @return null */ public static function getView() { // @TODO implement view. @@ -341,9 +341,9 @@ public static function addAdminDateFilter() { /** * Filters admin list by type (e.g. bookable, repair etc. ) * - * @param (wp_query object) $query + * @param \WP_Query $query for admin list objects * - * @return Void + * @return void */ public static function filterAdminList( $query ) { global $pagenow; @@ -875,6 +875,7 @@ public function savePost( $post_id, WP_Post $post ) { $e->getMessage(), 45 ); + return; } $timeframe->updatePostMetaStartAndEndDate(); @@ -930,8 +931,7 @@ public function updatedPostMeta($meta_id,$object_id,$meta_key,$meta_value) commonsbooking_sanitizeHTML( __( 'Orphaned bookings found, can migrate. Click here to migrate ', - 'commonsbooking', - 5 + 'commonsbooking' ) ) ); @@ -958,7 +958,7 @@ private static function sanitizeRepetitionEndDate( $postId ) : void { /** * Validates timeframe and sets state to draft if invalid. * - * @param Timeframe $timeframe + * @param \CommonsBooking\Model\Timeframe $timeframe * * @return bool */ @@ -1285,6 +1285,11 @@ public function setCustomColumnsData( $column, $post_id ) { } } + /** + * @param \WP_Query $query + * + * @return true|void returns true if inheriting method should set sort order, void if this method sets it + */ public function setCustomColumnSortOrder( \WP_Query $query ) { if (! parent::setCustomColumnSortOrder( $query ) ) { return; diff --git a/src/Wordpress/Options/OptionsTab.php b/src/Wordpress/Options/OptionsTab.php index a9159f4a1..830ad3839 100644 --- a/src/Wordpress/Options/OptionsTab.php +++ b/src/Wordpress/Options/OptionsTab.php @@ -6,6 +6,11 @@ use CommonsBooking\View\TimeframeExport; use Exception; +/** + * This adds the settings pane to the commonsbooking plugin page. + * It uses CMB2 fields to display settings in a generic way and uses underlying functionality to save them. + * The structure and contents of all the settings is controlled via the file OptionsArray. + */ class OptionsTab { public $option_key = COMMONSBOOKING_PLUGIN_SLUG . '_options'; diff --git a/src/Wordpress/Widget/UserWidget.php b/src/Wordpress/Widget/UserWidget.php index a86e37167..e62c62f2a 100644 --- a/src/Wordpress/Widget/UserWidget.php +++ b/src/Wordpress/Widget/UserWidget.php @@ -95,6 +95,11 @@ public function renderWidgetContent() { } + /** + * @param $instance + * + * @return string + */ public function form( $instance ) { $title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( '', 'commonsbooking' ); @@ -114,6 +119,8 @@ public function form( $instance ) {

assertArrayHasKey( 'pickup' , $dataArray[0] ); //because this is only set for bookings } - /** - * @ignore - */ - public function testExportCsv_testsFileCreation() { + public function testExportCsvAndFileCreation() { // TODO think about changing the signature of exportCSV or getExportData to include startDate and endDate, then it is less coupled to the actual usage atm ClockMock::freeze( new \DateTime( self::CURRENT_DATE ) ); Settings::updateOption( 'commonsbooking_options_export', 'export-timerange', 14 ); Settings::updateOption( 'commonsbooking_options_export', 'export-type', 'all' ); - $timeframeOneItemAndLocation = new Timeframe( $this->createBookableTimeFrameIncludingCurrentDay() ); + $this->createBookableTimeFrameIncludingCurrentDay(); TimeframeExport::cronExport( $this->directoryUnderTest );