From efef0250277b83484536546763931c6646cb852d Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 1 Jul 2016 14:26:18 +1200 Subject: [PATCH] BUG Fix missing use statements 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 --- ORM/Connect/DBSchemaManager.php | 15 ++++++++------- ORM/Connect/Database.php | 6 +++--- ORM/DB.php | 1 + ORM/FieldType/DBComposite.php | 9 +++++---- ORM/FieldType/DBCurrency.php | 12 ------------ ORM/FieldType/DBDate.php | 16 ++++++++++------ ORM/FieldType/DBDatetime.php | 8 ++++---- ORM/FieldType/DBDecimal.php | 3 ++- ORM/FieldType/DBEnum.php | 5 +++-- ORM/FieldType/DBField.php | 7 ++++++- ORM/FieldType/DBForeignKey.php | 2 ++ ORM/FieldType/DBMoney.php | 13 ++++++++++++- ORM/FieldType/DBMultiEnum.php | 2 ++ ORM/FieldType/DBPercentage.php | 3 +++ ORM/FieldType/DBPrimaryKey.php | 2 +- ORM/FieldType/DBString.php | 3 +-- ORM/FieldType/DBText.php | 10 ++++++---- ORM/FieldType/DBVarchar.php | 7 +++---- ORM/FieldType/DBYear.php | 4 ++-- 19 files changed, 74 insertions(+), 54 deletions(-) diff --git a/ORM/Connect/DBSchemaManager.php b/ORM/Connect/DBSchemaManager.php index 84d365c83..bc390e1ef 100644 --- a/ORM/Connect/DBSchemaManager.php +++ b/ORM/Connect/DBSchemaManager.php @@ -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; @@ -127,6 +127,7 @@ abstract class DBSchemaManager { // Clear update list for client code to mess around with $this->schemaUpdateTransaction = array(); + /** @var Exception $error */ $error = null; try { @@ -302,8 +303,8 @@ abstract class DBSchemaManager { * - 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 @@ -539,6 +540,7 @@ abstract class DBSchemaManager { * @see parseIndexSpec() for approximate inverse * * @param string|array $indexSpec + * @return string */ protected function convertIndexSpec($indexSpec) { // Return already converted spec @@ -551,7 +553,7 @@ abstract class DBSchemaManager { /** * 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); @@ -879,7 +881,7 @@ abstract class DBSchemaManager { * @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. */ @@ -940,8 +942,7 @@ abstract class DBSchemaManager { * 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) { diff --git a/ORM/Connect/Database.php b/ORM/Connect/Database.php index 976d823e8..e8361d29b 100644 --- a/ORM/Connect/Database.php +++ b/ORM/Connect/Database.php @@ -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; @@ -560,7 +560,7 @@ abstract class SS_Database { * @return boolean Flag indicating support for all of the above * @todo Write test cases */ - protected function supportsExtensions($extensions) { + public function supportsExtensions($extensions) { return false; } diff --git a/ORM/DB.php b/ORM/DB.php index a73302c71..586cfdd6c 100644 --- a/ORM/DB.php +++ b/ORM/DB.php @@ -9,6 +9,7 @@ use Config; use LogicException; use Cookie; use Injector; +use SilverStripe\ORM\Connect\DBSchemaManager; use SilverStripe\ORM\Queries\SQLExpression; use SilverStripe\ORM\Connect\SS_Database; diff --git a/ORM/FieldType/DBComposite.php b/ORM/FieldType/DBComposite.php index c5d2f2b26..ecb9584d2 100644 --- a/ORM/FieldType/DBComposite.php +++ b/ORM/FieldType/DBComposite.php @@ -5,6 +5,7 @@ namespace SilverStripe\ORM\FieldType; use Object; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DB; +use SilverStripe\ORM\Queries\SQLSelect; /** @@ -127,7 +128,7 @@ abstract class DBComposite extends DBField { 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); } } @@ -239,7 +240,8 @@ abstract class DBComposite extends DBField { // 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 @@ -272,8 +274,7 @@ abstract class DBComposite extends DBField { return $fields[$field]; } - - parent::castingHelper($field); + return parent::castingHelper($field); } } diff --git a/ORM/FieldType/DBCurrency.php b/ORM/FieldType/DBCurrency.php index 6c673b954..52bd543f1 100644 --- a/ORM/FieldType/DBCurrency.php +++ b/ORM/FieldType/DBCurrency.php @@ -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} @@ -63,15 +61,5 @@ class DBCurrency extends DBDecimal { $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; - } } diff --git a/ORM/FieldType/DBDate.php b/ORM/FieldType/DBDate.php index 1857d811b..f6e552034 100644 --- a/ORM/FieldType/DBDate.php +++ b/ORM/FieldType/DBDate.php @@ -67,7 +67,7 @@ class DBDate extends DBField { } 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; @@ -120,7 +120,7 @@ class DBDate extends DBField { /** * 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) { @@ -154,7 +154,7 @@ class DBDate extends DBField { public function Format($format) { if($this->value){ $date = new DateTime($this->value); - return $date->Format($format); + return $date->format($format); } } @@ -163,6 +163,9 @@ class DBDate extends DBField { * * 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) { @@ -192,10 +195,11 @@ class DBDate extends DBField { 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) { diff --git a/ORM/FieldType/DBDatetime.php b/ORM/FieldType/DBDatetime.php index 468271b3a..a924b19db 100644 --- a/ORM/FieldType/DBDatetime.php +++ b/ORM/FieldType/DBDatetime.php @@ -3,6 +3,7 @@ namespace SilverStripe\ORM\FieldType; use Convert; +use Exception; use Member; use DatetimeField; use Zend_Date; @@ -59,12 +60,11 @@ class DBDatetime extends DBDate implements TemplateGlobalProvider { 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; } diff --git a/ORM/FieldType/DBDecimal.php b/ORM/FieldType/DBDecimal.php index db5a6172c..79476e494 100644 --- a/ORM/FieldType/DBDecimal.php +++ b/ORM/FieldType/DBDecimal.php @@ -3,6 +3,7 @@ namespace SilverStripe\ORM\FieldType; use NumericField; +use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DB; /** @@ -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; diff --git a/ORM/FieldType/DBEnum.php b/ORM/FieldType/DBEnum.php index 2906e895b..1f55c1de7 100644 --- a/ORM/FieldType/DBEnum.php +++ b/ORM/FieldType/DBEnum.php @@ -50,9 +50,10 @@ class DBEnum extends DBString { * "MyField" => "Enum(array('Val1', 'Val2', 'Val3'), 'Val1')" * * - * @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) { diff --git a/ORM/FieldType/DBField.php b/ORM/FieldType/DBField.php index 4bb8f3a54..0d47866b8 100644 --- a/ORM/FieldType/DBField.php +++ b/ORM/FieldType/DBField.php @@ -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; @@ -151,7 +155,7 @@ abstract class DBField extends ViewableData { * * @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. */ @@ -348,6 +352,7 @@ abstract class DBField extends ViewableData { * 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) { diff --git a/ORM/FieldType/DBForeignKey.php b/ORM/FieldType/DBForeignKey.php index 5f34efc37..5824ad35e 100644 --- a/ORM/FieldType/DBForeignKey.php +++ b/ORM/FieldType/DBForeignKey.php @@ -2,6 +2,8 @@ namespace SilverStripe\ORM\FieldType; +use File; +use Image; use UploadField; use DropdownField; use NumericField; diff --git a/ORM/FieldType/DBMoney.php b/ORM/FieldType/DBMoney.php index ef3a9cfa0..375f85092 100644 --- a/ORM/FieldType/DBMoney.php +++ b/ORM/FieldType/DBMoney.php @@ -2,6 +2,7 @@ namespace SilverStripe\ORM\FieldType; +use FormField; use i18n; use Zend_Currency; use MoneyField; @@ -75,6 +76,7 @@ class DBMoney extends DBComposite { } /** + * @param array $options * @return string */ public function NiceWithShortname($options = array()){ @@ -83,6 +85,7 @@ class DBMoney extends DBComposite { } /** + * @param array $options * @return string */ public function NiceWithName($options = array()){ @@ -98,7 +101,8 @@ class DBMoney extends DBComposite { } /** - * @param string + * @param string $currency + * @param bool $markChanged */ public function setCurrency($currency, $markChanged = true) { $this->setField('Currency', $currency, $markChanged); @@ -113,6 +117,7 @@ class DBMoney extends DBComposite { /** * @param float $amount + * @param bool $markChanged */ public function setAmount($amount, $markChanged = true) { $this->setField('Amount', (float)$amount, $markChanged); @@ -149,6 +154,8 @@ class DBMoney extends DBComposite { } /** + * @param string $currency + * @param string $locale * @return string */ public function getSymbol($currency = null, $locale = null) { @@ -160,6 +167,8 @@ class DBMoney extends DBComposite { } /** + * @param string $currency + * @param string $locale * @return string */ public function getShortName($currency = null, $locale = null) { @@ -170,6 +179,8 @@ class DBMoney extends DBComposite { } /** + * @param string $currency + * @param string $locale * @return string */ public function getCurrencyName($currency = null, $locale = null) { diff --git a/ORM/FieldType/DBMultiEnum.php b/ORM/FieldType/DBMultiEnum.php index 4cd7475a1..ea9efd42f 100644 --- a/ORM/FieldType/DBMultiEnum.php +++ b/ORM/FieldType/DBMultiEnum.php @@ -3,6 +3,7 @@ namespace SilverStripe\ORM\FieldType; use CheckboxSetField; +use Config; use SilverStripe\ORM\DB; /** @@ -31,6 +32,7 @@ class DBMultiEnum extends DBEnum { } 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( diff --git a/ORM/FieldType/DBPercentage.php b/ORM/FieldType/DBPercentage.php index 386c6f3a1..5f974ba64 100644 --- a/ORM/FieldType/DBPercentage.php +++ b/ORM/FieldType/DBPercentage.php @@ -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; diff --git a/ORM/FieldType/DBPrimaryKey.php b/ORM/FieldType/DBPrimaryKey.php index 312d6e5c7..44ca89630 100644 --- a/ORM/FieldType/DBPrimaryKey.php +++ b/ORM/FieldType/DBPrimaryKey.php @@ -43,7 +43,7 @@ class DBPrimaryKey extends DBInt { /** * @param string $name - * @param DataOject $object The object that this is primary key for (should have a relation with $name) + * @param DataObject $object The object that this is primary key for (should have a relation with $name) */ public function __construct($name, $object = null) { $this->object = $object; diff --git a/ORM/FieldType/DBString.php b/ORM/FieldType/DBString.php index 2e8bf0067..fd6018960 100644 --- a/ORM/FieldType/DBString.php +++ b/ORM/FieldType/DBString.php @@ -49,14 +49,13 @@ abstract class DBString extends DBField { /** * Update the optional parameters for this field. - * @param $options array of options + * @param array $options array of options * The options allowed are: * - * @return unknown_type */ public function setOptions(array $options = array()) { if(array_key_exists("nullifyEmpty", $options)) { diff --git a/ORM/FieldType/DBText.php b/ORM/FieldType/DBText.php index 47a6a34e6..d753590bc 100644 --- a/ORM/FieldType/DBText.php +++ b/ORM/FieldType/DBText.php @@ -63,7 +63,7 @@ class DBText extends DBString { 'parts' => $parts ); - DB::require_field($this->tableName, $this->name, $values, $this->default); + DB::require_field($this->tableName, $this->name, $values); } /** @@ -78,6 +78,7 @@ class DBText extends DBString { * Limit sentences, can be controlled by passing an integer. * * @param int $sentCount The amount of sentences you want. + * @return string */ public function LimitSentences($sentCount = 2) { if(!is_numeric($sentCount)) { @@ -209,7 +210,7 @@ class DBText extends DBString { // get first sentence? // this needs to be more robust if($plain && $plain != 'html') { - $data = Convert::xml2raw($this->value, true); + $data = Convert::xml2raw($this->value); if(!$data) return ""; // grab the first paragraph, or, failing that, the whole content @@ -238,8 +239,8 @@ class DBText extends DBString { * @param boolean $string Supplied string ("keywords") * @param boolean $striphtml Strip HTML? * @param boolean $highlight Add a highlight element around search query? - * @param String prefix text - * @param String suffix + * @param string $prefix text + * @param string $suffix * * @return string */ @@ -293,6 +294,7 @@ class DBText extends DBString { * Allows a sub-class of TextParser to be rendered. * * @see TextParser for implementation details. + * @param string $parser * @return string */ public function Parse($parser = "TextParser") { diff --git a/ORM/FieldType/DBVarchar.php b/ORM/FieldType/DBVarchar.php index add2a7fe2..ef8645629 100644 --- a/ORM/FieldType/DBVarchar.php +++ b/ORM/FieldType/DBVarchar.php @@ -29,11 +29,10 @@ class DBVarchar extends DBString { /** * Construct a new short text field * - * @param $name string The name of the field - * @param $size int The maximum size of the field, in terms of characters - * @param $options array Optional parameters, e.g. array("nullifyEmpty"=>false). + * @param string $name The name of the field + * @param int $size The maximum size of the field, in terms of characters + * @param array $options Optional parameters, e.g. array("nullifyEmpty"=>false). * See {@link StringField::setOptions()} for information on the available options - * @return unknown_type */ public function __construct($name = null, $size = 50, $options = array()) { $this->size = $size ? $size : 50; diff --git a/ORM/FieldType/DBYear.php b/ORM/FieldType/DBYear.php index 812c58cd0..9e4785f53 100644 --- a/ORM/FieldType/DBYear.php +++ b/ORM/FieldType/DBYear.php @@ -36,8 +36,8 @@ class DBYear extends DBField { * input values. Starts by default at the current year, * and counts back to 1900. * - * @param int $start starting date to count down from - * @param int $end end date to count down to + * @param int|bool $start starting date to count down from + * @param int|bool $end end date to count down to * @return array */ private function getDefaultOptions($start=false, $end=false) {