I don't think this can be much shorter as it is, probably also due to the lack of code context. The only thing the code you are showing does is assigning values to variables. There isn't any quicker way then using the assignment operator =
.
Based on the code you posted, it would be best to tackle this issue on a higher level in your application. Maybe you need to rethink your class design in order to improve it's readability / usability.
You might already have all those values in some type of list, in that case you might be able to use a foreach()
loop. Or you can try giving your variables better names, and perhaps make sure all the assignment operators are nicely aligned vertically to improve the readability.
Is $jira_object
returned from json_decode(trim($jira_value->data))
really an object? Or is it just an array in object form? Since you are trimming the source data, I assume it's an array so I would keep it as one (unless you have any particular reasoning why you would want to access it like an object). Also the underscore _
prefix in your private variables is an old convention and is redundant.
The best I could come up with is the following while maintaining the readability:
$jira = json_decode(trim($jira_value->data), true);
$this->displayName = $jira['user']['displayName'];
$this->issueID = $jira['issue']['id'];
$this->issueKey = $jira['issue']['key'];
$this->issueFieldSummary = $jira['issue']['fields']['summary'];
$this->issueFieldProgress = $jira['issue']['fields']['progress'];
$this->issueFieldType = $jira['issue']['fields']['issuetype'];
$this->issueFieldUpdated = $jira['issue']['fields']['updated'];
$this->issueFieldCreated = $jira['issue']['fields']['created'];
$this->issueFieldPriority = $jira['issue']['fields']['priority'];
$this->issueFieldStatus = $jira['issue']['fields']['status'];
$this->issueFieldAssignee = $jira['issue']['fields']['assignee'];
$this->issueFieldProject = $jira['issue']['fields']['project'];
You could also put $jira['issue']['fields']
into a variable, but it wouldn't be that of an improvement. You will have extra lines of code without any significant benefits and it would fall under premature optimization, which is the root of all evil.
$jira_object->issue->fields
many times, so you could put that in a variable to reduce the code a bit. – Guffa Sep 10 '14 at 8:45