diff --git a/.editorconfig b/.editorconfig index 347aa2f..ee325e2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,7 +13,7 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false -[*.{yml,js,json,css,scss,eslintrc,feature}] +[*.{yml,js,json,css,scss,feature}] indent_size = 2 indent_style = space @@ -21,11 +21,6 @@ indent_style = space indent_size = 4 # Don't perform any clean-up on thirdparty files - [thirdparty/**] trim_trailing_whitespace = false insert_final_newline = false - -[admin/thirdparty/**] -trim_trailing_whitespace = false -insert_final_newline = false diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..acbf450 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,21 @@ + + + CodeSniffer ruleset for SilverStripe coding conventions. + + src + tests + + + + + + + + + + + + + + + diff --git a/src/ArrayBulkLoaderSource.php b/src/ArrayBulkLoaderSource.php index 6d02140..00f76d9 100755 --- a/src/ArrayBulkLoaderSource.php +++ b/src/ArrayBulkLoaderSource.php @@ -11,11 +11,8 @@ class ArrayBulkLoaderSource extends BulkLoaderSource { - protected $data; - - public function __construct($data) + public function __construct(protected $data) { - $this->data = $data; } public function getIterator(): ArrayIterator @@ -23,7 +20,7 @@ public function getIterator(): ArrayIterator return new ArrayIterator($this->data); } - public function setData($data) + public function setData($data): static { $this->data = $data; diff --git a/src/BulkLoader.php b/src/BulkLoader.php index 6e5c642..efb57c0 100644 --- a/src/BulkLoader.php +++ b/src/BulkLoader.php @@ -2,6 +2,7 @@ namespace AntonyThorpe\Consumer; +use SilverStripe\ORM\DataList; use SilverStripe\Core\Environment; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\ORM\ValidationException; @@ -28,13 +29,13 @@ class BulkLoader extends \SilverStripe\Dev\BulkLoader * Can include dot notations. * @var array */ - public $mappableFields = array(); + public $mappableFields = []; /** * Transformation and relation handling * @var array */ - public $transforms = array(); + public $transforms = []; /** * Specify a colsure to be run on every imported record. @@ -80,7 +81,6 @@ class BulkLoader extends \SilverStripe\Dev\BulkLoader /** * Set the BulkLoaderSource for this BulkLoader. - * @param BulkLoaderSource $source */ public function setSource(BulkLoaderSource $source) { @@ -90,7 +90,7 @@ public function setSource(BulkLoaderSource $source) /** * Get the BulkLoaderSource for this BulkLoader - * @return \AntonyThorpe\Consumer\BulkLoaderSource $source + * @return BulkLoaderSource $source */ public function getSource() { @@ -133,14 +133,14 @@ public function setPublishPages($dopubilsh) /** * Delete all existing records */ - public function deleteExistingRecords() + public function deleteExistingRecords(): void { DataObject::get($this->objectClass)->removeAll(); } /** * Get the DataList of objects this loader applies to. - * @return \SilverStripe\ORM\DataList + * @return DataList */ public function getDataList() { @@ -166,7 +166,7 @@ public function preview($filepath) * Start loading of data * @param string $filepath * @param boolean $preview Create results but don't write - * @return \AntonyThorpe\Consumer\BulkLoaderResult + * @return BulkLoaderResult */ public function load($filepath = null, $preview = false) { @@ -181,7 +181,7 @@ public function load($filepath = null, $preview = false) * Import all records from the source * @param string $filepath * @param boolean $preview - * @return \AntonyThorpe\Consumer\BulkLoaderResult + * @return BulkLoaderResult */ protected function processAll($filepath, $preview = false) { @@ -191,7 +191,7 @@ protected function processAll($filepath, $preview = false) E_USER_WARNING ); } - $results = new BulkLoaderResult(); + $results = BulkLoaderResult::create(); $iterator = $this->getSource()->getIterator(); foreach ($iterator as $record) { $this->processRecord($record, $this->columnMap, $results, $preview); @@ -208,13 +208,13 @@ protected function processAll($filepath, $preview = false) * @param boolean $preview * @param BulkLoaderResult $results * @param string $preview set to true to prevent writing to the dataobject - * @return \AntonyThorpe\Consumer\BulkLoaderResult + * @return BulkLoaderResult */ protected function processRecord($record, $columnMap, &$results, $preview = false) { - if (!is_array($record) || empty($record) || !array_filter($record)) { + if (!is_array($record) || $record === [] || !array_filter($record)) { $results->addSkipped("Empty/invalid record data."); - return; + return null; } //map incoming record according to the standardisation mapping (columnMap) @@ -222,13 +222,13 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals //skip if required data is not present if (!$this->hasRequiredData($record)) { $results->addSkipped("Required data is missing."); - return; + return null; } $modelClass = $this->objectClass; $placeholder = new $modelClass(); //populate placeholder object with transformed data - foreach ($this->mappableFields_cache as $field => $label) { + foreach (array_keys($this->mappableFields_cache) as $field) { //skip empty fields if (!isset($record[$field]) || empty($record[$field])) { continue; @@ -240,7 +240,7 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals $existing = null; $data = $placeholder->getQueriedDatabaseFields(); - if (!$placeholder->ID && !empty($this->duplicateChecks)) { + if (!$placeholder->ID && $this->duplicateChecks !== []) { $mapped_values = array_values($this->columnMap); //don't match on ID, ClassName or RecordClassName unset($data['ID'], $data['ClassName'], $data['RecordClassName']); @@ -264,7 +264,7 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals // new record if (!$this->addNewRecords) { $results->addSkipped('New record not added'); - return; + return null; } $obj = $placeholder; } @@ -291,10 +291,8 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals if (!$preview) { $obj->write(); - if ($obj instanceof SiteTree) { - if ($obj->isPublished() || $this->publishPages) { - $obj->publish('Stage', 'Live'); - } + if ($obj instanceof SiteTree && ($obj->isPublished() || $this->publishPages)) { + $obj->publish('Stage', 'Live'); } $obj->flushCache(); // avoid relation caching confusion @@ -323,7 +321,7 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals protected function columnMapRecord($record) { $adjustedmap = $this->columnMap; - $newrecord = array(); + $newrecord = []; foreach ($record as $field => $value) { if (isset($adjustedmap[$field])) { $newrecord[$adjustedmap[$field]] = $value; @@ -342,12 +340,11 @@ protected function columnMapRecord($record) */ protected function hasRequiredData($mappedrecord) { - if (!is_array($mappedrecord) || empty($mappedrecord) || !array_filter($mappedrecord)) { + if (!is_array($mappedrecord) || $mappedrecord === [] || !array_filter($mappedrecord)) { return false; } foreach ($this->transforms as $field => $t) { - if ( - is_array($t) && + if (is_array($t) && isset($t['required']) && $t['required'] === true && (!isset($mappedrecord[$field]) || @@ -361,11 +358,10 @@ protected function hasRequiredData($mappedrecord) /** * Perform field transformation or setting of data on placeholder. - * @param \SilverStripe\ORM\DataObject $placeholder + * @param DataObject $placeholder * @param string $field - * @param mixed $value */ - protected function transformField($placeholder, $field, $value) + protected function transformField($placeholder, $field, mixed $value) { $callback = isset($this->transforms[$field]['callback']) && is_callable($this->transforms[$field]['callback']) ? @@ -376,17 +372,13 @@ protected function transformField($placeholder, $field, $value) $relationName = null; $columnName = null; //extract relationName and columnName, if present - if (strpos($field, '.') !== false) { - list($relationName, $columnName) = explode('.', $field); + if (str_contains($field, '.')) { + [$relationName, $columnName] = explode('.', $field); } else { $relationName = $field; } //get the list that relation is added to/checked on - if (isset($this->transforms[$field]['list'])) { - $relationlist = $this->transforms[$field]['list']; - } else { - $relationlist = null; - } + $relationlist = isset($this->transforms[$field]['list']) ? $this->transforms[$field]['list'] : null; //check for the same relation set on the current record if ($placeholder->{$relationName."ID"}) { @@ -437,7 +429,7 @@ protected function transformField($placeholder, $field, $value) if ($relationlist && !$relationlist->byID($relation->ID)) { $relationlist->add($relation); } - } catch (ValidationException $e) { + } catch (ValidationException) { $relation = null; } //add the relation id to the placeholder @@ -451,9 +443,9 @@ protected function transformField($placeholder, $field, $value) $value = $callback($value, $placeholder); } //set field value - $placeholder->update(array( + $placeholder->update([ $field => $value - )); + ]); } } @@ -465,8 +457,8 @@ protected function transformField($placeholder, $field, $value) protected function isRelation($field) { //get relation name from dot notation - if (strpos($field, '.') !== false) { - list($field, $columnName) = explode('.', $field); + if (str_contains($field, '.')) { + [$field, $columnName] = explode('.', $field); } $has_ones = singleton($this->objectClass)->hasOne(); //check if relation is present in has ones @@ -485,8 +477,8 @@ protected function getRelationName($recordField) if (isset($this->relationCallbacks[$recordField])) { $relationName = $this->relationCallbacks[$recordField]['relationname']; } - if (strpos($recordField, '.') !== false) { - list($relationName, $columnName) = explode('.', $recordField); + if (str_contains((string) $recordField, '.')) { + [$relationName, $columnName] = explode('.', (string) $recordField); } return $relationName; @@ -498,7 +490,7 @@ protected function getRelationName($recordField) * @param array $record data * @return mixed */ - public function findExistingObject($record) + public function findExistingObject(array $record) { // checking for existing records (only if not already found) foreach ($this->duplicateChecks as $fieldName => $duplicateCheck) { @@ -506,8 +498,8 @@ public function findExistingObject($record) if (is_string($duplicateCheck)) { $fieldName = $duplicateCheck; //If the dupilcate check is a dot notation, then convert to ID relation - if (strpos($duplicateCheck, '.') !== false) { - list($relationName, $columnName) = explode('.', $duplicateCheck); + if (str_contains($duplicateCheck, '.')) { + [$relationName, $columnName] = explode('.', $duplicateCheck); $fieldName = $relationName."ID"; } //@todo also convert plain relation names to include ID @@ -548,11 +540,11 @@ public function findExistingObject($record) */ public function getMappableColumns() { - if (!empty($this->mappableFields)) { + if ($this->mappableFields !== []) { return $this->mappableFields; } $scaffolded = $this->scaffoldMappableFields(); - if (!empty($this->transforms)) { + if ($this->transforms !== []) { $transformables = array_keys($this->transforms); $transformables = array_combine($transformables, $transformables); $scaffolded = array_merge($transformables, $scaffolded); @@ -571,14 +563,12 @@ public function scaffoldMappableFields($includerelations = true) { $map = $this->getMappableFieldsForClass($this->objectClass); //set up 'dot notation' (Relation.Field) style mappings - if ($includerelations) { - if ($has_ones = singleton($this->objectClass)->hasOne()) { - foreach ($has_ones as $relationship => $type) { - $fields = $this->getMappableFieldsForClass($type); - foreach ($fields as $field => $title) { - $map[$relationship.".".$field] = - $this->formatMappingFieldLabel($relationship, $title); - } + if ($includerelations && ($has_ones = singleton($this->objectClass)->hasOne())) { + foreach ($has_ones as $relationship => $type) { + $fields = $this->getMappableFieldsForClass($type); + foreach ($fields as $field => $title) { + $map[$relationship.".".$field] = + $this->formatMappingFieldLabel($relationship, $title); } } } @@ -595,7 +585,7 @@ protected function getMappableFieldsForClass($class) { $singleton = singleton($class); $fields = (array)$singleton->fieldLabels(false); - foreach ($fields as $field => $label) { + foreach (array_keys($fields) as $field) { if (!$singleton->hasField($field)) { unset($fields[$field]); } @@ -616,7 +606,7 @@ protected function formatMappingFieldLabel($relationship, $title) /** * Check that the class has the required settings */ - public function preprocessChecks() + public function preprocessChecks(): void { // Checks if (!$this->objectClass) { @@ -645,13 +635,11 @@ public function preprocessChecks() * * @param array $apidata An array of arrays * @param boolean $preview Set to true to not write - * @return \AntonyThorpe\Consumer\BulkLoaderResult + * @return BulkLoaderResult */ public function updateRecords(array $apidata, $preview = false) { - if (is_array($apidata)) { - $this->setSource(new ArrayBulkLoaderSource($apidata)); - } + $this->setSource(new ArrayBulkLoaderSource($apidata)); $this->addNewRecords = false; $this->preprocessChecks(); return $this->load(null, $preview); @@ -660,15 +648,12 @@ public function updateRecords(array $apidata, $preview = false) /** * Update/create many dataobjects with data from the external api * - * @param array $apidata * @param boolean $preview Set to true to not write * @return BulkLoaderResult */ public function upsertManyRecords(array $apidata, $preview = false) { - if (is_array($apidata)) { - $this->setSource(new ArrayBulkLoaderSource($apidata)); - } + $this->setSource(new ArrayBulkLoaderSource($apidata)); $this->preprocessChecks(); return $this->load(null, $preview); } @@ -676,18 +661,15 @@ public function upsertManyRecords(array $apidata, $preview = false) /** * Delete dataobjects that match to the API data * - * @param array $apidata * @param boolean $preview Set to true to not write - * @return \AntonyThorpe\Consumer\BulkLoaderResult + * @return BulkLoaderResult */ public function deleteManyRecords(array $apidata, $preview = false) { - if (is_array($apidata)) { - $this->setSource(new ArrayBulkLoaderSource($apidata)); - } + $this->setSource(new ArrayBulkLoaderSource($apidata)); $this->preprocessChecks(); $this->mappableFields_cache = $this->getMappableColumns(); - $results = new BulkLoaderResult(); + $results = BulkLoaderResult::create(); $iterator = $this->getSource()->getIterator(); foreach ($iterator as $record) { //map incoming record according to the standardisation mapping (columnMap) @@ -698,7 +680,7 @@ public function deleteManyRecords(array $apidata, $preview = false) $placeholder = new $modelClass(); //populate placeholder object with transformed data - foreach ($this->mappableFields_cache as $field => $label) { + foreach (array_keys($this->mappableFields_cache) as $field) { //skip empty fields if (!isset($record[$field]) || empty($record[$field])) { continue; @@ -728,11 +710,11 @@ public function deleteManyRecords(array $apidata, $preview = false) * @param string $key The key that matches the column within the Object Class * @param string $property_name The property name of the class that matches to the key from the API data * @param boolean $preview Set to true to not save - * @return \AntonyThorpe\Consumer\BulkLoaderResult + * @return BulkLoaderResult */ public function clearAbsentRecords(array $apidata, $key, $property_name, $preview = false) { - $results = new BulkLoaderResult(); + $results = BulkLoaderResult::create(); $modelClass = $this->objectClass; foreach ($modelClass::get() as $record) { @@ -741,12 +723,10 @@ public function clearAbsentRecords(array $apidata, $key, $property_name, $previe if (!empty($property_value)) { $match = array_filter( $apidata, - function ($value) use ($key, $property_value) { - return $value[$key] == $property_value; - } + fn($value): bool => $value[$key] == $property_value ); - if (empty($match)) { // The property value doesn't exist in the API data (therefore clear) + if ($match === []) { // The property value doesn't exist in the API data (therefore clear) $record->{$property_name} = ""; $results->addUpdated($record, _t('Consumer.CLEARABSENT', 'Clear absent'), $this->duplicateChecks); if (!$preview) { diff --git a/src/BulkLoaderResult.php b/src/BulkLoaderResult.php index b4d806a..902a5f3 100644 --- a/src/BulkLoaderResult.php +++ b/src/BulkLoaderResult.php @@ -2,24 +2,23 @@ namespace AntonyThorpe\Consumer; +use SilverStripe\Dev\BulkLoader_Result; +use SilverStripe\ORM\DataObject; use SilverStripe\ORM\ArrayList; use SilverStripe\View\ArrayData; /** * Store result information about a BulkLoader import */ -class BulkLoaderResult extends \SilverStripe\Dev\BulkLoader_Result +class BulkLoaderResult extends BulkLoader_Result { /** * Keep track of skipped records. * @var array */ - protected $skipped = array(); + protected $skipped = []; - /** - * @return int - */ - public function SkippedCount() + public function SkippedCount(): int { return count($this->skipped); } @@ -28,46 +27,46 @@ public function SkippedCount() /** * @param string $message Reason for skipping */ - public function addSkipped($message = null) + public function addSkipped($message = null): void { - $this->skipped[] = array( + $this->skipped[] = [ 'Message' => $message - ); + ]; } /** * Get an array of messages describing the result. * @return array messages */ - public function getMessageList() + public function getMessageList(): array { - $output = array(); + $output = []; if ($this->CreatedCount()) { $output['created'] = _t( 'SilverStripe\\Dev\\BulkLoader.IMPORTEDRECORDS', "Imported {count} new records.", - array('count' => $this->CreatedCount()) + ['count' => $this->CreatedCount()] ); } if ($this->UpdatedCount()) { $output['updated'] = _t( 'SilverStripe\\Dev\\BulkLoader.UPDATEDRECORDS', "Updated {count} records.", - array('count' => $this->UpdatedCount()) + ['count' => $this->UpdatedCount()] ); } if ($this->DeletedCount()) { $output['deleted'] = _t( 'SilverStripe\\Dev\\BulkLoader.DELETEDRECORDS', "Deleted {count} records.", - array('count' => $this->DeletedCount()) + ['count' => $this->DeletedCount()] ); } - if ($this->SkippedCount()) { + if ($this->SkippedCount() !== 0) { $output['skipped'] = _t( 'SilverStripe\\Dev\\BulkLoader.SKIPPEDRECORDS', "Skipped {count} bad records.", - array('count' => $this->SkippedCount()) + ['count' => $this->SkippedCount()] ); } @@ -80,24 +79,22 @@ public function getMessageList() /** * Genenrate a human-readable result message. - * @return string */ - public function getMessage() + public function getMessage(): string { return implode("\n", $this->getMessageList()); } /** * Provide a useful message type, based on result. - * @return string */ - public function getMessageType() + public function getMessageType(): string { $type = "bad"; - if ($this->Count()) { + if ($this->Count() !== 0) { $type = "good"; } - if ($this->SkippedCount()) { + if ($this->SkippedCount() !== 0) { $type= "warning"; } @@ -107,7 +104,7 @@ public function getMessageType() /** * Returns all created objects. Each object might * contain specific importer feedback in the "_BulkLoaderMessage" property. - * @return \SilverStripe\ORM\ArrayList + * @return ArrayList */ public function getCreated() { @@ -116,12 +113,10 @@ public function getCreated() /** * Return all updated objects - * - * @return \SilverStripe\ORM\ArrayList */ - public function getUpdated() + public function getUpdated(): ArrayList { - $set = new ArrayList(); + $set = ArrayList::create(); foreach ($this->updated as $arrItem) { $set->push(ArrayData::create($arrItem)); } @@ -130,11 +125,10 @@ public function getUpdated() /** * Return all deleted objects - * @return \SilverStripe\ORM\ArrayList */ - public function getDeleted() + public function getDeleted(): ArrayList { - $set = new ArrayList(); + $set = ArrayList::create(); foreach ($this->deleted as $arrItem) { $set->push(ArrayData::create($arrItem)); } @@ -143,53 +137,52 @@ public function getDeleted() /** * Prepare the boby for an email or build task - * @return \SilverStripe\ORM\ArrayList */ - public function getData() + public function getData(): ArrayList { - $data = new ArrayList(); + $data = ArrayList::create(); if ($this->CreatedCount()) { - $data->push(ArrayData::create(array("Title" => _t('Consumer.CREATED', 'Created')))); + $data->push(ArrayData::create(["Title" => _t('Consumer.CREATED', 'Created')])); $data->merge($this->getCreated()); } if ($this->UpdatedCount()) { - $data->push(ArrayData::create(array("Title" => _t('Consumer.UPDATED', 'Updated')))); + $data->push(ArrayData::create(["Title" => _t('Consumer.UPDATED', 'Updated')])); $data->merge($this->getUpdated()); } if ($this->DeletedCount()) { - $data->push(ArrayData::create(array("Title" => _t('Consumer.DELETED', 'Deleted')))); + $data->push(ArrayData::create(["Title" => _t('Consumer.DELETED', 'Deleted')])); $data->merge($this->$this->getDeleted()); } return $data; } /** - * @param \SilverStripe\ORM\DataObject $obj + * @param DataObject $obj * @param string $message */ - public function addCreated($obj, $message = null) + public function addCreated($obj, $message = null): void { $this->created[] = $this->lastChange = $this->createResult($obj, $message); $this->lastChange['ChangeType'] = 'created'; } /** - * @param \SilverStripe\ORM\DataObject $obj + * @param DataObject $obj * @param string $message */ - public function addUpdated($obj, $message = null, $additionalFields = null) + public function addUpdated($obj, $message = null, $additionalFields = null): void { if ($changedFields = $this->getChangedFields($obj)) { // create additional fields to include with results - $extra_data = array(); + $extra_data = []; foreach ($additionalFields as $field) { $extra_data[$field] = $obj->{$field}; } $extra_data['_ChangedFields'] = $changedFields; - $base = array( + $base = [ 'ID' => $obj->ID, 'ClassName' => $obj->class - ); + ]; if ($message) { $base['Message'] = $message; } @@ -203,7 +196,7 @@ public function addUpdated($obj, $message = null, $additionalFields = null) /** * Modelled on the getChangedFields of DataObject, with the addition of the variable's type - * @param \SilverStripe\ORM\DataObject $obj + * @param DataObject $obj * @return array The before/after changes of each field */ protected function getChangedFields($obj) @@ -218,10 +211,10 @@ protected function getChangedFields($obj) } /** - * @param \SilverStripe\ORM\DataObject $obj + * @param DataObject $obj * @param string $message */ - public function addDeleted($obj, $message = null) + public function addDeleted($obj, $message = null): void { $this->deleted[] = $this->lastChange = $this->createResult($obj, $message); $this->lastChange['ChangeType'] = 'deleted'; @@ -229,7 +222,7 @@ public function addDeleted($obj, $message = null) /** * Create the Result for Deleted and Created items - * @param \SilverStripe\ORM\DataObject $obj + * @param DataObject $obj * @param String $message * @return array */ @@ -242,11 +235,11 @@ protected function createResult($obj, $message) /** * @param $arr array Either the created, updated or deleted items - * @return \SilverStripe\ORM\ArrayList + * @return ArrayList */ protected function mapToArrayList($arr) { - $set = new ArrayList(); + $set = ArrayList::create(); foreach ($arr as $arrItem) { $set->push(ArrayData::create($arrItem)); } diff --git a/src/BulkLoaderSource.php b/src/BulkLoaderSource.php index d356d33..02fefd6 100755 --- a/src/BulkLoaderSource.php +++ b/src/BulkLoaderSource.php @@ -17,7 +17,6 @@ abstract class BulkLoaderSource implements IteratorAggregate /** * Provide iterator for bulk loading from. * Records are expected to be 1 dimensional key-value arrays. - * @return ArrayIterator */ abstract public function getIterator(): ArrayIterator; } diff --git a/src/Consumer.php b/src/Consumer.php index 043d968..0b50776 100644 --- a/src/Consumer.php +++ b/src/Consumer.php @@ -11,22 +11,25 @@ */ class Consumer extends DataObject { - private static $table_name = 'Consumer'; + /** + * @config + */ + private static string $table_name = 'Consumer'; /** * Save the maximum data using setExternalLastEdited method. Can use it to filter future calls to the API. - * @var array + * @config * @property Title provides a name against the API call * @property ExternalLastEditedKey is the key that labels the last date the call was made * @property ExternalLastEdited is the last modified date from the external API data */ - private static $db = [ + private static array $db = [ 'Title' => 'Varchar(250)', 'ExternalLastEditedKey' => 'Varchar(100)', 'ExternalLastEdited' => 'Datetime' ]; - public static function convertUnix2UTC($data) + public static function convertUnix2UTC($data): string { $string = preg_replace('/\D/', '', $data); $date = new DateTime(); @@ -43,18 +46,16 @@ public static function convertUnix2UTC($data) /** * Determine if the string is a Unix Timestamp * @link(Stack Overflow, http://stackoverflow.com/questions/2524680/check-whether-the-string-is-a-unix-timestamp) - * @param string $string - * @return boolean */ - public static function isTimestamp($string) + public static function isTimestamp(string $string): bool { - if (substr($string, 0, 5) == "/Date") { + if (str_starts_with($string, "/Date")) { return true; } try { new DateTime('@' . $string); - } catch (Exception $e) { + } catch (Exception) { return false; } return true; @@ -62,10 +63,9 @@ public static function isTimestamp($string) /** * Set the ExternalLastEdited to the maximum last edited date - * @param array $apidata * @return $this */ - public function setMaxExternalLastEdited(array $apidata) + public function setMaxExternalLastEdited(array $apidata): static { $external_last_edited_key = $this->ExternalLastEditedKey; @@ -77,9 +77,7 @@ public function setMaxExternalLastEdited(array $apidata) ); } - $dates = array_map(function ($item) use ($external_last_edited_key) { - return $item[$external_last_edited_key]; - }, $apidata); + $dates = array_map(fn($item) => $item[$external_last_edited_key], $apidata); $max_date = max($dates); if (self::isTimestamp($max_date)) { diff --git a/src/Utilities.php b/src/Utilities.php index 91047ed..a9e6837 100644 --- a/src/Utilities.php +++ b/src/Utilities.php @@ -9,7 +9,7 @@ class Utilities * @param array $data a list * @return array The items that are duplicates */ - public static function getDuplicates($data = array()) + public static function getDuplicates($data = []): array { return array_unique(array_diff_assoc($data, array_unique($data))); } diff --git a/tests/ConsumerArrayBulkLoaderSourceTest.php b/tests/ConsumerArrayBulkLoaderSourceTest.php index 6cc512c..fe18994 100644 --- a/tests/ConsumerArrayBulkLoaderSourceTest.php +++ b/tests/ConsumerArrayBulkLoaderSourceTest.php @@ -7,12 +7,12 @@ class ConsumerArrayBulkLoaderSourceTest extends SapphireTest { - public function testIterator() + public function testIterator(): void { - $data = array( - array("First" => 1), - array("First" => 2) - ); + $data = [ + ["First" => 1], + ["First" => 2] + ]; $source = new ArrayBulkLoaderSource($data); $iterator = $source->getIterator(); $count = 0; diff --git a/tests/ConsumerBulkLoaderClearAbsentRecordsTest.php b/tests/ConsumerBulkLoaderClearAbsentRecordsTest.php index 4e92bd6..524f561 100644 --- a/tests/ConsumerBulkLoaderClearAbsentRecordsTest.php +++ b/tests/ConsumerBulkLoaderClearAbsentRecordsTest.php @@ -14,10 +14,10 @@ class BulkLoaderClearAbsentRecordsTest extends SapphireTest protected static $extra_dataobjects = [User::class]; - public function testClearAbsentRecords() + public function testClearAbsentRecords(): void { $apidata = json_decode($this->jsondata, true); - $results = UserBulkLoader::create('AntonyThorpe\Consumer\Tests\User')->clearAbsentRecords($apidata, 'guid', 'Guid'); + $results = UserBulkLoader::create(User::class)->clearAbsentRecords($apidata, 'guid', 'Guid'); // Check Results $this->assertEquals($results->CreatedCount(), 0); @@ -47,10 +47,10 @@ public function testClearAbsentRecords() ); } - public function testClearAbsentRecordsWithPreview() + public function testClearAbsentRecordsWithPreview(): void { $apidata = json_decode($this->jsondata, true); - UserBulkLoader::create('AntonyThorpe\Consumer\Tests\User')->clearAbsentRecords($apidata, 'guid', 'Guid', true); + UserBulkLoader::create(User::class)->clearAbsentRecords($apidata, 'guid', 'Guid', true); $item = User::get()->find('Email', 'LocalOnly@local.net'); $this->assertSame( diff --git a/tests/ConsumerBulkLoaderDeleteManyRecordsTest.php b/tests/ConsumerBulkLoaderDeleteManyRecordsTest.php index 0791539..9f1f125 100644 --- a/tests/ConsumerBulkLoaderDeleteManyRecordsTest.php +++ b/tests/ConsumerBulkLoaderDeleteManyRecordsTest.php @@ -11,7 +11,7 @@ class BulkLoaderDeleteManyRecordsTest extends SapphireTest protected static $extra_dataobjects = [User::class]; - public function testDeleteManyRecords() + public function testDeleteManyRecords(): void { $shanna = User::get()->find('Email', 'Shanna@melissa.tv'); $nathan = User::get()->find('Email', 'Nathan@yesenia.net'); @@ -19,7 +19,7 @@ public function testDeleteManyRecords() $this->assertTrue($nathan->exists(), 'Nathan exists in User'); $apidata = json_decode($this->jsondata_to_delete, true); - $results = UserBulkLoader::create('AntonyThorpe\Consumer\Tests\User')->deleteManyRecords($apidata); + $results = UserBulkLoader::create(User::class)->deleteManyRecords($apidata); // Check Results $this->assertEquals($results->CreatedCount(), 0); @@ -69,11 +69,11 @@ public function testDeleteManyRecords() ); } - public function testDeleteManyWithPreview() + public function testDeleteManyWithPreview(): void { $original_count = User::get()->count(); $apidata = json_decode($this->jsondata_to_delete, true); - UserBulkLoader::create('AntonyThorpe\Consumer\Tests\User')->deleteManyRecords($apidata, true); + UserBulkLoader::create(User::class)->deleteManyRecords($apidata, true); $this->assertEquals( $original_count, diff --git a/tests/ConsumerBulkLoaderRelationTest.php b/tests/ConsumerBulkLoaderRelationTest.php index 1fb6d00..7f6a31c 100644 --- a/tests/ConsumerBulkLoaderRelationTest.php +++ b/tests/ConsumerBulkLoaderRelationTest.php @@ -26,15 +26,15 @@ class BulkLoaderRelationTest extends SapphireTest public function setUp(): void { parent::setUp(); - $data = array( + $data = [ //unlinked relation, no record - array("Course.Title" => "Math 101", "Term" => 1), + ["Course.Title" => "Math 101", "Term" => 1], //existing relation and record - array("Course.Title" => "Tech 102", "Term" => 1), + ["Course.Title" => "Tech 102", "Term" => 1], //relation does not exist, no record - array("Course.Title" => "Geometry 722", "Term" => 1) - ); - $this->loader = new BulkLoader('\AntonyThorpe\Consumer\Tests\CourseSelection'); + ["Course.Title" => "Geometry 722", "Term" => 1] + ]; + $this->loader = BulkLoader::create(CourseSelection::class); $this->loader->setSource( new ArrayBulkLoaderSource($data) ); @@ -44,7 +44,7 @@ public function setUp(): void * This default behaviour should act the same as * testLinkAndCreateRelations */ - public function testEmptyBehaviour() + public function testEmptyBehaviour(): void { $results = $this->loader->load(); $this->assertEquals( @@ -64,12 +64,12 @@ public function testEmptyBehaviour() ); } - public function testLinkAndCreateRelations() + public function testLinkAndCreateRelations(): void { - $this->loader->transforms['Course.Title'] = array( + $this->loader->transforms['Course.Title'] = [ 'link' => true, 'create' => true - ); + ]; $results = $this->loader->load(); $this->assertEquals( 3, @@ -88,12 +88,12 @@ public function testLinkAndCreateRelations() ); } - public function testNoRelations() + public function testNoRelations(): void { - $this->loader->transforms['Course.Title'] = array( + $this->loader->transforms['Course.Title'] = [ 'link' => false, 'create' => false - ); + ]; $results = $this->loader->load(); $this->assertEquals( 3, @@ -112,12 +112,12 @@ public function testNoRelations() ); } - public function testOnlyLinkRelations() + public function testOnlyLinkRelations(): void { - $this->loader->transforms['Course.Title'] = array( + $this->loader->transforms['Course.Title'] = [ 'link' => true, 'create' => false - ); + ]; $results = $this->loader->load(); $this->assertEquals( 3, @@ -137,12 +137,12 @@ public function testOnlyLinkRelations() ); } - public function testOnlyCreateUniqueRelations() + public function testOnlyCreateUniqueRelations(): void { - $this->loader->transforms['Course.Title'] = array( + $this->loader->transforms['Course.Title'] = [ 'link' => false, 'create' => true - ); + ]; $results = $this->loader->load(); $this->assertEquals( 3, @@ -161,15 +161,15 @@ public function testOnlyCreateUniqueRelations() ); } - public function testRelationDuplicateCheck() + public function testRelationDuplicateCheck(): void { - $this->loader->transforms['Course.Title'] = array( + $this->loader->transforms['Course.Title'] = [ 'link' => true, 'create' => true - ); - $this->loader->duplicateChecks = array( + ]; + $this->loader->duplicateChecks = [ "Course.Title" - ); + ]; $results = $this->loader->load(); $this->assertEquals(2, $results->CreatedCount(), "2 created"); $this->assertEquals(0, $results->SkippedCount(), "0 skipped"); @@ -178,14 +178,14 @@ public function testRelationDuplicateCheck() //$this->markTestIncomplete("test using {RelationName}ID and {RelationName}"); } - public function testRelationList() + public function testRelationList(): void { - $list = new ArrayList(); - $this->loader->transforms['Course.Title'] = array( + $list = ArrayList::create(); + $this->loader->transforms['Course.Title'] = [ 'create' => true, 'link' => true, 'list' => $list - ); + ]; $results = $this->loader->load(); $this->assertEquals(3, $results->CreatedCount(), "3 records created"); $this->assertEquals(3, $list->count(), "3 relations created"); diff --git a/tests/ConsumerBulkLoaderTest.php b/tests/ConsumerBulkLoaderTest.php index 6a18d21..4ff28dc 100644 --- a/tests/ConsumerBulkLoaderTest.php +++ b/tests/ConsumerBulkLoaderTest.php @@ -17,41 +17,41 @@ class BulkLoaderTest extends SapphireTest Country::class ]; - public function testLoading() + public function testLoading(): void { - $loader = new BulkLoader('AntonyThorpe\Consumer\Tests\Person'); + $loader = BulkLoader::create(Person::class); - $loader->columnMap = array( + $loader->columnMap = [ "first name" => "FirstName", "last name" => "Surname", "name" => "Name", "age" => "Age", "country" => "Country.Code", - ); + ]; - $loader->transforms = array( - "Name" => array( - 'callback' => function ($value, $obj) { + $loader->transforms = [ + "Name" => [ + 'callback' => function ($value, $obj): void { $name = explode(" ", $value); $obj->FirstName = $name[0]; $obj->Surname = $name[1]; } - ), - "Country.Code" => array( + ], + "Country.Code" => [ "link" => true, //link up to existing relations "create" => false //don't create new relation objects - ) - ); + ] + ]; - $loader->duplicateChecks = array( + $loader->duplicateChecks = [ "FirstName" - ); + ]; //set the source data - $data = array( - array("name" => "joe bloggs", "age" => "62", "country" => "NZ"), - array("name" => "alice smith", "age" => "24", "country" => "AU") - ); + $data = [ + ["name" => "joe bloggs", "age" => "62", "country" => "NZ"], + ["name" => "alice smith", "age" => "24", "country" => "AU"] + ]; $loader->setSource(new ArrayBulkLoaderSource($data)); $results = $loader->load(); @@ -72,41 +72,41 @@ public function testLoading() $this->assertEquals($joe->Country()->Code, "NZ"); } - public function testLoadUpdatesOnly() + public function testLoadUpdatesOnly(): void { //Set up some existing dataobjects - Person::create(array("FirstName" => "joe", "Surname" => "Kiwi", "Age" => "62", "CountryID" => 1))->write(); - Person::create(array("FirstName" => "bruce", "Surname" => "Aussie", "Age" => "24", "CountryID" => 2))->write(); + Person::create(["FirstName" => "joe", "Surname" => "Kiwi", "Age" => "62", "CountryID" => 1])->write(); + Person::create(["FirstName" => "bruce", "Surname" => "Aussie", "Age" => "24", "CountryID" => 2])->write(); $this->assertEquals( 2, Person::get()->Count(), "Two people exist in Person class" ); - $loader = new BulkLoader('AntonyThorpe\Consumer\Tests\Person'); + $loader = BulkLoader::create(Person::class); $loader->addNewRecords = false; // don't add new records from source - $loader->columnMap = array( + $loader->columnMap = [ "firstname" => "FirstName", "surname" => "Surname", "age" => "Age", "country" => "Country.Code" - ); - $loader->transforms = array( - "Country.Code" => array( + ]; + $loader->transforms = [ + "Country.Code" => [ "link" => true, //link up to existing relations "create" => false //don't create new relation objects - ) - ); - $loader->duplicateChecks = array( + ] + ]; + $loader->duplicateChecks = [ "FirstName" - ); + ]; //set the source data. Joe has aged one year and shifted to Australia. Bruce has aged a year too, but is missing other elements, which should remain the same. - $data = array( - array("firstname" => "joe", "surname" => "Kiwi", "age" => "63", "country" => "AU"), - array("firstname" => "bruce", "age" => "25"), - array("firstname" => "NotEntered", "surname" => "should not be entered", "age" => "33", "country" => "NZ"), - array("firstname" => "NotEntered2", "surname" => "should not be entered as well", "age" => "24", "country" => "AU") - ); + $data = [ + ["firstname" => "joe", "surname" => "Kiwi", "age" => "63", "country" => "AU"], + ["firstname" => "bruce", "age" => "25"], + ["firstname" => "NotEntered", "surname" => "should not be entered", "age" => "33", "country" => "NZ"], + ["firstname" => "NotEntered2", "surname" => "should not be entered as well", "age" => "24", "country" => "AU"] + ]; $loader->setSource(new ArrayBulkLoaderSource($data)); $results = $loader->load(); @@ -129,43 +129,41 @@ public function testLoadUpdatesOnly() $this->assertSame(2, (int)$bruce->CountryID, 'Bruce should still have the CountryID for Australia'); } - public function testTransformCallback() + public function testTransformCallback(): void { - $loader = new BulkLoader('AntonyThorpe\Consumer\Tests\Person'); - $data = array( - array("FirstName" => "joe", "age" => "62", "country" => "NZ") - ); + $loader = BulkLoader::create(Person::class); + $data = [ + ["FirstName" => "joe", "age" => "62", "country" => "NZ"] + ]; $loader->setSource(new ArrayBulkLoaderSource($data)); - $loader->transforms = array( - 'FirstName' => array( - 'callback' => function ($value) { - return strtoupper($value); - } - ) - ); + $loader->transforms = [ + 'FirstName' => [ + 'callback' => fn($value): string => strtoupper((string) $value) + ] + ]; $results = $loader->load(); $this->assertEquals($results->CreatedCount(), 1); $result = $results->Created()->first(); $this->assertEquals("JOE", $result->FirstName, "First name has been transformed"); } - public function testRequiredFields() + public function testRequiredFields(): void { - $loader = new BulkLoader('AntonyThorpe\Consumer\Tests\Person'); - $data = array( - array("FirstName" => "joe", "Surname" => "Bloggs"), //valid - array("FirstName" => 0, "Surname" => "Bloggs"), //invalid firstname - array("FirstName" => null), //invalid firstname - array("FirstName" => "", "Surname" => ""), //invalid firstname - array("age" => "25", "Surname" => "Smith"), //invalid firstname - array("FirstName" => "Jane"), //valid - ); + $loader = BulkLoader::create(Person::class); + $data = [ + ["FirstName" => "joe", "Surname" => "Bloggs"], //valid + ["FirstName" => 0, "Surname" => "Bloggs"], //invalid firstname + ["FirstName" => null], //invalid firstname + ["FirstName" => "", "Surname" => ""], //invalid firstname + ["age" => "25", "Surname" => "Smith"], //invalid firstname + ["FirstName" => "Jane"], //valid + ]; $loader->setSource(new ArrayBulkLoaderSource($data)); - $loader->transforms = array( - 'FirstName' => array( + $loader->transforms = [ + 'FirstName' => [ 'required' => true - ) - ); + ] + ]; $results = $loader->load(); $this->assertEquals(2, $results->CreatedCount(), "Created 2"); $this->assertEquals(4, $results->SkippedCount(), "Skipped 4"); diff --git a/tests/ConsumerBulkLoaderUpdateRecordsTest.php b/tests/ConsumerBulkLoaderUpdateRecordsTest.php index 3c96409..cc083a4 100644 --- a/tests/ConsumerBulkLoaderUpdateRecordsTest.php +++ b/tests/ConsumerBulkLoaderUpdateRecordsTest.php @@ -9,10 +9,10 @@ class BulkLoaderUpdateRecordsTest extends SapphireTest { - protected static $fixture_file = array( + protected static $fixture_file = [ 'fixtures/User.yml', 'fixtures/Product.yml' - ); + ]; protected static $extra_dataobjects = [ User::class, @@ -30,10 +30,10 @@ public function setUp(): void $this->objFromFixture(Product::class, 'pm3')->copyVersionToStage('Stage', 'Live'); } - public function testUpdateRecords() + public function testUpdateRecords(): void { $apidata = json_decode($this->jsondata1, true); - $results = UserBulkLoader::create('AntonyThorpe\Consumer\Tests\User')->updateRecords($apidata); + $results = UserBulkLoader::create(User::class)->updateRecords($apidata); // Check Results $this->assertEquals($results->CreatedCount(), 0); @@ -84,11 +84,11 @@ public function testUpdateRecords() ); } - public function testUpdateRecordsWithPreview() + public function testUpdateRecordsWithPreview(): void { $original_count = User::get()->count(); $apidata = json_decode($this->jsondata1, true); - UserBulkLoader::create('AntonyThorpe\Consumer\Tests\User')->updateRecords($apidata, true); + UserBulkLoader::create(User::class)->updateRecords($apidata, true); $this->assertEquals( $original_count, @@ -121,18 +121,18 @@ public function testUpdateRecordsWithPreview() ); } - public function testUpdateRecordsWhenDataobjectExtendsPage() + public function testUpdateRecordsWhenDataobjectExtendsPage(): void { $apidata = json_decode($this->jsondata2, true); - $loader = ProductBulkLoader::create('AntonyThorpe\Consumer\Tests\Product'); - $loader->transforms = array( - 'Title' => array( + $loader = ProductBulkLoader::create(Product::class); + $loader->transforms = [ + 'Title' => [ 'callback' => function ($value, &$placeholder) { $placeholder->URLSegment = Convert::raw2url($value); return $value; } - ) - ); + ] + ]; $results = $loader->updateRecords($apidata); // Check Results diff --git a/tests/ConsumerBulkLoaderUpsertManyRecordsTest.php b/tests/ConsumerBulkLoaderUpsertManyRecordsTest.php index 4df499a..0ca6f3c 100644 --- a/tests/ConsumerBulkLoaderUpsertManyRecordsTest.php +++ b/tests/ConsumerBulkLoaderUpsertManyRecordsTest.php @@ -7,14 +7,14 @@ class BulkLoaderUpsertManyRecordsTest extends SapphireTest { - protected static $fixture_file = array('fixtures/User.yml'); + protected static $fixture_file = ['fixtures/User.yml']; protected static $extra_dataobjects = [User::class]; - public function testUpsertManyRecords() + public function testUpsertManyRecords(): void { $apidata = json_decode($this->jsondata_to_upsert, true); - $results = UserBulkLoader::create('AntonyThorpe\Consumer\Tests\User')->upsertManyRecords($apidata); + $results = UserBulkLoader::create(User::class)->upsertManyRecords($apidata); // Check Results $this->assertEquals($results->CreatedCount(), 1); @@ -68,10 +68,10 @@ public function testUpsertManyRecords() ); } - public function testUpsertManyRecordsWithPreview() + public function testUpsertManyRecordsWithPreview(): void { $apidata = json_decode($this->jsondata_to_upsert, true); - UserBulkLoader::create('AntonyThorpe\Consumer\Tests\User')->upsertManyRecords($apidata, true); + UserBulkLoader::create(User::class)->upsertManyRecords($apidata, true); $remains = User::get()->find('Email', 'Sincere@april.biz'); $this->assertSame( diff --git a/tests/ConsumerModelTest.php b/tests/ConsumerModelTest.php index cf1ad10..8323afe 100644 --- a/tests/ConsumerModelTest.php +++ b/tests/ConsumerModelTest.php @@ -7,14 +7,14 @@ class ConsumerModelTest extends SapphireTest { - public function testCreateUpdate() + public function testCreateUpdate(): void { $apidata = json_decode($this->jsondata, true); $dataobject = Consumer::create( - array( + [ 'Title' => 'ProductUpdate', 'ExternalLastEditedKey' => 'lastmodified' - ) + ] )->setMaxExternalLastEdited($apidata); $id = $dataobject->write(); @@ -36,14 +36,14 @@ public function testCreateUpdate() ); } - public function testCreateUpdateWithUnixDateFormat() + public function testCreateUpdateWithUnixDateFormat(): void { $apidata = json_decode($this->jsondata2, true); $dataobject = Consumer::create( - array( + [ 'Title' => 'ProductUpdate2', 'ExternalLastEditedKey' => 'lastmodified' - ) + ] )->setMaxExternalLastEdited($apidata); $id = $dataobject->write(); @@ -55,14 +55,14 @@ public function testCreateUpdateWithUnixDateFormat() ); } - public function testCreateUpdateWithUnixDateFormatInMilliseconds() + public function testCreateUpdateWithUnixDateFormatInMilliseconds(): void { $apidata = json_decode($this->jsondata3, true); $dataobject = Consumer::create( - array( + [ 'Title' => 'ProductUpdate3', 'ExternalLastEditedKey' => 'lastmodified' - ) + ] )->setMaxExternalLastEdited($apidata); $id = $dataobject->write(); diff --git a/tests/loaders/ProductBulkLoader.php b/tests/loaders/ProductBulkLoader.php index 060be50..300d251 100644 --- a/tests/loaders/ProductBulkLoader.php +++ b/tests/loaders/ProductBulkLoader.php @@ -7,11 +7,11 @@ class ProductBulkLoader extends BulkLoader implements TestOnly { - public $columnMap = array( + public $columnMap = [ 'ProductCode' => 'InternalItemID', 'ProductDescription' => 'Title', 'DefaultSellPrice' => 'BasePrice' - ); + ]; - public $duplicateChecks = array('InternalItemID'); + public $duplicateChecks = ['InternalItemID']; } diff --git a/tests/loaders/UserBulkLoader.php b/tests/loaders/UserBulkLoader.php index 8b2f852..7179794 100644 --- a/tests/loaders/UserBulkLoader.php +++ b/tests/loaders/UserBulkLoader.php @@ -7,13 +7,13 @@ class UserBulkLoader extends BulkLoader implements TestOnly { - public $columnMap = array( + public $columnMap = [ 'name' => 'Name', 'email' => 'Email', 'username' => 'UserName', 'phone' => 'Phone', 'website' => 'Website' - ); + ]; - public $duplicateChecks = array('Email'); + public $duplicateChecks = ['Email']; } diff --git a/tests/models/Country.php b/tests/models/Country.php index e3bb3e6..a305c2c 100644 --- a/tests/models/Country.php +++ b/tests/models/Country.php @@ -7,10 +7,16 @@ class Country extends Dataobject implements TestOnly { - private static $table_name = 'Country'; + /** + * @config + */ + private static string $table_name = 'Country'; - private static $db = array( + /** + * @config + */ + private static array $db = [ "Title" => "Varchar", "Code" => "Varchar" - ); + ]; } diff --git a/tests/models/Course.php b/tests/models/Course.php index 8a11fe5..e9fb29f 100644 --- a/tests/models/Course.php +++ b/tests/models/Course.php @@ -7,9 +7,15 @@ class Course extends DataObject implements TestOnly { - private static $table_name = 'Course'; + /** + * @config + */ + private static string $table_name = 'Course'; - private static $db = array( + /** + * @config + */ + private static array $db = [ "Title" => "Varchar" - ); + ]; } diff --git a/tests/models/CourseSelection.php b/tests/models/CourseSelection.php index f827552..8a20fe1 100644 --- a/tests/models/CourseSelection.php +++ b/tests/models/CourseSelection.php @@ -7,13 +7,22 @@ class CourseSelection extends DataObject implements TestOnly { - private static $table_name = 'CourseSelection'; + /** + * @config + */ + private static string $table_name = 'CourseSelection'; - private static $db = array( + /** + * @config + */ + private static array $db = [ "Term" => "Int" - ); + ]; - private static $has_one = array( + /** + * @config + */ + private static array $has_one = [ "Course" => Course::class - ); + ]; } diff --git a/tests/models/Page.php b/tests/models/Page.php index c037056..3698b32 100644 --- a/tests/models/Page.php +++ b/tests/models/Page.php @@ -12,10 +12,15 @@ */ class Page extends SiteTree implements TestOnly { + /** + * @config + */ + private static $table_name = 'Page'; + /** * Set font symbol for menus - * @var array + * @config */ - private static $db = array( - ); + private static array $db = []; + } diff --git a/tests/models/Person.php b/tests/models/Person.php index c584ca5..970c323 100644 --- a/tests/models/Person.php +++ b/tests/models/Person.php @@ -7,15 +7,24 @@ class Person extends DataObject implements TestOnly { - private static $table_name = 'Person'; + /** + * @config + */ + private static string $table_name = 'Person'; - private static $db = array( + /** + * @config + */ + private static array $db = [ "FirstName" => "Varchar", "Surname" => "Varchar", "Age" => "Int" - ); + ]; - private static $has_one = array( + /** + * @config + */ + private static array $has_one = [ "Country" => Country::class - ); + ]; } diff --git a/tests/models/Product.php b/tests/models/Product.php index ad3fa1e..e3e32bf 100644 --- a/tests/models/Product.php +++ b/tests/models/Product.php @@ -6,11 +6,17 @@ class Product extends Page implements TestOnly { - private static $table_name = 'Product'; + /** + * @config + */ + private static string $table_name = 'Product'; - private static $db = array( + /** + * @config + */ + private static array $db = [ 'InternalItemID' => 'Varchar(30)', 'Title' => 'Varchar(200)', 'BasePrice' => 'Currency' - ); + ]; } diff --git a/tests/models/User.php b/tests/models/User.php index 6c60650..ff70ecb 100644 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -7,14 +7,20 @@ class User extends DataObject implements TestOnly { - private static $table_name = 'User'; + /** + * @config + */ + private static string $table_name = 'User'; - private static $db = array( + /** + * @config + */ + private static array $db = [ 'Name' => 'Varchar', 'Email' => 'Varchar(254)', 'UserName' => 'Varchar', 'Phone' => 'Varchar', 'Website' => 'Varchar', 'Guid' => 'Varchar' - ); + ]; }