Merge pull request #9717 from robbieaverill/pulls/4.7/improve-stuff

Update spaces in syntax, single quotes, early returns where possible
This commit is contained in:
Sam Minnée 2020-10-02 19:45:05 +13:00 committed by GitHub
commit 4ab36ac210
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 159 additions and 167 deletions

View File

@ -122,9 +122,8 @@ abstract class DBConnector
$operation = $matches['operation']; $operation = $matches['operation'];
if (is_array($type)) { if (is_array($type)) {
return in_array(strtolower($operation), $type); return in_array(strtolower($operation), $type);
} else {
return strcasecmp($sql, $type) === 0;
} }
return strcasecmp($sql, $type) === 0;
} }
/** /**

View File

@ -788,51 +788,45 @@ MESSAGE
if (!$this->supressOutput) { if (!$this->supressOutput) {
if (Director::is_cli()) { if (Director::is_cli()) {
switch ($type) { switch ($type) {
case "created": case 'created':
case "changed": case 'changed':
case "repaired": case 'repaired':
$sign = "+"; $sign = '+';
break; break;
case "obsolete": case 'obsolete':
case "deleted": case 'deleted':
$sign = '-'; $sign = '-';
break; break;
case "notice": case 'notice':
$sign = '*'; $sign = '*';
break; break;
case "error": case 'error':
$sign = "!"; $sign = '!';
break; break;
default: default:
$sign = " "; $sign = ' ';
} }
$message = strip_tags($message); $message = strip_tags($message);
echo " $sign $message\n"; echo " $sign $message\n";
} else { } else {
switch ($type) { switch ($type) {
case "created": case 'created':
$class = "success"; $class = 'success';
break; break;
case "obsolete": case 'obsolete':
$class = "error"; case 'error':
case 'deleted':
$class = 'error';
break; break;
case "notice": case 'notice':
$class = "warning"; $class = 'warning';
break; break;
case "error": case 'changed':
$class = "error"; case 'repaired':
break; $class = 'info';
case "deleted":
$class = "error";
break;
case "changed":
$class = "info";
break;
case "repaired":
$class = "info";
break; break;
default: default:
$class = ""; $class = '';
} }
echo "<li class=\"$class\">$message</li>"; echo "<li class=\"$class\">$message</li>";
} }
@ -878,7 +872,7 @@ MESSAGE
$this->alterationMessage( $this->alterationMessage(
"Table $tableName: renamed from $currentName", "Table $tableName: renamed from $currentName",
"repaired" 'repaired'
); );
// Rename via temp table to avoid case-sensitivity issues // Rename via temp table to avoid case-sensitivity issues

View File

@ -254,9 +254,8 @@ abstract class Database
Backtrace::backtrace(); Backtrace::backtrace();
} }
return $result; return $result;
} else {
return $callback($sql);
} }
return $callback($sql);
} }
/** /**

View File

@ -53,7 +53,7 @@ class DatabaseException extends Exception
* @param string $sql The SQL executed for this query * @param string $sql The SQL executed for this query
* @param array $parameters The parameters given for this query, if any * @param array $parameters The parameters given for this query, if any
*/ */
function __construct($message = '', $code = 0, $previous = null, $sql = null, $parameters = []) public function __construct($message = '', $code = 0, $previous = null, $sql = null, $parameters = [])
{ {
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
$this->sql = $sql; $this->sql = $sql;

View File

@ -11,7 +11,6 @@ use SilverStripe\ORM\DB;
*/ */
class DBBoolean extends DBField class DBBoolean extends DBField
{ {
public function __construct($name = null, $defaultVal = 0) public function __construct($name = null, $defaultVal = 0)
{ {
$this->defaultVal = ($defaultVal) ? 1 : 0; $this->defaultVal = ($defaultVal) ? 1 : 0;
@ -21,15 +20,15 @@ class DBBoolean extends DBField
public function requireField() public function requireField()
{ {
$parts=[ $parts = [
'datatype'=>'tinyint', 'datatype' => 'tinyint',
'precision'=>1, 'precision' => 1,
'sign'=>'unsigned', 'sign' => 'unsigned',
'null'=>'not null', 'null' => 'not null',
'default'=>$this->defaultVal, 'default' => $this->defaultVal,
'arrayValue'=>$this->arrayValue 'arrayValue' => $this->arrayValue
]; ];
$values=['type'=>'boolean', 'parts'=>$parts]; $values = ['type' => 'boolean', 'parts' => $parts];
DB::require_field($this->tableName, $this->name, $values); DB::require_field($this->tableName, $this->name, $values);
} }
@ -81,9 +80,11 @@ class DBBoolean extends DBField
{ {
if (is_bool($value)) { if (is_bool($value)) {
return $value ? 1 : 0; return $value ? 1 : 0;
} elseif (empty($value)) { }
if (empty($value)) {
return 0; return 0;
} elseif (is_string($value)) { }
if (is_string($value)) {
switch (strtolower($value)) { switch (strtolower($value)) {
case 'false': case 'false':
case 'f': case 'f':

View File

@ -4,9 +4,9 @@ namespace SilverStripe\ORM\FieldType;
use SilverStripe\Core\ClassInfo; use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\Dev\Deprecation;
/** /**
* Represents a classname selector, which respects obsolete clasess. * Represents a classname selector, which respects obsolete clasess.

View File

@ -126,7 +126,7 @@ abstract class DBComposite extends DBField
public function isChanged() public function isChanged()
{ {
// When unbound, use the local changed flag // When unbound, use the local changed flag
if (! ($this->record instanceof DataObject)) { if (!$this->record instanceof DataObject) {
return $this->isChanged; return $this->isChanged;
} }

View File

@ -35,7 +35,6 @@ class DBCurrency extends DBDecimal
*/ */
public function Nice() public function Nice()
{ {
// return "<span title=\"$this->value\">$" . number_format($this->value, 2) . '</span>';
$val = $this->config()->currency_symbol . number_format(abs($this->value), 2); $val = $this->config()->currency_symbol . number_format(abs($this->value), 2);
if ($this->value < 0) { if ($this->value < 0) {
return "($val)"; return "($val)";

View File

@ -335,11 +335,11 @@ class DBDate extends DBField
if ($y1 != $y2) { if ($y1 != $y2) {
return "$d1 $m1 $y1 - $d2 $m2 $y2"; return "$d1 $m1 $y1 - $d2 $m2 $y2";
} elseif ($m1 != $m2) {
return "$d1 $m1 - $d2 $m2 $y1";
} else {
return "$d1 - $d2 $m1 $y1";
} }
if ($m1 != $m2) {
return "$d1 $m1 - $d2 $m2 $y1";
}
return "$d1 - $d2 $m1 $y1";
} }
/** /**
@ -393,19 +393,18 @@ class DBDate extends DBField
$now = DBDatetime::now()->getTimestamp(); $now = DBDatetime::now()->getTimestamp();
if ($timestamp <= $now) { if ($timestamp <= $now) {
return _t( return _t(
'SilverStripe\\ORM\\FieldType\\DBDate.TIMEDIFFAGO', __CLASS__ . '.TIMEDIFFAGO',
"{difference} ago", "{difference} ago",
'Natural language time difference, e.g. 2 hours ago', 'Natural language time difference, e.g. 2 hours ago',
['difference' => $this->TimeDiff($includeSeconds, $significance)] ['difference' => $this->TimeDiff($includeSeconds, $significance)]
); );
} else {
return _t(
'SilverStripe\\ORM\\FieldType\\DBDate.TIMEDIFFIN',
"in {difference}",
'Natural language time difference, e.g. in 2 hours',
['difference' => $this->TimeDiff($includeSeconds, $significance)]
);
} }
return _t(
__CLASS__ . '.TIMEDIFFIN',
"in {difference}",
'Natural language time difference, e.g. in 2 hours',
['difference' => $this->TimeDiff($includeSeconds, $significance)]
);
} }
/** /**
@ -423,20 +422,24 @@ class DBDate extends DBField
$time = $this->getTimestamp(); $time = $this->getTimestamp();
$ago = abs($time - $now); $ago = abs($time - $now);
if ($ago < 60 && !$includeSeconds) { if ($ago < 60 && !$includeSeconds) {
return _t('SilverStripe\\ORM\\FieldType\\DBDate.LessThanMinuteAgo', 'less than a minute'); return _t(__CLASS__ . '.LessThanMinuteAgo', 'less than a minute');
} elseif ($ago < $significance * 60 && $includeSeconds) {
return $this->TimeDiffIn('seconds');
} elseif ($ago < $significance * 3600) {
return $this->TimeDiffIn('minutes');
} elseif ($ago < $significance * 86400) {
return $this->TimeDiffIn('hours');
} elseif ($ago < $significance * 86400 * 30) {
return $this->TimeDiffIn('days');
} elseif ($ago < $significance * 86400 * 365) {
return $this->TimeDiffIn('months');
} else {
return $this->TimeDiffIn('years');
} }
if ($ago < $significance * 60 && $includeSeconds) {
return $this->TimeDiffIn('seconds');
}
if ($ago < $significance * 3600) {
return $this->TimeDiffIn('minutes');
}
if ($ago < $significance * 86400) {
return $this->TimeDiffIn('hours');
}
if ($ago < $significance * 86400 * 30) {
return $this->TimeDiffIn('days');
}
if ($ago < $significance * 86400 * 365) {
return $this->TimeDiffIn('months');
}
return $this->TimeDiffIn('years');
} }
/** /**
@ -456,7 +459,7 @@ class DBDate extends DBField
$time = $this->getTimestamp(); $time = $this->getTimestamp();
$ago = abs($time - $now); $ago = abs($time - $now);
switch ($format) { switch ($format) {
case "seconds": case 'seconds':
$span = $ago; $span = $ago;
return _t( return _t(
__CLASS__ . '.SECONDS_SHORT_PLURALS', __CLASS__ . '.SECONDS_SHORT_PLURALS',
@ -464,7 +467,7 @@ class DBDate extends DBField
['count' => $span] ['count' => $span]
); );
case "minutes": case 'minutes':
$span = round($ago / 60); $span = round($ago / 60);
return _t( return _t(
__CLASS__ . '.MINUTES_SHORT_PLURALS', __CLASS__ . '.MINUTES_SHORT_PLURALS',
@ -472,7 +475,7 @@ class DBDate extends DBField
['count' => $span] ['count' => $span]
); );
case "hours": case 'hours':
$span = round($ago / 3600); $span = round($ago / 3600);
return _t( return _t(
__CLASS__ . '.HOURS_SHORT_PLURALS', __CLASS__ . '.HOURS_SHORT_PLURALS',
@ -480,7 +483,7 @@ class DBDate extends DBField
['count' => $span] ['count' => $span]
); );
case "days": case 'days':
$span = round($ago / 86400); $span = round($ago / 86400);
return _t( return _t(
__CLASS__ . '.DAYS_SHORT_PLURALS', __CLASS__ . '.DAYS_SHORT_PLURALS',
@ -488,7 +491,7 @@ class DBDate extends DBField
['count' => $span] ['count' => $span]
); );
case "months": case 'months':
$span = round($ago / 86400 / 30); $span = round($ago / 86400 / 30);
return _t( return _t(
__CLASS__ . '.MONTHS_SHORT_PLURALS', __CLASS__ . '.MONTHS_SHORT_PLURALS',
@ -496,7 +499,7 @@ class DBDate extends DBField
['count' => $span] ['count' => $span]
); );
case "years": case 'years':
$span = round($ago / 86400 / 365); $span = round($ago / 86400 / 365);
return _t( return _t(
__CLASS__ . '.YEARS_SHORT_PLURALS', __CLASS__ . '.YEARS_SHORT_PLURALS',
@ -554,6 +557,7 @@ class DBDate extends DBField
* </code> * </code>
* *
* @param string $adjustment PHP strtotime style * @param string $adjustment PHP strtotime style
* @return $this
*/ */
public function modify(string $adjustment): self public function modify(string $adjustment): self
{ {
@ -588,7 +592,7 @@ class DBDate extends DBField
protected function fixInputDate($value) protected function fixInputDate($value)
{ {
// split // split
list($year, $month, $day, $time) = $this->explodeDateString($value); [$year, $month, $day, $time] = $this->explodeDateString($value);
if ((int)$year === 0 && (int)$month === 0 && (int)$day === 0) { if ((int)$year === 0 && (int)$month === 0 && (int)$day === 0) {
return null; return null;

View File

@ -93,7 +93,7 @@ class DBDatetime extends DBDate implements TemplateGlobalProvider
* Return a date and time formatted as per a CMS user's settings. * Return a date and time formatted as per a CMS user's settings.
* *
* @param Member $member * @param Member $member
* @return boolean | string A time and date pair formatted as per user-defined settings. * @return boolean|string A time and date pair formatted as per user-defined settings.
*/ */
public function FormatFromSettings($member = null) public function FormatFromSettings($member = null)
{ {
@ -150,7 +150,7 @@ class DBDatetime extends DBDate implements TemplateGlobalProvider
'SilverStripe\\Forms\\FormField.EXAMPLE', 'SilverStripe\\Forms\\FormField.EXAMPLE',
'e.g. {format}', 'e.g. {format}',
'Example format', 'Example format',
[ 'format' => $date ] ['format' => $date]
)) ))
->setAttribute('placeholder', $dateTimeFormat); ->setAttribute('placeholder', $dateTimeFormat);

View File

@ -2,8 +2,8 @@
namespace SilverStripe\ORM\FieldType; namespace SilverStripe\ORM\FieldType;
use SilverStripe\ORM\DB;
use SilverStripe\Forms\NumericField; use SilverStripe\Forms\NumericField;
use SilverStripe\ORM\DB;
/** /**
* Represents a Decimal field. * Represents a Decimal field.

View File

@ -2,8 +2,8 @@
namespace SilverStripe\ORM\FieldType; namespace SilverStripe\ORM\FieldType;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\Connect\MySQLDatabase; use SilverStripe\ORM\Connect\MySQLDatabase;
use SilverStripe\ORM\DB;
/** /**
* Supports double precision DB types * Supports double precision DB types

View File

@ -130,7 +130,7 @@ class DBEnum extends DBString
* @param string $emptyString * @param string $emptyString
* @return DropdownField * @return DropdownField
*/ */
public function formField($title = null, $name = null, $hasEmpty = false, $value = "", $emptyString = null) public function formField($title = null, $name = null, $hasEmpty = false, $value = '', $emptyString = null)
{ {
if (!$title) { if (!$title) {
@ -154,13 +154,12 @@ class DBEnum extends DBString
} }
/** /**
* @param string * @param string $title
*
* @return DropdownField * @return DropdownField
*/ */
public function scaffoldSearchField($title = null) public function scaffoldSearchField($title = null)
{ {
$anyText = _t('SilverStripe\\ORM\\FieldType\\DBEnum.ANY', 'Any'); $anyText = _t(__CLASS__ . '.ANY', 'Any');
return $this->formField($title, null, true, '', "($anyText)"); return $this->formField($title, null, true, '', "($anyText)");
} }

View File

@ -232,7 +232,7 @@ abstract class DBField extends ViewableData implements DBIndexable
* *
* @param mixed $value * @param mixed $value
* @param DataObject|array $record An array or object that this field is part of * @param DataObject|array $record An array or object that this field is part of
* @param bool $markChanged Indicate wether this field should be marked changed. * @param bool $markChanged Indicate whether this field should be marked changed.
* Set to FALSE if you are initializing this field after construction, rather * Set to FALSE if you are initializing this field after construction, rather
* than setting a new value. * than setting a new value.
* @return $this * @return $this
@ -335,7 +335,7 @@ abstract class DBField extends ViewableData implements DBIndexable
* will be escaped automatically by the prepared query processor, so it * will be escaped automatically by the prepared query processor, so it
* should not be escaped or quoted at all. * should not be escaped or quoted at all.
* *
* @param $value mixed The value to check * @param mixed $value The value to check
* @return mixed The raw value, or escaped parameterised details * @return mixed The raw value, or escaped parameterised details
*/ */
public function prepValueForDB($value) public function prepValueForDB($value)

View File

@ -21,12 +21,12 @@ class DBFloat extends DBField
public function requireField() public function requireField()
{ {
$parts = [ $parts = [
'datatype'=>'float', 'datatype' => 'float',
'null'=>'not null', 'null' => 'not null',
'default'=>$this->defaultVal, 'default' => $this->defaultVal,
'arrayValue'=>$this->arrayValue 'arrayValue' => $this->arrayValue
]; ];
$values = ['type'=>'float', 'parts'=>$parts]; $values = ['type' => 'float', 'parts' => $parts];
DB::require_field($this->tableName, $this->name, $values); DB::require_field($this->tableName, $this->name, $values);
} }
@ -66,7 +66,9 @@ class DBFloat extends DBField
{ {
if ($value === true) { if ($value === true) {
return 1; return 1;
} elseif (empty($value) || !is_numeric($value)) { }
if (empty($value) || !is_numeric($value)) {
return 0; return 0;
} }

View File

@ -79,7 +79,7 @@ class DBForeignKey extends DBInt
} }
// Build selector / numeric field // Build selector / numeric field
$titleField = $hasOneSingleton->hasField('Title') ? "Title" : "Name"; $titleField = $hasOneSingleton->hasField('Title') ? 'Title' : 'Name';
$list = DataList::create($hasOneClass); $list = DataList::create($hasOneClass);
// Don't scaffold a dropdown for large tables, as making the list concrete // Don't scaffold a dropdown for large tables, as making the list concrete
// might exceed the available PHP memory in creating too many DataObject instances // might exceed the available PHP memory in creating too many DataObject instances
@ -118,7 +118,10 @@ class DBForeignKey extends DBInt
$field->setEmptyString(' '); $field->setEmptyString(' ');
} else { } else {
$field = new NumericField($this->name, $title); $field = new NumericField($this->name, $title);
$field->setRightTitle(_t(self::class . '.DROPDOWN_THRESHOLD_FALLBACK_MESSAGE', 'Too many related objects; fallback field in use')); $field->setRightTitle(_t(
self::class . '.DROPDOWN_THRESHOLD_FALLBACK_MESSAGE',
'Too many related objects; fallback field in use'
));
} }
return $field; return $field;
} }

View File

@ -2,11 +2,10 @@
namespace SilverStripe\ORM\FieldType; namespace SilverStripe\ORM\FieldType;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Control\HTTP; use SilverStripe\Control\HTTP;
use SilverStripe\Forms\TextField; use SilverStripe\Core\Convert;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField; use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\TextField;
use SilverStripe\View\Parsers\HTMLValue; use SilverStripe\View\Parsers\HTMLValue;
use SilverStripe\View\Parsers\ShortcodeParser; use SilverStripe\View\Parsers\ShortcodeParser;
@ -131,9 +130,8 @@ class DBHTMLText extends DBText
{ {
if ($this->processShortcodes) { if ($this->processShortcodes) {
return ShortcodeParser::get_active()->parse($this->value); return ShortcodeParser::get_active()->parse($this->value);
} else {
return $this->value;
} }
return $this->value;
} }
/** /**

View File

@ -3,8 +3,8 @@
namespace SilverStripe\ORM\FieldType; namespace SilverStripe\ORM\FieldType;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField; use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\TextField;
use SilverStripe\View\Parsers\ShortcodeParser; use SilverStripe\View\Parsers\ShortcodeParser;
/** /**
@ -88,9 +88,8 @@ class DBHTMLVarchar extends DBVarchar
{ {
if ($this->processShortcodes) { if ($this->processShortcodes) {
return ShortcodeParser::get_active()->parse($this->value); return ShortcodeParser::get_active()->parse($this->value);
} else {
return $this->value;
} }
return $this->value;
} }
/** /**

View File

@ -30,7 +30,7 @@ interface DBIndexable
* @param string|bool $indexType Either of the types listed in {@link SilverStripe\ORM\FieldType\DBIndexable}, or * @param string|bool $indexType Either of the types listed in {@link SilverStripe\ORM\FieldType\DBIndexable}, or
* boolean true to indicate that the default index type should be used. * boolean true to indicate that the default index type should be used.
* @return $this * @return $this
* @throws InvalidArgumentException If $type is not one of TYPE_INDEX, TYPE_UNIQUE or TYPE_FULLTEXT * @throws \InvalidArgumentException If $type is not one of TYPE_INDEX, TYPE_UNIQUE or TYPE_FULLTEXT
*/ */
public function setIndexType($type); public function setIndexType($type);

View File

@ -3,8 +3,8 @@
namespace SilverStripe\ORM\FieldType; namespace SilverStripe\ORM\FieldType;
use SilverStripe\Forms\NumericField; use SilverStripe\Forms\NumericField;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DB;
use SilverStripe\View\ArrayData; use SilverStripe\View\ArrayData;
/** /**
@ -45,7 +45,7 @@ class DBInt extends DBField
{ {
$output = new ArrayList(); $output = new ArrayList();
for ($i = 0; $i < $this->value; $i++) { for ($i = 0; $i < $this->value; $i++) {
$output->push(new ArrayData([ 'Number' => $i + 1 ])); $output->push(ArrayData::create(['Number' => $i + 1]));
} }
return $output; return $output;

View File

@ -65,7 +65,7 @@ class DBLocale extends DBVarchar
public function getNativeName() public function getNativeName()
{ {
$locale = $this->value; $locale = $this->value;
return i18n::with_locale($locale, function () use ($locale) { return i18n::with_locale($locale, function () {
return $this->getShortName(); return $this->getShortName();
}); });
} }

View File

@ -22,8 +22,8 @@ class DBMoney extends DBComposite
* @param array * @param array
*/ */
private static $composite_db = [ private static $composite_db = [
"Currency" => "Varchar(3)", 'Currency' => 'Varchar(3)',
"Amount" => 'Decimal(19,4)' 'Amount' => 'Decimal(19,4)'
]; ];
/** /**

View File

@ -3,9 +3,9 @@
namespace SilverStripe\ORM\FieldType; namespace SilverStripe\ORM\FieldType;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\CheckboxSetField;
use SilverStripe\ORM\Connect\MySQLDatabase; use SilverStripe\ORM\Connect\MySQLDatabase;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\Forms\CheckboxSetField;
/** /**
* Represents an multi-select enumeration field. * Represents an multi-select enumeration field.
@ -25,7 +25,7 @@ class DBMultiEnum extends DBEnum
if (!in_array($thisDefault, $this->enum)) { if (!in_array($thisDefault, $this->enum)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
"Enum::__construct() The default value '$thisDefault' does not match " "Enum::__construct() The default value '$thisDefault' does not match "
. "any item in the enumeration" . 'any item in the enumeration'
); );
} }
} }
@ -38,16 +38,16 @@ class DBMultiEnum extends DBEnum
// @todo: Remove mysql-centric logic from this // @todo: Remove mysql-centric logic from this
$charset = Config::inst()->get(MySQLDatabase::class, 'charset'); $charset = Config::inst()->get(MySQLDatabase::class, 'charset');
$collation = Config::inst()->get(MySQLDatabase::class, 'collation'); $collation = Config::inst()->get(MySQLDatabase::class, 'collation');
$values=[ $values = [
'type'=>'set', 'type' => 'set',
'parts'=>[ 'parts' => [
'enums'=>$this->enum, 'enums' => $this->enum,
'character set'=> $charset, 'character set' => $charset,
'collate'=> $collation, 'collate' => $collation,
'default'=> $this->default, 'default' => $this->default,
'table'=>$this->tableName, 'table' => $this->tableName,
'arrayValue'=>$this->arrayValue 'arrayValue' => $this->arrayValue,
] ],
]; ];
DB::require_field($this->tableName, $this->name, $values); DB::require_field($this->tableName, $this->name, $values);
@ -64,7 +64,7 @@ class DBMultiEnum extends DBEnum
* @param string $emptyString * @param string $emptyString
* @return CheckboxSetField * @return CheckboxSetField
*/ */
public function formField($title = null, $name = null, $hasEmpty = false, $value = "", $emptyString = null) public function formField($title = null, $name = null, $hasEmpty = false, $value = '', $emptyString = null)
{ {
if (!$title) { if (!$title) {
@ -74,8 +74,6 @@ class DBMultiEnum extends DBEnum
$name = $this->name; $name = $this->name;
} }
$field = new CheckboxSetField($name, $title, $this->enumValues($hasEmpty), $value); return new CheckboxSetField($name, $title, $this->enumValues($hasEmpty), $value);
return $field;
} }
} }

View File

@ -83,7 +83,7 @@ class DBPolymorphicForeignKey extends DBComposite
{ {
$id = $this->getIDValue(); $id = $this->getIDValue();
$class = $this->getClassValue(); $class = $this->getClassValue();
if ($id && $class && is_subclass_of($class, 'SilverStripe\ORM\DataObject')) { if ($id && $class && is_subclass_of($class, DataObject::class)) {
return DataObject::get_by_id($class, $id); return DataObject::get_by_id($class, $id);
} }
return null; return null;

View File

@ -2,8 +2,8 @@
namespace SilverStripe\ORM\FieldType; namespace SilverStripe\ORM\FieldType;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
/** /**
* A special type Int field used for primary keys. * A special type Int field used for primary keys.

View File

@ -11,12 +11,12 @@ abstract class DBString extends DBField
* @var array * @var array
*/ */
private static $casting = [ private static $casting = [
"LimitCharacters" => "Text", 'LimitCharacters' => 'Text',
"LimitCharactersToClosestWord" => "Text", 'LimitCharactersToClosestWord' => 'Text',
"LimitWordCount" => "Text", 'LimitWordCount' => 'Text',
"LowerCase" => "Text", 'LowerCase' => 'Text',
"UpperCase" => "Text", 'UpperCase' => 'Text',
"Plain" => "Text", 'Plain' => 'Text',
]; ];
/** /**

View File

@ -2,14 +2,14 @@
namespace SilverStripe\ORM\FieldType; namespace SilverStripe\ORM\FieldType;
use InvalidArgumentException;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\NullableField; use SilverStripe\Forms\NullableField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextField;
use SilverStripe\ORM\Connect\MySQLDatabase;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use InvalidArgumentException;
/** /**
* Represents a variable-length string of up to 16 megabytes, designed to store raw text * Represents a variable-length string of up to 16 megabytes, designed to store raw text
@ -29,12 +29,12 @@ class DBText extends DBString
{ {
private static $casting = [ private static $casting = [
"BigSummary" => "Text", 'BigSummary' => 'Text',
"ContextSummary" => "HTMLFragment", // Always returns HTML as it contains formatting and highlighting 'ContextSummary' => 'HTMLFragment', // Always returns HTML as it contains formatting and highlighting
"FirstParagraph" => "Text", 'FirstParagraph' => 'Text',
"FirstSentence" => "Text", 'FirstSentence' => 'Text',
"LimitSentences" => "Text", 'LimitSentences' => 'Text',
"Summary" => "Text", 'Summary' => 'Text',
]; ];
/** /**
@ -43,8 +43,8 @@ class DBText extends DBString
*/ */
public function requireField() public function requireField()
{ {
$charset = Config::inst()->get('SilverStripe\ORM\Connect\MySQLDatabase', 'charset'); $charset = Config::inst()->get(MySQLDatabase::class, 'charset');
$collation = Config::inst()->get('SilverStripe\ORM\Connect\MySQLDatabase', 'collation'); $collation = Config::inst()->get(MySQLDatabase::class, 'collation');
$parts = [ $parts = [
'datatype' => 'mediumtext', 'datatype' => 'mediumtext',
@ -76,7 +76,7 @@ class DBText extends DBString
$value = $this->Plain(); $value = $this->Plain();
if (!$value) { if (!$value) {
return ""; return '';
} }
// Do a word-search // Do a word-search
@ -94,10 +94,9 @@ class DBText extends DBString
// Failing to find the number of sentences requested, fallback to a logical default // Failing to find the number of sentences requested, fallback to a logical default
if ($maxSentences > 1) { if ($maxSentences > 1) {
return $value; return $value;
} else {
// If searching for a single sentence (and there are none) just do a text summary
return $this->Summary(20);
} }
// If searching for a single sentence (and there are none) just do a text summary
return $this->Summary(20);
} }
@ -260,10 +259,9 @@ class DBText extends DBString
if (!$this->nullifyEmpty) { if (!$this->nullifyEmpty) {
// Allow the user to select if it's null instead of automatically assuming empty string is // Allow the user to select if it's null instead of automatically assuming empty string is
return NullableField::create(TextareaField::create($this->name, $title)); return NullableField::create(TextareaField::create($this->name, $title));
} else {
// Automatically determine null (empty string)
return TextareaField::create($this->name, $title);
} }
// Automatically determine null (empty string)
return TextareaField::create($this->name, $title);
} }
public function scaffoldSearchField($title = null) public function scaffoldSearchField($title = null)

View File

@ -32,7 +32,7 @@ class DBTime extends DBField
$value = $this->parseTime($value); $value = $this->parseTime($value);
if ($value === false) { if ($value === false) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
"Invalid date passed. Use " . $this->getISOFormat() . " to prevent this error." 'Invalid date passed. Use ' . $this->getISOFormat() . ' to prevent this error.'
); );
} }
$this->value = $value; $this->value = $value;

View File

@ -19,8 +19,8 @@ class DBVarchar extends DBString
{ {
private static $casting = [ private static $casting = [
"Initial" => "Text", 'Initial' => 'Text',
"URL" => "Text", 'URL' => 'Text',
]; ];
/** /**
@ -68,11 +68,11 @@ class DBVarchar extends DBString
$collation = Config::inst()->get(MySQLDatabase::class, 'collation'); $collation = Config::inst()->get(MySQLDatabase::class, 'collation');
$parts = [ $parts = [
'datatype'=>'varchar', 'datatype' => 'varchar',
'precision'=>$this->size, 'precision' => $this->size,
'character set'=> $charset, 'character set' => $charset,
'collate'=> $collation, 'collate' => $collation,
'arrayValue'=>$this->arrayValue 'arrayValue' => $this->arrayValue
]; ];
$values = [ $values = [
@ -107,9 +107,8 @@ class DBVarchar extends DBString
$value = $this->RAW(); $value = $this->RAW();
if (preg_match('#^[a-zA-Z]+://#', $value)) { if (preg_match('#^[a-zA-Z]+://#', $value)) {
return $value; return $value;
} else {
return "http://" . $value;
} }
return 'http://' . $value;
} }
/** /**

View File

@ -13,8 +13,8 @@ class DBYear extends DBField
public function requireField() public function requireField()
{ {
$parts=['datatype'=>'year', 'precision'=>4, 'arrayValue'=>$this->arrayValue]; $parts = ['datatype' => 'year', 'precision' => 4, 'arrayValue' => $this->arrayValue];
$values=['type'=>'year', 'parts'=>$parts]; $values = ['type' => 'year', 'parts' => $parts];
DB::require_field($this->tableName, $this->name, $values); DB::require_field($this->tableName, $this->name, $values);
} }
@ -44,7 +44,7 @@ class DBYear extends DBField
$end = 1900; $end = 1900;
} }
$years = []; $years = [];
for ($i=$start; $i>=$end; $i--) { for ($i = $start; $i >= $end; $i--) {
$years[$i] = $i; $years[$i] = $i;
} }
return $years; return $years;