[Coding Standards] Applied new coding standards to CachetHQ\Cachet folder
This commit is contained in:
@@ -1,91 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
|
||||
use Input, Incident;
|
||||
use Dingo\Api\Routing\Controller as DingoController;
|
||||
use Dingo\Api\Auth\Shield;
|
||||
use Input, Incident;
|
||||
use Dingo\Api\Routing\Controller as DingoController;
|
||||
use Dingo\Api\Auth\Shield;
|
||||
|
||||
class IncidentController extends DingoController {
|
||||
class IncidentController extends DingoController {
|
||||
|
||||
protected $auth;
|
||||
protected $auth;
|
||||
|
||||
public function __construct(Shield $auth) {
|
||||
$this->auth = $auth;
|
||||
}
|
||||
public function __construct(Shield $auth) {
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all incidents
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getIncidents() {
|
||||
return Incident::all();
|
||||
}
|
||||
/**
|
||||
* Get all incidents
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getIncidents() {
|
||||
return Incident::all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single incident
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
public function getIncident($id) {
|
||||
if ($incident = Incident::find($id)) {
|
||||
return $incident;
|
||||
} else {
|
||||
App::abort(404, 'Incident not found');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get a single incident
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
public function getIncident($id) {
|
||||
if ($incident = Incident::find($id)) {
|
||||
return $incident;
|
||||
} else {
|
||||
App::abort(404, 'Incident not found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new incident
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
public function postIncidents() {
|
||||
$incident = new Incident(Input::all());
|
||||
$incident->user_id = $this->auth->user()->id;
|
||||
return $this->_saveIncident($incident);
|
||||
}
|
||||
/**
|
||||
* Create a new incident
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
public function postIncidents() {
|
||||
$incident = new Incident(Input::all());
|
||||
$incident->user_id = $this->auth->user()->id;
|
||||
return $this->_saveIncident($incident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing incident
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
public function putIncident($id) {
|
||||
$incident = $this->getIncident($id);
|
||||
/**
|
||||
* Update an existing incident
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
public function putIncident($id) {
|
||||
$incident = $this->getIncident($id);
|
||||
|
||||
$incident->fill(Input::all());
|
||||
$incident->fill(Input::all());
|
||||
|
||||
return $this->_saveIncident($incident);
|
||||
}
|
||||
return $this->_saveIncident($incident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for saving the incident, and returning appropriate error codes
|
||||
*
|
||||
* @param Incident $incident
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
private function _saveIncident($incident) {
|
||||
if ($incident->isValid()) {
|
||||
try {
|
||||
$component = $incident->parent;
|
||||
if (!$component) {
|
||||
App::abort(400, 'Invalid component specified');
|
||||
}
|
||||
/**
|
||||
* Function for saving the incident, and returning appropriate error codes
|
||||
*
|
||||
* @param Incident $incident
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
private function _saveIncident($incident) {
|
||||
if ($incident->isValid()) {
|
||||
try {
|
||||
$component = $incident->parent;
|
||||
if (!$component) {
|
||||
App::abort(400, 'Invalid component specified');
|
||||
}
|
||||
|
||||
$incident->saveOrFail();
|
||||
return $incident;
|
||||
} catch (Exception $e) {
|
||||
App::abort(500, $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
App::abort(404, $incident->getErrors()->first());
|
||||
}
|
||||
}
|
||||
}
|
||||
$incident->saveOrFail();
|
||||
return $incident;
|
||||
} catch (Exception $e) {
|
||||
App::abort(500, $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
App::abort(404, $incident->getErrors()->first());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
namespace CachetHQ\Cachet\Controllers\Api;
|
||||
|
||||
use Input, Metric;
|
||||
use Dingo\Api\Routing\Controller as DingoController;
|
||||
use Input, Metric;
|
||||
use Dingo\Api\Routing\Controller as DingoController;
|
||||
|
||||
class MetricController extends DingoController {
|
||||
class MetricController extends DingoController {
|
||||
|
||||
/**
|
||||
* Get all metrics
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getMetrics() {
|
||||
return Metric::all();
|
||||
}
|
||||
/**
|
||||
* Get all metrics
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getMetrics() {
|
||||
return Metric::all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single metric
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
public function getMetric($id) {
|
||||
if ($metric = Metric::find($id)) {
|
||||
return $metric;
|
||||
} else {
|
||||
App::abort(404, 'Metric not found');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get a single metric
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
public function getMetric($id) {
|
||||
if ($metric = Metric::find($id)) {
|
||||
return $metric;
|
||||
} else {
|
||||
App::abort(404, 'Metric not found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new metric
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
public function postMetrics() {
|
||||
$metric = new Metric(Input::all());
|
||||
return $this->_saveMetric($metric);
|
||||
}
|
||||
/**
|
||||
* Create a new metric
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
public function postMetrics() {
|
||||
$metric = new Metric(Input::all());
|
||||
return $this->_saveMetric($metric);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing metric
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
public function putMetric($id) {
|
||||
$metric = $this->getMetric($id);
|
||||
$metric->fill(Input::all());
|
||||
return $this->_saveMetric($metric);
|
||||
}
|
||||
/**
|
||||
* Update an existing metric
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
public function putMetric($id) {
|
||||
$metric = $this->getMetric($id);
|
||||
$metric->fill(Input::all());
|
||||
return $this->_saveMetric($metric);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for saving a metric, and returning appropriate error codes
|
||||
*
|
||||
* @param Metric $metric
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
private function _saveMetric($metric) {
|
||||
if ($metric->isValid()) {
|
||||
try {
|
||||
$metric->saveOrFail();
|
||||
return $metric;
|
||||
} catch (Exception $e) {
|
||||
App::abort(500, $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
App::abort(404, $metric->getErrors()->first());
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Function for saving a metric, and returning appropriate error codes
|
||||
*
|
||||
* @param Metric $metric
|
||||
*
|
||||
* @return Metric
|
||||
*/
|
||||
private function _saveMetric($metric) {
|
||||
if ($metric->isValid()) {
|
||||
try {
|
||||
$metric->saveOrFail();
|
||||
return $metric;
|
||||
} catch (Exception $e) {
|
||||
App::abort(500, $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
App::abort(404, $metric->getErrors()->first());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
<?php
|
||||
|
||||
class IncidentTransformer extends \League\Fractal\TransformerAbstract {
|
||||
public function transform(Incident $incident) {
|
||||
$component = $incident->parent;
|
||||
$transformer = $component->getTransformer();
|
||||
class IncidentTransformer extends \League\Fractal\TransformerAbstract {
|
||||
public function transform(Incident $incident) {
|
||||
$component = $incident->parent;
|
||||
$transformer = $component->getTransformer();
|
||||
|
||||
return [
|
||||
'id' => (int) $incident->id,
|
||||
'name' => $incident->name,
|
||||
'message' => $incident->message,
|
||||
'status_id' => (int) $incident->status,
|
||||
'status' => $incident->getHumanStatusAttribute(),
|
||||
'component' => $transformer->transform($component),
|
||||
'created_at' => $incident->created_at->timestamp,
|
||||
'updated_at' => $incident->updated_at->timestamp,
|
||||
];
|
||||
}
|
||||
}
|
||||
return [
|
||||
'id' => (int) $incident->id,
|
||||
'name' => $incident->name,
|
||||
'message' => $incident->message,
|
||||
'status_id' => (int) $incident->status,
|
||||
'status' => $incident->getHumanStatusAttribute(),
|
||||
'component' => $transformer->transform($component),
|
||||
'created_at' => $incident->created_at->timestamp,
|
||||
'updated_at' => $incident->updated_at->timestamp,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
class MetricTransformer extends \League\Fractal\TransformerAbstract {
|
||||
public function transform(Metric $metric) {
|
||||
return [
|
||||
'id' => (int) $component->id,
|
||||
'name' => $component->name,
|
||||
'description' => $component->description,
|
||||
'suffix' => $component->suffix,
|
||||
'display' => $component->shouldDisplay,
|
||||
'created_at' => $component->created_at->timestamp,
|
||||
'updated_at' => $component->updated_at->timestamp,
|
||||
];
|
||||
}
|
||||
}
|
||||
class MetricTransformer extends \League\Fractal\TransformerAbstract {
|
||||
public function transform(Metric $metric) {
|
||||
return [
|
||||
'id' => (int) $component->id,
|
||||
'name' => $component->name,
|
||||
'description' => $component->description,
|
||||
'suffix' => $component->suffix,
|
||||
'display' => $component->shouldDisplay,
|
||||
'created_at' => $component->created_at->timestamp,
|
||||
'updated_at' => $component->updated_at->timestamp,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user