diff --git a/src/Messages/BookingCodesMessage.php b/src/Messages/BookingCodesMessage.php index 63263bdb3..65f1a479d 100644 --- a/src/Messages/BookingCodesMessage.php +++ b/src/Messages/BookingCodesMessage.php @@ -39,32 +39,32 @@ public function __construct( $postId, string $action, int $tsFrom=null, int $tsT /** * prepares Message and sends by E-mail - * + * * @return bool true if message was sent, false otherwise. If the message is not sent, an error is raised. */ public function sendMessage(): bool { $timeframeId=(int)$this->getPostId(); $timeframe=new Timeframe($timeframeId); - if(!$this->prepareReceivers($timeframe)) return $this->raiseError( + if(!$this->prepareReceivers($timeframe)) return $this->raiseError( __( "Unable to send Emails. No location email(s) configured, check location", "commonsbooking" )); $bookingCodes = BookingCodes::getCodes($timeframeId, $this->tsFrom,$this->tsTo); if(empty($bookingCodes)) return $this->raiseError( __( "Could not find booking codes for this timeframe/period", "commonsbooking" )); - + $bookingTable=apply_filters('commonsbooking_emailcodes_rendertable', \CommonsBooking\View\BookingCodes::renderBookingCodesTable( $bookingCodes ), $bookingCodes,'email'); - + $bAddIcal=apply_filters('commonsbooking_emailcodes_addical', Settings::getOption( 'commonsbooking_options_bookingcodes', 'mail-booking-' . $this->action . '-attach-ical' ), $timeframe); $attachment=$bAddIcal?$this->getIcalAttachment($bookingCodes):null; - + //Workaround: arbitrary object for template parser $codes=new \WP_User((object)array( "ID" => -1)); $codes->codeTable=$bookingTable; - + $dispTo= wp_date("M-Y",strtotime(end($bookingCodes)->getDate())); $dispFrom= wp_date("M-Y",strtotime(reset($bookingCodes)->getDate())); $codes->formatDateRange=($dispFrom == $dispTo)?$dispFrom:$dispFrom . " - " . $dispTo; @@ -97,19 +97,19 @@ public function sendMessage(): bool { ], $attachment ); - + add_action( 'commonsbooking_mail_sent',array($this,'updateEmailSent'), 5, 2 ); - + if(count($this->locationAdmins) > 1) { add_filter('commonsbooking_mail_to', array($this,'addMultiTo'), 25); - $this->SendNotificationMail(); + $this->sendNotificationMail(); remove_filter('commonsbooking_mail_to', array($this,'addMultiTo'), 25); } else - $this->SendNotificationMail(); + $this->sendNotificationMail(); remove_action( 'commonsbooking_mail_sent',array($this,'updateEmailSent'), 5 ); - + return true; } @@ -126,17 +126,17 @@ public function sendMessage(): bool { public function updateEmailSent($action,$result) { if($this->action != $action) return; - + if($result === true) { - update_post_meta( (int)$this->getPostId(), \CommonsBooking\View\BookingCodes::LAST_CODES_EMAIL, time() ); + update_post_meta( (int)$this->getPostId(), \CommonsBooking\View\BookingCodes::LAST_CODES_EMAIL, time() ); } } /** * filter commonsbooking_mail_to for adding multiple to email addresses - * + * * @return array */ public function addMultiTo(): array { @@ -163,18 +163,18 @@ protected function prepareReceivers(Timeframe $timeframe): bool { foreach(array_map('trim', explode(',', $location_emails)) as $email) { $dUser=$this->locationAdmins[]=new \WP_User((object)array( "ID" => $dummy_id--)); $dUser->user_nicename=''; - $dUser->user_email=$email; + $dUser->user_email=$email; } } return !empty($this->locationAdmins); } - + /** * generates iCalendar attachment with all requested booking codes * * @param BookingCode[] $bookingCodes List of BookingCode objects - * + * * @return array */ protected function getIcalAttachment( array $bookingCodes): array { @@ -199,7 +199,7 @@ protected function getIcalAttachment( array $bookingCodes): array { ]; return $attachment; - + } /** diff --git a/src/Messages/BookingMessage.php b/src/Messages/BookingMessage.php index 64283638c..827204cfc 100644 --- a/src/Messages/BookingMessage.php +++ b/src/Messages/BookingMessage.php @@ -83,7 +83,7 @@ public function sendMessage() { $template_objects, $attachment ); - $this->SendNotificationMail(); + $this->sendNotificationMail(); } } \ No newline at end of file diff --git a/src/Messages/BookingReminderMessage.php b/src/Messages/BookingReminderMessage.php index e1fbc9e2a..6a981f907 100644 --- a/src/Messages/BookingReminderMessage.php +++ b/src/Messages/BookingReminderMessage.php @@ -54,7 +54,7 @@ public function sendMessage() { 'user' => $booking_user, ] ); - $this->SendNotificationMail(); + $this->sendNotificationMail(); } } \ No newline at end of file diff --git a/src/Messages/Message.php b/src/Messages/Message.php index ae5522bc9..807d9607a 100644 --- a/src/Messages/Message.php +++ b/src/Messages/Message.php @@ -146,19 +146,19 @@ protected function prepareMail( // Setup email: From $this->headers[] = $from_headers; - // add bcc adresses + // add bcc adresses if ( ! empty ( $bcc_adresses ) ) { $addresses_array = explode( ',', $bcc_adresses ); $this->add_bcc( $addresses_array ); } - + //add attachment when it exists if (!empty($attachment)) { $this->attachment = $attachment; } } - + /** * Send the email using wp_mail function * @@ -166,13 +166,13 @@ protected function prepareMail( * * @return void */ - public function SendNotificationMail() { + public function sendNotificationMail() { $to = $this->getTo(); $subject = $this->getSubject(); $body = $this->getBody(); $attachment = $this->getAttachment(); $headers = implode( "\r\n", $this->headers ); - + if (!empty($attachment)) { //When attachment exists, modify wp_mail function to support attachment strings add_filter('wp_mail', array($this,'addStringAttachments'), 25); //add arbitrary priority to identify filter for removal $result = wp_mail($to, $subject, $body, $headers, $attachment); @@ -237,7 +237,7 @@ public function getValidActions(): array { * Adds support for defining attachments as data arrays in wp_mail(). * Allows us to send string-based or binary attachments (non-filesystem) * and gives us more control over the attachment data. - * + * * @param array $atts Array of the `wp_mail()` arguments. * - string|string[] $to Array or comma-separated list of email addresses to send message. * - string $subject Email subject. @@ -253,12 +253,12 @@ public function addStringAttachments($atts) if (array_key_exists('attachments', $atts) && isset($atts['attachments']) && $atts['attachments']) { $attachments = $atts['attachments']; if (is_array($attachments) && !empty($attachments)) { - // Is the $attachments array a single array of attachment data, or an array containing multiple arrays of + // Is the $attachments array a single array of attachment data, or an array containing multiple arrays of // attachment data? (note that the array may also be a one-dimensional array of file paths, as-per default usage). $is_multidimensional_array = count($attachments) == count($attachments, COUNT_RECURSIVE) ? false : true; if (!$is_multidimensional_array) $attachments = [$attachments]; - // Work out which attachments we want to process here. If the value is an array with either - // a 'path' or 'path' key, then we'll process it separately and remove it from the + // Work out which attachments we want to process here. If the value is an array with either + // a 'path' or 'path' key, then we'll process it separately and remove it from the // $atts['attachments'] so that WP doesn't try to process it in wp_mail(). foreach ($attachments as $index => $attachment) { if (is_array($attachment) && (array_key_exists('path', $attachment) || array_key_exists('string', $attachment))) { @@ -279,9 +279,9 @@ public function addStringAttachments($atts) global $wp_mail_attachments; $wp_mail_attachments = $attachment_arrays; - // We can't use the global $phpmailer to add our attachments directly in the 'wp_mail' filter callback because WP calls $phpmailer->clearAttachments() - // after this filter runs. Instead, we now hook into the 'phpmailer_init' action (triggered right before the email is sent), and read - // the $wp_mail_attachments global to check for any additional attachments to add. + // We can't use the global $phpmailer to add our attachments directly in the 'wp_mail' filter callback because WP calls $phpmailer->clearAttachments() + // after this filter runs. Instead, we now hook into the 'phpmailer_init' action (triggered right before the email is sent), and read + // the $wp_mail_attachments global to check for any additional attachments to add. add_action('phpmailer_init', function ( $phpmailer) { // Check the $wp_mail_attachments global for any attachment data, and reset it for good measure. $attachment_arrays = []; diff --git a/src/Messages/RestrictionMessage.php b/src/Messages/RestrictionMessage.php index 465677e5d..d5127e6c6 100644 --- a/src/Messages/RestrictionMessage.php +++ b/src/Messages/RestrictionMessage.php @@ -75,7 +75,7 @@ protected function sendHintMail() { $subject ); - $this->SendNotificationMail(); + $this->sendNotificationMail(); } /** @@ -90,7 +90,7 @@ protected function sendRepairMail() { $subject ); - $this->SendNotificationMail(); + $this->sendNotificationMail(); } /** @@ -105,7 +105,7 @@ protected function sendRestrictionCancelationMail() { $subject ); - $this->SendNotificationMail(); + $this->sendNotificationMail(); } /** diff --git a/src/Model/Booking.php b/src/Model/Booking.php index 9e7462fda..edd12b7a3 100755 --- a/src/Model/Booking.php +++ b/src/Model/Booking.php @@ -883,7 +883,7 @@ public function hasTotalBreakdown(): bool { /** * Returns formatted user info based on the template field in settings -> templates * - * @return void + * @return mixed */ public static function getFormattedUserInfo() { return commonsbooking_parse_template( diff --git a/src/Model/CustomPost.php b/src/Model/CustomPost.php index e105d7e7e..a1d20995d 100644 --- a/src/Model/CustomPost.php +++ b/src/Model/CustomPost.php @@ -194,7 +194,7 @@ public function getUserData() { * Checks if the given user is the author of the current post. * @param \WP_User $user * - * @return boolean - true if user is author, false if not. + * @return bool - true if user is author, false if not. */ public function isAuthor (\WP_User $user): bool { return $user->ID === intval( $this->post_author ); diff --git a/src/Model/Day.php b/src/Model/Day.php index b7bc6755a..aedef3566 100644 --- a/src/Model/Day.php +++ b/src/Model/Day.php @@ -221,15 +221,15 @@ protected function getStartSlot( int $grid, \CommonsBooking\Model\Timeframe $tim * * @param int $grid * @param Restriction $restriction - + * @return float|int */ - protected function getRestrictionStartSlot( int $grid, \CommonsBooking\Model\Restriction $restriction ) { + protected function getRestrictionStartSlot( int $grid, Restriction $restriction ) { $startTime = $restriction->getStartTimeDateTime(); $startSlot = $this->getSlotByTime( $startTime, $grid ); - $startDateBooking = intval( $restriction->getStartDate() ); + $startDateBooking = $restriction->getStartDate(); $startDateDay = strtotime( $this->getDate() ); // if restriction starts on day before, we set startslot to 0 @@ -285,7 +285,7 @@ protected function getEndSlot( array $slots, int $grid, \CommonsBooking\Model\Ti * @return float|int * @throws Exception */ - protected function getRestrictionEndSlot( array $slots, int $grid, \CommonsBooking\Model\Restriction $restriction ) { + protected function getRestrictionEndSlot( array $slots, int $grid, Restriction $restriction ) { $endTime = $restriction->getEndTimeDateTime( $this->getDateObject()->getTimestamp() ); $endDate = $restriction->getEndDateDateTime(); @@ -440,7 +440,7 @@ protected function mapRestrictions( array &$slots ) { $grid = 24 / count( $slots ); // Iterate through timeframes and fill slots - /** @var \CommonsBooking\Model\Restriction $restriction */ + /** @var Restriction $restriction */ foreach ( $this->getRestrictions() as $restriction ) { // Only if there is a repair we block the timeframe diff --git a/src/Model/Timeframe.php b/src/Model/Timeframe.php index 80ecc5e4a..1184ef552 100644 --- a/src/Model/Timeframe.php +++ b/src/Model/Timeframe.php @@ -5,7 +5,6 @@ use CommonsBooking\Exception\OverlappingException; use CommonsBooking\Exception\TimeframeInvalidException; use CommonsBooking\Helper\Wordpress; -use CommonsBooking\Tests\Repository\TimeframeTest; use DateTime; use Exception; @@ -898,7 +897,7 @@ public function getGrid(): int { * Checks if timeframes are overlapping in time ranges or daily slots. * * Use {@see Timeframe::overlaps()} if you want to compute full-overlap between two timeframes. - * + * * @param Timeframe $otherTimeframe * * @return bool If start-time and end-time overlaps, regardless of overlapping start-date and end-date. diff --git a/src/Model/Week.php b/src/Model/Week.php index 05eb814d5..8e714ca77 100644 --- a/src/Model/Week.php +++ b/src/Model/Week.php @@ -15,13 +15,13 @@ class Week { /** - * @var integer + * @var int */ protected $year; /** * Day in the year to start the week from (0-365) - * @var integer + * @var int */ protected $dayOfYear; diff --git a/src/Plugin.php b/src/Plugin.php index 50dc971c1..6e0ec7203 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -253,7 +253,7 @@ public static function admin_init() { // Check if we need to run post options updated actions if ( get_transient( 'commonsbooking_options_saved' ) == 1 ) { - AdminOptions::SetOptionsDefaultValues(); + AdminOptions::setOptionsDefaultValues(); flush_rewrite_rules(); diff --git a/src/Service/Scheduler.php b/src/Service/Scheduler.php index 762bdf4aa..4576af453 100644 --- a/src/Service/Scheduler.php +++ b/src/Service/Scheduler.php @@ -14,8 +14,8 @@ */ class Scheduler { - protected string $jobhook; - protected string $reccurence; + protected string $jobhook; + protected string $reccurence; protected int $timestamp; const UNSCHEDULER_HOOK = COMMONSBOOKING_PLUGIN_SLUG . '_unschedule'; @@ -45,7 +45,7 @@ function __construct( // Add custom cron intervals add_filter( 'cron_schedules', array( self::class, 'initIntervals' ) ); - $this->jobhook = COMMONSBOOKING_PLUGIN_SLUG . '_' .$jobhook; //Prepends plugin slug so that hooks can be found easily afterwards + $this->jobhook = COMMONSBOOKING_PLUGIN_SLUG . '_' .$jobhook; //Prepends plugin slug so that hooks can be found easily afterwards if ((count($option) == 2) && Settings::getOption($option[0],$option[1]) != 'on' ) { //removes job if option unset $this->unscheduleJob(); @@ -54,7 +54,7 @@ function __construct( if (empty($executionTime)){ $this->timestamp = time(); - } + } elseif ($reccurence == 'daily'){ $this->timestamp = strtotime($executionTime); if($this->timestamp < time()) { //if timestamp is in the past, add one day @@ -226,7 +226,7 @@ public function getTimestamp(): int { * - The job is no longer needed * - The job has been updated and needs to be rescheduled * - The plugin has been deactivated - * @return boolean + * @return int|false|\WP_Error */ private function unscheduleJob() { return wp_clear_scheduled_hook($this->jobhook); diff --git a/src/Service/Upgrade.php b/src/Service/Upgrade.php index a47d8ca56..c57684d81 100644 --- a/src/Service/Upgrade.php +++ b/src/Service/Upgrade.php @@ -84,7 +84,7 @@ class Upgrade { */ private function runEveryUpgrade(): void { // set Options default values (e.g. if there are new fields added) - AdminOptions::SetOptionsDefaultValues(); + AdminOptions::setOptionsDefaultValues(); // flush rewrite rules flush_rewrite_rules(); diff --git a/tests/php/Messages/MessageTest.php b/tests/php/Messages/MessageTest.php index 6fb078587..b09cc88fd 100644 --- a/tests/php/Messages/MessageTest.php +++ b/tests/php/Messages/MessageTest.php @@ -107,7 +107,7 @@ public function testGetPost() { } public function testSendNotificationMail() { - $this->message->SendNotificationMail(); + $this->message->sendNotificationMail(); /** @var \PHPMailer\PHPMailer\PHPMailer $mailer */ $mailer = $this->getMockMailer(); $this->assertEmpty($mailer->ErrorInfo); @@ -162,7 +162,7 @@ public function test_1433() { $fromMail = self::FROM_MAIL; $fromHeader = 'From: ' . $fromName . ' <' . $fromMail . '>'; $subject = 'Test ' . $specialChar . ' Subject'; - + $this->message = $this->getMockBuilder(Message::class) ->onlyMethods(['sendMessage']) ->setConstructorArgs([$this->postID, self::ACTION]) @@ -175,7 +175,7 @@ public function test_1433() { $subject, $fromHeader, ] ); - $this->message->SendNotificationMail(); + $this->message->sendNotificationMail(); /** @var \PHPMailer\PHPMailer\PHPMailer $mailer */ $mailer = $this->getMockMailer(); $this->assertEquals($fromMail, $mailer->From);