Navigation Menu

Skip to content

Commit

Permalink
BUG Fix missing use statements
Browse files Browse the repository at this point in the history
BUG Fix incorrect method visibility on SS_Database
BUG Fix obvious PHPDoc errors in SilverStripe\ORM\FieldType
BUG Fix incorrect case on some method invocations
API Remove some deprecated code
  • Loading branch information
Damian Mooyman committed Jul 1, 2016
1 parent 80d4af6 commit efef025
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 54 deletions.
15 changes: 8 additions & 7 deletions ORM/Connect/DBSchemaManager.php
Expand Up @@ -46,7 +46,7 @@ abstract class DBSchemaManager {
/**
* Injector injection point for database controller
*
* @param SS_Database $connector
* @param SS_Database $database
*/
public function setDatabase(SS_Database $database) {
$this->database = $database;
Expand Down Expand Up @@ -127,6 +127,7 @@ public function schemaUpdate($callback) {
// Clear update list for client code to mess around with
$this->schemaUpdateTransaction = array();

/** @var Exception $error */
$error = null;
try {

Expand Down Expand Up @@ -302,8 +303,8 @@ protected function transInitTable($table) {
* - array('fields' => array('A','B','C'), 'type' => 'index/unique/fulltext'): This gives you full
* control over the index.
* @param boolean $hasAutoIncPK A flag indicating that the primary key on this table is an autoincrement type
* @param string $options SQL statement to append to the CREATE TABLE call.
* @param array $extensions List of extensions
* @param string|array $options SQL statement to append to the CREATE TABLE call.
* @param array|bool $extensions List of extensions
*/
public function requireTable($table, $fieldSchema = null, $indexSchema = null, $hasAutoIncPK = true,
$options = array(), $extensions = false
Expand Down Expand Up @@ -539,6 +540,7 @@ protected function parseIndexSpec($name, $spec) {
* @see parseIndexSpec() for approximate inverse
*
* @param string|array $indexSpec
* @return string
*/
protected function convertIndexSpec($indexSpec) {
// Return already converted spec
Expand All @@ -551,7 +553,7 @@ protected function convertIndexSpec($indexSpec) {
/**
* Returns true if the given table is exists in the current database
*
* @param string $table Name of table to check
* @param string $tableName Name of table to check
* @return boolean Flag indicating existence of table
*/
abstract public function hasTable($tableName);
Expand Down Expand Up @@ -879,7 +881,7 @@ abstract public function tableList();
* @param array $options An map of additional options. The available keys are as follows:
* - 'MSSQLDatabase'/'MySQLDatabase'/'PostgreSQLDatabase' - database-specific options such as "engine" for MySQL.
* - 'temporary' - If true, then a temporary table will be created
* @param $advancedOptions Advanced creation options
* @param array $advancedOptions Advanced creation options
* @return string The table name generated. This may be different from the table name, for example with temporary
* tables.
*/
Expand Down Expand Up @@ -940,8 +942,7 @@ abstract public function fieldList($table);
* This allows the cached values for a table's field list to be erased.
* If $tablename is empty, then the whole cache is erased.
*
* @param string $tableName
*
* @param string|bool $tableName
* @return boolean
*/
public function clearCachedFieldlist($tableName = false) {
Expand Down
6 changes: 3 additions & 3 deletions ORM/Connect/Database.php
Expand Up @@ -26,10 +26,10 @@ abstract class SS_Database {
* @var DBConnector
*/
protected $connector = null;

/**
* Amount of queries executed, for debugging purposes.
*
*
* @var int
*/
protected $queryCount = 0;
Expand Down Expand Up @@ -560,7 +560,7 @@ public function withTransaction(
* @return boolean Flag indicating support for all of the above
* @todo Write test cases
*/
protected function supportsExtensions($extensions) {
public function supportsExtensions($extensions) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions ORM/DB.php
Expand Up @@ -9,6 +9,7 @@
use LogicException;
use Cookie;
use Injector;
use SilverStripe\ORM\Connect\DBSchemaManager;
use SilverStripe\ORM\Queries\SQLExpression;
use SilverStripe\ORM\Connect\SS_Database;

Expand Down
9 changes: 5 additions & 4 deletions ORM/FieldType/DBComposite.php
Expand Up @@ -5,6 +5,7 @@
use Object;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\Queries\SQLSelect;


/**
Expand Down Expand Up @@ -127,7 +128,7 @@ public function exists() {
public function requireField() {
foreach($this->compositeDatabaseFields() as $field => $spec){
$key = $this->getName() . $field;
DB::requireField($this->tableName, $key, $spec);
DB::require_field($this->tableName, $key, $spec);
}
}

Expand Down Expand Up @@ -239,7 +240,8 @@ public function setField($field, $value, $markChanged = true) {
// Set bound object
if($this->record instanceof DataObject) {
$key = $this->getName() . $field;
return $this->record->setField($key, $value);
$this->record->setField($key, $value);
return;
}

// Set local record
Expand Down Expand Up @@ -272,8 +274,7 @@ public function castingHelper($field) {
return $fields[$field];
}


parent::castingHelper($field);
return parent::castingHelper($field);
}

}
12 changes: 0 additions & 12 deletions ORM/FieldType/DBCurrency.php
Expand Up @@ -2,8 +2,6 @@

namespace SilverStripe\ORM\FieldType;

use Deprecation;

/**
* Represents a decimal field containing a currency amount.
* The currency class only supports single currencies. For multi-currency support, use {@link Money}
Expand Down Expand Up @@ -63,15 +61,5 @@ public function setValue($value, $record = null, $markChanged = true) {
$this->value = 0;
}
}

/**
* @deprecated 4.0 Use the "Currency.currency_symbol" config setting instead
* @param [type] $value [description]
*/

public static function setCurrencySymbol($value) {
Deprecation::notice('4.0', 'Use the "Currency.currency_symbol" config setting instead');
DBCurrency::config()->currency_symbol = $value;
}
}

16 changes: 10 additions & 6 deletions ORM/FieldType/DBDate.php
Expand Up @@ -67,7 +67,7 @@ public function setValue($value, $record = null, $markChanged = true) {
} elseif(is_string($value)) {
try{
$date = new DateTime($value);
$this->value = $date->Format('Y-m-d');
$this->value = $date->format('Y-m-d');
return;
}catch(Exception $e){
$this->value = null;
Expand Down Expand Up @@ -120,7 +120,7 @@ public function ShortMonth() {

/**
* Returns the day of the month.
* @param boolean $includeOrdinals Include ordinal suffix to day, e.g. "th" or "rd"
* @param bool $includeOrdinal Include ordinal suffix to day, e.g. "th" or "rd"
* @return string
*/
public function DayOfMonth($includeOrdinal = false) {
Expand Down Expand Up @@ -154,7 +154,7 @@ public function Full() {
public function Format($format) {
if($this->value){
$date = new DateTime($this->value);
return $date->Format($format);
return $date->format($format);
}
}

Expand All @@ -163,6 +163,9 @@ public function Format($format) {
*
* strftime obeys the current LC_TIME/LC_ALL when printing lexical values
* like day- and month-names
*
* @param string $formattingString
* @return string
*/
public function FormatI18N($formattingString) {
if($this->value) {
Expand Down Expand Up @@ -192,10 +195,11 @@ public function FormatFromSettings($member = null) {
return $zendDate->toString($formatD);
}

/*
/**
* Return a string in the form "12 - 16 Sept" or "12 Aug - 16 Sept"
* @param Date $otherDateObj Another date object specifying the end of the range
* @param boolean $includeOrdinals Include ordinal suffix to day, e.g. "th" or "rd"
*
* @param DBDate $otherDateObj Another date object specifying the end of the range
* @param bool $includeOrdinals Include ordinal suffix to day, e.g. "th" or "rd"
* @return string
*/
public function RangeString($otherDateObj, $includeOrdinals = false) {
Expand Down
8 changes: 4 additions & 4 deletions ORM/FieldType/DBDatetime.php
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\ORM\FieldType;

use Convert;
use Exception;
use Member;
use DatetimeField;
use Zend_Date;
Expand Down Expand Up @@ -59,12 +60,11 @@ public function setValue($value, $record = null, $markChanged = true) {
if(is_numeric($value)) {
$this->value = date('Y-m-d H:i:s', $value);
} elseif(is_string($value)) {
// $this->value = date('Y-m-d H:i:s', strtotime($value));
try{
try {
$date = new DateTime($value);
$this->value = $date->Format('Y-m-d H:i:s');
$this->value = $date->format('Y-m-d H:i:s');
return;
}catch(Exception $e){
} catch(Exception $e) {
$this->value = null;
return;
}
Expand Down
3 changes: 2 additions & 1 deletion ORM/FieldType/DBDecimal.php
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\ORM\FieldType;

use NumericField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;

/**
Expand All @@ -21,7 +22,7 @@ class DBDecimal extends DBField {
* @param string $name
* @param int $wholeSize
* @param int $decimalSize
* @param float $defaultValue
* @param float|int $defaultValue
*/
public function __construct($name = null, $wholeSize = 9, $decimalSize = 2, $defaultValue = 0) {
$this->wholeSize = is_int($wholeSize) ? $wholeSize : 9;
Expand Down
5 changes: 3 additions & 2 deletions ORM/FieldType/DBEnum.php
Expand Up @@ -50,9 +50,10 @@ class DBEnum extends DBString {
* "MyField" => "Enum(array('Val1', 'Val2', 'Val3'), 'Val1')"
* </code>
*
* @param enum: A string containing a comma separated list of options or an
* @param string $name
* @param string|array $enum A string containing a comma separated list of options or an
* array of Vals.
* @param string The default option, which is either NULL or one of the
* @param string $default The default option, which is either NULL or one of the
* items in the enumeration.
*/
public function __construct($name = null, $enum = NULL, $default = NULL) {
Expand Down
7 changes: 6 additions & 1 deletion ORM/FieldType/DBField.php
Expand Up @@ -2,6 +2,10 @@

namespace SilverStripe\ORM\FieldType;

use FormField;
use SearchFilter;
use SilverStripe\ORM\Connect\SS_Query;
use SilverStripe\ORM\DataObject;
use ViewableData;
use Convert;
use Object;
Expand Down Expand Up @@ -151,7 +155,7 @@ public function getValue() {
*
* @param mixed $value
* @param DataObject|array $record An array or object that this field is part of
* @param boolean $markChanged Indicate wether this field should be marked changed.
* @param bool $markChanged Indicate wether this field should be marked changed.
* Set to FALSE if you are initializing this field after construction, rather
* than setting a new value.
*/
Expand Down Expand Up @@ -348,6 +352,7 @@ public function scaffoldSearchField($title = null) {
* search filters (note: parameter hack now in place to pass in the required full path - using $this->name
* won't work)
*
* @param string|bool $name
* @return SearchFilter
*/
public function defaultSearchFilter($name = false) {
Expand Down
2 changes: 2 additions & 0 deletions ORM/FieldType/DBForeignKey.php
Expand Up @@ -2,6 +2,8 @@

namespace SilverStripe\ORM\FieldType;

use File;
use Image;
use UploadField;
use DropdownField;
use NumericField;
Expand Down
13 changes: 12 additions & 1 deletion ORM/FieldType/DBMoney.php
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\ORM\FieldType;

use FormField;
use i18n;
use Zend_Currency;
use MoneyField;
Expand Down Expand Up @@ -75,6 +76,7 @@ public function Nice($options = array()) {
}

/**
* @param array $options
* @return string
*/
public function NiceWithShortname($options = array()){
Expand All @@ -83,6 +85,7 @@ public function NiceWithShortname($options = array()){
}

/**
* @param array $options
* @return string
*/
public function NiceWithName($options = array()){
Expand All @@ -98,7 +101,8 @@ public function getCurrency() {
}

/**
* @param string
* @param string $currency
* @param bool $markChanged
*/
public function setCurrency($currency, $markChanged = true) {
$this->setField('Currency', $currency, $markChanged);
Expand All @@ -113,6 +117,7 @@ public function getAmount() {

/**
* @param float $amount
* @param bool $markChanged
*/
public function setAmount($amount, $markChanged = true) {
$this->setField('Amount', (float)$amount, $markChanged);
Expand Down Expand Up @@ -149,6 +154,8 @@ public function getLocale() {
}

/**
* @param string $currency
* @param string $locale
* @return string
*/
public function getSymbol($currency = null, $locale = null) {
Expand All @@ -160,6 +167,8 @@ public function getSymbol($currency = null, $locale = null) {
}

/**
* @param string $currency
* @param string $locale
* @return string
*/
public function getShortName($currency = null, $locale = null) {
Expand All @@ -170,6 +179,8 @@ public function getShortName($currency = null, $locale = null) {
}

/**
* @param string $currency
* @param string $locale
* @return string
*/
public function getCurrencyName($currency = null, $locale = null) {
Expand Down
2 changes: 2 additions & 0 deletions ORM/FieldType/DBMultiEnum.php
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\ORM\FieldType;

use CheckboxSetField;
use Config;
use SilverStripe\ORM\DB;

/**
Expand Down Expand Up @@ -31,6 +32,7 @@ public function __construct($name, $enum = NULL, $default = NULL) {
}

public function requireField(){
// @todo: Remove mysql-centric logic from this
$charset = Config::inst()->get('SilverStripe\ORM\Connect\MySQLDatabase', 'charset');
$collation = Config::inst()->get('SilverStripe\ORM\Connect\MySQLDatabase', 'collation');
$values=array(
Expand Down
3 changes: 3 additions & 0 deletions ORM/FieldType/DBPercentage.php
Expand Up @@ -20,6 +20,9 @@ class DBPercentage extends DBDecimal {

/**
* Create a new Decimal field.
*
* @param string $name
* @param int $precision
*/
public function __construct($name = null, $precision = 4) {
if(!$precision) $precision = 4;
Expand Down

0 comments on commit efef025

Please sign in to comment.