Skip to content

Commit ddff68e

Browse files
authored
Merge pull request #533 from alleyinteractive/phpcs-textarea-datepicker
PHPCS for TextArea and Datepicker
2 parents cde28c4 + 2d37f7a commit ddff68e

3 files changed

+78
-60
lines changed

php/class-fieldmanager-datepicker.php

+62-48
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,72 @@
11
<?php
2-
32
/**
4-
* A Javascript date-picker which submits dates as unix timestamps.
3+
* Class file for Fieldmanager_Datepicker.
54
*
65
* @package Fieldmanager_Field
76
*/
7+
8+
/**
9+
* A JavaScript date-picker which submits dates as Unix timestamps.
10+
*/
811
class Fieldmanager_Datepicker extends Fieldmanager_Field {
912

1013
/**
11-
* @var boolean
1214
* Collect time info or just date info? Defaults to just date info.
15+
*
16+
* @var bool
1317
*/
14-
public $use_time = False;
18+
public $use_time = false;
1519

1620
/**
17-
* @var boolean
18-
* If true, and $use_time == true, and $date_element = 'dropdown', will render an 'AM' and 'PM' dropdown
21+
* If true, and $use_time == true, and $date_element = 'dropdown', will render an 'AM' and 'PM' dropdown.
22+
*
23+
* @var bool
1924
*/
20-
public $use_am_pm = True;
25+
public $use_am_pm = true;
2126

2227
/**
28+
* PHP date format, only used for rendering already-saved dates.
29+
*
30+
* Use $js_opts['dateFormat'] for the date shown when a user selects an
31+
* option. This option renders to '21 Apr 2013', and is fairly friendly to
32+
* international users.
33+
*
2334
* @var string
24-
* PHP date format, only used for rendering already-saved dates. Use js_opts['dateFormat'] for the
25-
* date shown when a user selects an option. This option renders to '21 Apr 2013', and is fairly
26-
* friendly to international users.
2735
*/
2836
public $date_format = 'j M Y';
2937

3038
/**
31-
* @var boolean
39+
* Whether to use the site's timezone setting when generating a timestamp.
40+
*
3241
* By default in WordPress, strtotime() assumes GMT. If $store_local_time is true, FM will use the
3342
* site's timezone setting when generating the timestamp. Note that `date()` will return GMT times
3443
* for the stamp no matter what, so if you store the local time, `date( 'H:i', $time )` will return
3544
* the offset time. Use this option if the exact timestamp is important, e.g. to schedule a wp-cron
3645
* event.
46+
*
47+
* @var bool
3748
*/
3849
public $store_local_time = false;
3950

4051
/**
41-
* @var array
42-
* Options to pass to the jQueryUI Datepicker. If you change dateFormat, be sure that it returns
43-
* a valid unix timestamp. Also, it's best to change js_opts['dateFormat'] and date_format together
44-
* for a consistent user experience.
52+
* Options to pass to the jQuery UI Datepicker.
53+
*
54+
* If you change dateFormat, be sure that it returns a valid Unix timestamp.
55+
* Also, it's best to change $js_opts['dateFormat'] and $date_format
56+
* together for a consistent user experience.
57+
*
58+
* @see http://api.jqueryui.com/datepicker/.
59+
* @see Fieldmanager_Datepicker::__construct() For the default options.
4560
*
46-
* Default:
47-
* <code>
48-
* array(
49-
* 'showButtonPanel' => True,
50-
* 'showOtherMonths' => True,
51-
* 'selectOtherMonths' => True,
52-
* 'dateFormat' => 'd M yy',
53-
* );
54-
* </code>
55-
* @see http://api.jqueryui.com/datepicker/
61+
* @var array
5662
*/
5763
public $js_opts = array();
5864

5965
/**
60-
* Construct default attributes and enqueue javascript
61-
* @param array $options
66+
* Construct default attributes and enqueue JavaScript.
67+
*
68+
* @param string $label Field label.
69+
* @param array $options Associative array of class property values. @see Fieldmanager_Field::__construct().
6270
*/
6371
public function __construct( $label = '', $options = array() ) {
6472
fm_add_style( 'fm-jquery-ui', 'css/jquery-ui/jquery-ui-1.10.2.custom.min.css' );
@@ -67,9 +75,9 @@ public function __construct( $label = '', $options = array() ) {
6775

6876
if ( empty( $this->js_opts ) ) {
6977
$this->js_opts = array(
70-
'showButtonPanel' => True,
71-
'showOtherMonths' => True,
72-
'selectOtherMonths' => True,
78+
'showButtonPanel' => true,
79+
'showOtherMonths' => true,
80+
'selectOtherMonths' => true,
7381
'dateFormat' => 'd M yy',
7482
);
7583
}
@@ -78,7 +86,7 @@ public function __construct( $label = '', $options = array() ) {
7886
/**
7987
* Generate HTML for the form element itself. Generally should be just one tag, no wrappers.
8088
*
81-
* @param mixed string[]|string the value of the element.
89+
* @param mixed $value The value of the element.
8290
* @return string HTML for the element.
8391
*/
8492
public function form_element( $value ) {
@@ -93,23 +101,26 @@ public function form_element( $value ) {
93101
ob_start();
94102
include fieldmanager_get_template( 'datepicker' );
95103

96-
// Reset the timestamp
104+
// Reset the timestamp.
97105
$value = $old_value;
98106
return ob_get_clean();
99107
}
100108

101109
/**
102-
* Convert date to timestamp
103-
* @param $value
104-
* @param $current_value
105-
* @return int unix timestamp
110+
* Convert date to timestamp.
111+
*
112+
* @param mixed $value The new value for the field.
113+
* @param mixed $current_value The current value for the field.
114+
* @return int Unix timestamp.
106115
*/
107116
public function presave( $value, $current_value = array() ) {
108117
$time_to_parse = sanitize_text_field( $value['date'] );
109118
if ( isset( $value['hour'] ) && is_numeric( $value['hour'] ) && $this->use_time ) {
110119
$hour = intval( $value['hour'] );
111120
$minute = ( isset( $value['minute'] ) && is_numeric( $value['minute'] ) ) ? intval( $value['minute'] ) : 0;
112-
if ( $hour == 0 && $this->use_am_pm ) $hour = 12;
121+
if ( 0 === $hour && $this->use_am_pm ) {
122+
$hour = 12;
123+
}
113124
$time_to_parse .= ' ' . $hour;
114125
$time_to_parse .= ':' . str_pad( $minute, 2, '0', STR_PAD_LEFT );
115126
$time_to_parse .= ' ' . sanitize_text_field( $value['ampm'] );
@@ -122,27 +133,30 @@ public function presave( $value, $current_value = array() ) {
122133
}
123134

124135
/**
125-
* Get hour for rendering in field
126-
* @param int $value unix timestamp
127-
* @return string value of hour
136+
* Get hour for rendering in field.
137+
*
138+
* @param int $value Unix timestamp.
139+
* @return string Value of hour.
128140
*/
129141
public function get_hour( $value ) {
130-
return !empty( $value ) ? date( $this->use_am_pm ? 'g' : 'G', $value ) : '';
142+
return ! empty( $value ) ? date( $this->use_am_pm ? 'g' : 'G', $value ) : '';
131143
}
132144

133145
/**
134-
* Get minute for rendering in field
135-
* @param int $value unix timestamp
136-
* @return string value of hour
146+
* Get minute for rendering in field.
147+
*
148+
* @param int $value Unix timestamp.
149+
* @return string Value of minute.
137150
*/
138151
public function get_minute( $value ) {
139-
return !empty( $value ) ? date( 'i', $value ) : '';
152+
return ! empty( $value ) ? date( 'i', $value ) : '';
140153
}
141154

142155
/**
143-
* Get am or pm for rendering in field
144-
* @param int $value unix timestamp
145-
* @return string 'am', 'pm', or ''
156+
* Get 'am' or 'pm' for rendering in field.
157+
*
158+
* @param int $value Unix timestamp.
159+
* @return string 'am', 'pm', or ''.
146160
*/
147161
public function get_am_pm( $value ) {
148162
return ! empty( $value ) ? date( 'a', $value ) : '';

php/class-fieldmanager-textarea.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
<?php
2-
32
/**
4-
* Multi-line text field.
3+
* Class file for Fieldmanager_TextArea.
54
*
65
* @package Fieldmanager_Field
76
*/
7+
8+
/**
9+
* Multi-line text field.
10+
*/
811
class Fieldmanager_TextArea extends Fieldmanager_Field {
912

1013
/**
14+
* Override $field_class.
15+
*
1116
* @var string
12-
* Override field_class
1317
*/
1418
public $field_class = 'text';
1519

1620
/**
17-
* Construct default attributes; 50x10 textarea
18-
* @param string $label
19-
* @param array $options
21+
* Construct default attributes; 50x10 textarea.
22+
*
23+
* @param string $label Field label.
24+
* @param array $options Associative array of class property values. @see Fieldmanager_Field::__construct().
2025
*/
2126
public function __construct( $label = '', $options = array() ) {
2227
$this->attributes = array(
2328
'cols' => '50',
24-
'rows' => '10'
29+
'rows' => '10',
2530
);
2631

2732
// Sanitize the textarea to preserve newlines. Could be overriden.
@@ -31,8 +36,9 @@ public function __construct( $label = '', $options = array() ) {
3136
}
3237

3338
/**
34-
* Form element
35-
* @param mixed $value
39+
* Form element.
40+
*
41+
* @param mixed $value Field value.
3642
* @return string HTML
3743
*/
3844
public function form_element( $value = '' ) {
@@ -45,4 +51,4 @@ public function form_element( $value = '' ) {
4551
);
4652
}
4753

48-
}
54+
}

phpcs.ruleset.xml

-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<exclude-pattern>php/class-fieldmanager-checkbox.php</exclude-pattern>
2525
<exclude-pattern>php/class-fieldmanager-checkboxes.php</exclude-pattern>
2626
<exclude-pattern>php/class-fieldmanager-colorpicker.php</exclude-pattern>
27-
<exclude-pattern>php/class-fieldmanager-datepicker.php</exclude-pattern>
2827
<exclude-pattern>php/class-fieldmanager-draggablepost.php</exclude-pattern>
2928
<exclude-pattern>php/class-fieldmanager-field.php</exclude-pattern>
3029
<exclude-pattern>php/class-fieldmanager-grid.php</exclude-pattern>
@@ -37,7 +36,6 @@
3736
<exclude-pattern>php/class-fieldmanager-radios.php</exclude-pattern>
3837
<exclude-pattern>php/class-fieldmanager-richtextarea.php</exclude-pattern>
3938
<exclude-pattern>php/class-fieldmanager-select.php</exclude-pattern>
40-
<exclude-pattern>php/class-fieldmanager-textarea.php</exclude-pattern>
4139
<exclude-pattern>php/class-fieldmanager-textfield.php</exclude-pattern>
4240
<exclude-pattern>php/context/class-fieldmanager-context-page.php</exclude-pattern>
4341
<exclude-pattern>php/context/class-fieldmanager-context-post.php</exclude-pattern>

0 commit comments

Comments
 (0)