for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace FloSports\ScaleEngine\Model\Factory;
/**
* A factory used to construct ScaleEngine ticket models.
*/
class ScaleEngineTicketFactory extends AbstractScaleEngineModelFactory
{
/** @type array A map of keys from ScaleEngine's API to exposed model. **/
const KEY_MAP = [
'active' => 'active',
'app' => 'app',
'created_date' => 'createdDate',
'ip' => 'ip',
'key' => 'key',
'pass' => 'pass',
'used_date' => 'usedDate',
'uses' => 'uses',
'video' => 'video',
];
* Create the model factory for ScaleEngine tickets.
public function __construct()
parent::__construct(
'\FloSports\ScaleEngine\Model\ScaleEngineTicket',
self::KEY_MAP
);
}
* Parse the data given into correct types and changes keys based on the
* `KEY_MAP`.
*
* @param array $data The ticket data to parse.
* @return array The data after being converted to the parsed form.
public function parseData(array $data)
$parsedData = [];
foreach (self::KEY_MAP as $from => $to) {
if (array_key_exists($from, $data)) {
$parsedData[$to] = $data[$from];
$parsedData['active'] = (bool)$parsedData['active'];
$parsedData['createdDate'] = $this->convertDate($parsedData['createdDate']);
$parsedData['usedDate'] = $this->convertDate($parsedData['usedDate']);
$parsedData['uses'] = (int)$parsedData['uses'];
return $parsedData;