Problem/Motivation

The doxygen on \Drupal\Component\DateTimePlus are out of date and do not match the type signature for the functions in the class. These need to be fixed.

Proposed resolution

Update doxygen for

\Drupal\Component\DateTimePlus::createFromDateTime()
\Drupal\Component\DateTimePlus::createFromArray()
\Drupal\Component\DateTimePlus::createFromTimestamp()
\Drupal\Component\DateTimePlus::createFromFormat()
\Drupal\Component\DateTimePlus::prepareTime()
\Drupal\Component\DateTimePlus::prepareTimezone()
\Drupal\Component\DateTimePlus::prepareFormat()
\Drupal\Component\DateTimePlus::hasErrors()
\Drupal\Component\DateTimePlus::getErrors()

Remaining tasks

Fix remaining instances.

User interface changes

None.

API changes

None.

Data model changes

None.

Release Eval

This is eligible for 8.1.x per the policy under

- API documentation improvements

Original report

While working on other issue I spotted incomplete doxygen comment. Having fully specified function description helps prevent unhandled exception cases, so here is a
simple patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dpovshed created an issue. See original summary.

mpdonadio’s picture

Version: 8.2.x-dev » 8.1.x-dev
Category: Bug report » Task
Status: Needs review » Needs work
Issue tags: +Quick fix, +Needs issue summary update
+++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
@@ -132,6 +132,8 @@ public static function createFromDateTime(\DateTime $datetime, $settings = array
    * @return static
    *   A new \Drupal\Component\DateTimePlus object based on the parameters
    *   passed in.
+   * @throws \Exception
+   *   If array date values or value combination are not correct.
    */
   public static function createFromArray(array $date_parts, $timezone = NULL, $settings = array()) {

Total nit, but the convention is for a blank comment line between the sections, so there should be one above the @throws line.

Otherwise, fine with the wording; phrasing is consistent with other similar exceptions. This would be eligible under the allowed changes to go into 8.1.x as a patch release b/c it is an API documentation improvement. Should do a quick IS update to follow the template.

ztl8702’s picture

ztl8702’s picture

Status: Needs work » Needs review
mpdonadio’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update +Documentation

@ztl8702, normally, we try to post an interdiff when posting a new patch so we can see what has changed. No worries on this, though, since it is a simple patch.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think it is worth to re-scope this issue to fix this issue for all the methods in DateTimePlus as there are quite a few methods in this class that throw exceptions

mpdonadio’s picture

Title: Missing @throws in Doxygen doc for createFromDateTime » Update Doxygen for \Drupal\Component\DateTimePlus
Issue summary: View changes
Issue tags: +Novice

Edited IS to re-scope issue per #6 w/ the methods that PhpStorm complained about.

ztl8702’s picture

Assigned: Unassigned » ztl8702
ztl8702’s picture

Status: Needs work » Needs review
FileSize
3.22 KB
2.75 KB
mpdonadio’s picture

Assigned: ztl8702 » Unassigned
Issue summary: View changes
Status: Needs review » Needs work

Thanks for the quick turnaround. Just a few small things, and I'll RTBC this.

  1. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -104,6 +104,10 @@ class DateTimePlus {
    +   * @return static
    +   *   A new \Drupal\Component\DateTimePlus object based on the parameters
    +   *   passed in.
        */
    

    General convention in core is to not fully qualify the class in these. I think it can simply be "A new DateTimePlus object." (This is somewhat obvious from the static constructors, but this pattern is used a lot in core.)

  2. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -155,6 +162,13 @@ public static function createFromArray(array $date_parts, $timezone = NULL, $set
    +   * @return static
    +   *   A new \Drupal\Component\DateTimePlus object based on the parameters
    +   *   passed in.
    +   *
    

    Same as above.

  3. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -187,6 +201,14 @@ public static function createFromTimestamp($timestamp, $timezone = NULL, $settin
    +   * @return static
    +   *   A new \Drupal\Component\DateTimePlus object based on the parameters
    +   *   passed in.
    +   *
    

    Same as above.

  4. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -324,6 +346,8 @@ public function __clone() {
    +   *
    +   * @return mixed
        */
    

    For future reviewers, I think the comment on the method when you read this in context explains this fully and more details on the return value isn't needed.

  5. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -338,6 +362,9 @@ protected function prepareTime($time) {
    +   *
    +   * @return \DateTimeZone
    +   *   A \DateTimeZone object based on the timezone passed in.
    

    Same as above.

  6. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -370,6 +397,8 @@ protected function prepareTimezone($timezone) {
    +   *
    +   * @return string
    

    As above, I'm fine w/o additional info here.

ztl8702’s picture

@mpdonadio thanks for your detailed instructions.

ztl8702’s picture

Status: Needs work » Needs review
ztl8702’s picture

mpdonadio’s picture

Thanks, I think this looks perfect. But, I need to read it applied before I RTBC it, which I can't do until tonight.

mpdonadio’s picture

Issue summary: View changes
Status: Needs review » Needs work

OK, patch looks good. In looking at this in context, let's do this right and also add

- @return for hasErrors
- @return for getErrors

so they at least typehint properly.

The docs in this class aren't up to our current quality, but I think I want to stop the scope of the issue here. The protected properties need types, and some of the comments are wrong, but we can clean that up later.

himanshugautam’s picture

added @return boolean and @return string to hasErrors and getErrors

I am new here and want to learn.
Please correct if I anything wrong

himanshugautam’s picture

Status: Needs work » Needs review
mpdonadio’s picture

Status: Needs review » Needs work
FileSize
734 bytes

#16, thanks for the patch. We normally try to post an interdiff so we can easily see what has changed patch-to-patch. I attached one for your changes.

+++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
@@ -408,6 +432,8 @@ public function checkErrors() {
@@ -417,6 +443,8 @@ public function hasErrors() {

@@ -417,6 +443,8 @@ public function hasErrors() {
    * Gets error messages.
    *
    * Public function to return the error messages.
+   *
+   * @return string
    */

This is an array.

himanshugautam’s picture

Sorry @mpdonadio, for some reason I want not able to upload the interdiff.
Made changes again uploading interdiff

himanshugautam’s picture

Status: Needs work » Needs review
mpdonadio’s picture

Status: Needs review » Reviewed & tested by the community

This class still has issues, but I am happy with the improvements that this patch provides. Further doc updates are premature before we look at better look at whether there are refactoring opportunities.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
@@ -329,6 +347,8 @@ public function __clone() {
+   *
+   * @return mixed

@@ -343,6 +363,8 @@ protected function prepareTime($time) {
+   *
+   * @return \DateTimeZone

@@ -375,6 +397,8 @@ protected function prepareTimezone($timezone) {
+   *
+   * @return string

@@ -408,6 +432,8 @@ public function checkErrors() {
+   *
+   * @return boolean

@@ -417,6 +443,8 @@ public function hasErrors() {
+   *
+   * @return array

If we are going to add these @return's in this patch then let's at least not docs which don't conform to the standards. These all need a description.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
1.62 KB
3.81 KB

Added the descriptions as requested in #22.

mpdonadio’s picture

Status: Needs review » Needs work

Thanks. I think we need a few tweaks before this is ready. DREditor is being weird. I hope these make sense.

  1. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -324,6 +342,10 @@ public function __clone() {
    +   * @return mixed
    +   *   An input value, which could be a timestamp, a string, or an array of date
    +   *   parts.
        */
    

    For the return value for prepareTime(), how about 'The massaged time.'

  2. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -338,6 +360,9 @@ protected function prepareTime($time) {
    +   * @return \DateTimeZone
    +   *   A DateTimeZone object.
        */
    

    For prepareTimezone(), how about 'The massaged time zone.'

  3. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -370,6 +395,9 @@ protected function prepareTimezone($timezone) {
    +   * @return string
    +   *   A PHP format string.
        */
    

    For prepareFormat(), how about 'The massaged PHP format string.'

These better match the comments where they are used.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
1.15 KB
3.75 KB

I like how that's shorter and less repetitive, yet still clear. Thanks!

mpdonadio’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Read this in place, and it looks good. Think all feedback has been addressed. This is eligible for 8.1.x per the policy under "API documentation improvements."

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 864055b and pushed to 8.1.x and 8.2.x. Thanks!

  • alexpott committed 2c54c39 on 8.2.x
    Issue #2702835 by ztl8702, pjonckiere, himanshugautam, dpovshed,...

  • alexpott committed 864055b on 8.1.x
    Issue #2702835 by ztl8702, pjonckiere, himanshugautam, dpovshed,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.