Skip to content

Commit fb25be5

Browse files
authored
Merge pull request #4 from codem/maint-module-requirements
Module requirements - general maintenance and requirements updates
2 parents 2ce7bc6 + 4147f3a commit fb25be5

36 files changed

+226
-129
lines changed

.gitattributes

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/tests export-ignore
2-
/docs export-ignore
3-
/client/src export-ignore
4-
/.gitattributes export-ignore
5-
/.gitignore export-ignore
6-
/.php_cs.dist
7-
/.phpcs.xml.dist
8-
/.phpunit.xml.dist
9-
/README.md export-ignore
1+
/tests export-ignore
2+
/docs export-ignore
3+
/.editorconfig export-ignore
4+
/.gitattributes export-ignore
5+
/.gitignore export-ignore
6+
/.php-cs-fixer.dist.php export-ignore
7+
/code-of-conduct.md export-ignore
8+
/CONTRIBUTING.md export-ignore
9+
/README.md export-ignore

.php-cs-fixer.dist.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Configuration file for https://github.com/FriendsOfPHP/PHP-CS-Fixer
4+
* Install with composer: $ composer global require friendsofphp/php-cs-fixer
5+
* Usage (in this directory) : ~/.composer/vendor/bin/php-cs-fixer fix .
6+
*/
7+
$finder = PhpCsFixer\Finder::create()
8+
->in(__DIR__);
9+
10+
$config = new PhpCsFixer\Config();
11+
return $config->setRules([
12+
'@PSR2' => true,
13+
'array_indentation' => true,
14+
'array_syntax' => ['syntax' => 'short'],
15+
'blank_line_after_namespace' => true,
16+
'blank_line_after_opening_tag' => true,
17+
'full_opening_tag' => true,
18+
'no_closing_tag' => true,
19+
])
20+
->setIndent(" ")
21+
->setFinder($finder);

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
}
2626
},
2727
"require": {
28-
"silverstripe/framework" : "^4"
28+
"silverstripe/framework" : "^4.10.0"
2929
},
3030
"require-dev": {
31-
"phpunit/phpunit": "^5.7 | ^9.5",
32-
"squizlabs/php_codesniffer": "^3.0",
31+
"phpunit/phpunit": "^9.5",
32+
"friendsofphp/php-cs-fixer": "^3",
3333
"ext-dom" : "*"
3434
}
3535
}

phpcs.xml.dist

-11
This file was deleted.

src/Forms/ColorField.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color
1212
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color#Value wrt value
1313
*/
14-
class ColorField extends TextField {
14+
class ColorField extends TextField
15+
{
1516

1617
use Core;
1718
use Datalist;
@@ -24,7 +25,8 @@ class ColorField extends TextField {
2425
* Returns the value saved as a 6 chr RGB colour with # prefixed
2526
* @return string
2627
*/
27-
public function dataValue() {
28+
public function dataValue()
29+
{
2830
$value = $this->getValidRGB($this->value);
2931
return $value;
3032
}
@@ -42,7 +44,8 @@ public function Value()
4244
* @param string $value an RGB colour value as a 'valid simple colour'
4345
* @return void
4446
*/
45-
public function setValue($value, $data = null) {
47+
public function setValue($value, $data = null)
48+
{
4649
$this->value = $this->getValidRGB($value);
4750
}
4851

@@ -61,7 +64,8 @@ public function setValue($value, $data = null) {
6164
* representing the red component, the middle two digits representing the green component,
6265
* and the last two digits representing the blue component, in hexadecimal.</blockquote>
6366
*/
64-
public function getValidRGB($value, Validator $validator = null) {
67+
public function getValidRGB($value, Validator $validator = null)
68+
{
6569

6670
// empty values default to the empty value value
6771
if(!$value) {
@@ -71,7 +75,7 @@ public function getValidRGB($value, Validator $validator = null) {
7175
$value = strtolower($value);
7276

7377
// If input is not exactly seven characters long, then return an error.
74-
if(mb_strlen( $value ) != 7) {
78+
if(mb_strlen($value) != 7) {
7579
if($validator) {
7680
$validator->validationError(
7781
$this->name,

src/Forms/ColourField.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
/**
66
* Provides a class for those of us not using en_US
77
*/
8-
class ColourField extends ColorField {
8+
class ColourField extends ColorField
9+
{
910

1011
protected $template = "Codem/Utilities/HTML5/ColorField";
1112

src/Forms/DateField.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
* Provides a date field
99
* @author James
1010
*/
11-
class DateField extends TextField {
11+
class DateField extends TextField
12+
{
1213

1314
use Core;
1415
use Datalist;
@@ -21,15 +22,18 @@ class DateField extends TextField {
2122

2223
protected $example = "2020-12-31";
2324

24-
protected function formatDate(\Datetime $datetime) {
25-
return $datetime->format( $this->datetime_format );
25+
protected function formatDate(\Datetime $datetime)
26+
{
27+
return $datetime->format($this->datetime_format);
2628
}
2729

28-
public function setMin(\DateTime $min) {
30+
public function setMin(\DateTime $min)
31+
{
2932
return $this->setAttribute('min', $this->formatDate($min));
3033
}
3134

32-
public function setMax(\DateTime $max) {
35+
public function setMax(\DateTime $max)
36+
{
3337
return $this->setAttribute('max', $this->formatDate($max));
3438
}
3539

src/Forms/DatetimeField.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
* but with hour and minute selection
88
* @author James
99
*/
10-
class DatetimeField extends DateField {
10+
class DatetimeField extends DateField
11+
{
1112

1213
protected $inputType = 'datetime-local';
1314

src/Forms/EmailField.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
* Text input field with validation for correct email format according to RFC 2822.
99
* @author james
1010
*/
11-
class EmailField extends CoreEmailField {
11+
class EmailField extends CoreEmailField
12+
{
1213

1314
use Core;
1415
use Datalist;

src/Forms/MonthField.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
* but with month and year selection
88
* @author James
99
*/
10-
class MonthField extends DateField {
10+
class MonthField extends DateField
11+
{
1112

1213
protected $inputType = 'month';
1314

src/Forms/NumberField.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
* Number input field
99
* @author James
1010
*/
11-
class NumberField extends TextField {
11+
class NumberField extends TextField
12+
{
1213

1314
use Core;
1415
use Datalist;

src/Forms/RangeField.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
/**
88
* Range input field
99
*/
10-
class RangeField extends TextField {
10+
class RangeField extends TextField
11+
{
1112

1213
use Core;
1314
use Datalist;

src/Forms/SearchField.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
* Search input field
99
* @author James
1010
*/
11-
class SearchField extends TextField {
11+
class SearchField extends TextField
12+
{
1213

1314
use Core;
1415
use Datalist;

src/Forms/TelField.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
* From <input> elements of type tel are used to let the user enter and edit a telephone number.
99
* @author James
1010
*/
11-
class TelField extends TextField {
11+
class TelField extends TextField
12+
{
1213

1314
use Core;
1415
use Datalist;
@@ -20,7 +21,8 @@ class TelField extends TextField {
2021
/**
2122
* @inheritdoc
2223
*/
23-
public function Type() {
24+
public function Type()
25+
{
2426
return 'tel text';
2527
}
2628

src/Forms/TimeField.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* Provides a time field, limited to hour and minute selection only
77
* @author James
88
*/
9-
class TimeField extends DateField {
9+
class TimeField extends DateField
10+
{
1011

1112
protected $inputType = 'time';
1213

src/Forms/UrlField.php

+19-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
/**
99
* Provides a URL input field
1010
*/
11-
class UrlField extends TextField {
11+
class UrlField extends TextField
12+
{
1213

1314
use Core;
1415
use Datalist;
@@ -28,7 +29,8 @@ class UrlField extends TextField {
2829
/**
2930
* @inheritdoc
3031
*/
31-
public function Type() {
32+
public function Type()
33+
{
3234
return 'url text';
3335
}
3436

@@ -86,7 +88,8 @@ public function validate($validator)
8688
return true;
8789
}
8890

89-
public function setRequiredParts(array $requiredParts) {
91+
public function setRequiredParts(array $requiredParts)
92+
{
9093
$this->requiredParts = $requiredParts;
9194
return $this;
9295
}
@@ -95,7 +98,8 @@ public function setRequiredParts(array $requiredParts) {
9598
* Parse a possible URL string
9699
* If the second parameter is provided, the URL must have those parts
97100
*/
98-
public function parseURL(string $url) : bool {
101+
public function parseURL(string $url) : bool
102+
{
99103
if($url == '') {
100104
// an empty URL is a valid URL
101105
return true;
@@ -104,7 +108,7 @@ public function parseURL(string $url) : bool {
104108
$parts = parse_url($url);
105109
if(empty($this->requiredParts)) {
106110
return !empty($parts);
107-
} else {
111+
} else {
108112
// ensure all of the required parts are present in all of the keys
109113
$result = array_intersect($this->requiredParts, array_keys($parts));
110114
sort($result);
@@ -116,19 +120,22 @@ public function parseURL(string $url) : bool {
116120
/**
117121
* Schemes are set by calling restrictToSchemes
118122
*/
119-
protected function setSchemes(array $schemes) {
123+
protected function setSchemes(array $schemes)
124+
{
120125
$this->schemes = $schemes;
121126
return $this;
122127
}
123128

124-
public function getSchemes() {
129+
public function getSchemes()
130+
{
125131
return $this->schemes;
126132
}
127133

128134
/**
129135
* Restrict to http (and https) protocols
130136
*/
131-
public function restrictToHttp() {
137+
public function restrictToHttp()
138+
{
132139
$this->restrictToSchemes(["https","http"]);
133140
$this->setAttribute(
134141
'placeholder',
@@ -143,14 +150,16 @@ public function restrictToHttp() {
143150
/**
144151
* Restrict to URLs beginning with https://
145152
*/
146-
public function restrictToHttps() {
153+
public function restrictToHttps()
154+
{
147155
return $this->restrictToSchemes(["https"]);
148156
}
149157

150158
/**
151159
* Restrict to URLs beginning with the provided scheme
152160
*/
153-
public function restrictToSchemes(array $schemes) {
161+
public function restrictToSchemes(array $schemes)
162+
{
154163
$this->setSchemes($schemes);
155164
$schemesString = implode("://, ", $schemes) . "://";
156165
$this->setAttribute(

src/Forms/WeekField.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
* year plus the ISO 8601 week number during that year (i.e., week 1 to 52 or 53).
99
* @author James
1010
*/
11-
class WeekField extends DateField {
11+
class WeekField extends DateField
12+
{
1213

1314
protected $inputType = 'week';
1415

src/Traits/Core.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66
* Core common attribute methods
77
* @author James
88
*/
9-
trait Core {
9+
trait Core
10+
{
1011

11-
protected function bool2str($value) {
12+
protected function bool2str($value)
13+
{
1214
return $value ? 'true' : 'false';
1315
}
1416

15-
public function setSpellcheck($spellcheck) {
17+
public function setSpellcheck($spellcheck)
18+
{
1619
return $this->setAttribute('spellcheck', $this->bool2str($spellcheck));
1720
}
1821

19-
public function getSpellcheck() {
22+
public function getSpellcheck()
23+
{
2024
return $this->getAttribute('spellcheck');
2125
}
2226

0 commit comments

Comments
 (0)