I have a controller called Guzzle controller.Yurrently, I am passing the slack class as a dependency through the constructor, but iam not using it. Instead i am using the Slack class as static (Slack::send(...blablabla
).
const DEFAULT_FREQUENCY = 1;
private $client;
private $Slack;
public function __construct(Client $clinet,Slack $slack)
{
$this->client = $clinet;
$this->slack = $slack;
}
public function status()
{
$notifications = Notification::where('active', 1)->get();
$status = Status::where('name', 'health')->first();
foreach ($notifications as $notification) {
$this->updateStatus($notification, $status);
}
}
private function updateStatus(Notification $notification, Status $status)
{
$status_health = $notification->status('health');
$frequency = $this->getFrequency($notification);
$elapsed_time = \Carbon\Carbon::parse($status_health['timestamp'])->diffInMinutes();
if ($elapsed_time >= $frequency) {
$response = $this->client->get($notification->website_url, ['http_errors' => false]);
$notification->statuses()->attach($status, [
'values'=> $response->getStatusCode() === 200 ? 'up' : 'down'
]);
$resCode = $response->getStatusCode();
if($resCode != 200){
Slack::send('the site is dying help!!');
}
}
}
private function getFrequency(Notification $notification)
{
return isset($notification->check_frequency)
? intval($notification->check_frequency)
: self::DEFAULT_FREQUENCY;
}
}
now iam trying to accomplish the following task
1, But GuzzleController class shouldn't be depending on Slack. But it should depend on another class. Let's call it Reporter
and its job would be to report to certain channels when needed?