public function toArray()
{
$mr = ['url' => null, 'number' => null, 'state' => null, 'title' => null, 'body' => null, 'labels' => [], 'milestone' => null, 'created_at' => new \DateTime(), 'updated_at' => null, 'user' => null, 'assignee' => null, 'merged' => false, 'merged_by' => null, 'head' => ['ref' => null, 'sha' => null, 'user' => null, 'repo' => null], 'base' => ['ref' => null, 'label' => null, 'sha' => null, 'repo' => null, 'user' => null]];
foreach (static::$properties as $property) {
switch ($property) {
case 'id':
$mr['number'] = $this->{$property};
break;
case 'author':
$mr['author'] = $this->{$property}->username;
break;
case 'source_project_id':
if ($this->project->id === $this->{$property}) {
$sourceProject = $this->project;
} else {
$sourceProject = Model\Project::fromArray($this->getClient(), $this->getClient()->api('projects')->show($this->{$property}));
}
$mr['head']['user'] = $sourceProject->namespace->path;
$mr['head']['repo'] = $sourceProject->name;
break;
case 'state':
$mr['state'] = 'opened' === $this->{$property} ? 'open' : $this->{$property};
$mr['merged'] = $this->{$property} === 'merged';
break;
case 'source_branch':
$mr['head']['ref'] = $this->{$property};
break;
case 'target_project_id':
if ($this->project->id === $this->{$property}) {
$targetProject = $this->project;
} else {
$targetProject = Model\Project::fromArray($this->getClient(), $this->getClient()->api('projects')->show($this->{$property}));
}
$mr['base']['user'] = $targetProject->namespace->path;
$mr['base']['repo'] = $targetProject->name;
break;
case 'target_branch':
$mr['base']['ref'] = $this->{$property};
break;
case 'created_at':
case 'updated_at':
// remove microseconds precision (2014-11-28T08:43:59.354Z -> 2014-11-28T08:43:59Z)
$mr[$property] = new \DateTime(preg_replace('{\\.\\d+}', '', $this->{$property}));
break;
case 'description':
$mr['body'] = $this->{$property};
break;
default:
$mr[$property] = $this->{$property};
break;
}
}
return $mr;
}