Skip to content

Commit

Permalink
Codestyle fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
leonjza committed Nov 28, 2016
1 parent e9b2b42 commit 88ac259
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 171 deletions.
136 changes: 68 additions & 68 deletions src/Alerts/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,25 @@ abstract class Base
protected $cacheKey = 'notifications';

/**
* The required method to handle the Alert.
*
* @return mixed
* Base constructor.
*/
abstract protected function getData(): Collection;
public function __construct()
{

$this->data = $this->getData();
$this->name = $this->getName();
$this->type = $this->getType();

$this->notifier = $this->getNotifier();

}

/**
* The type of notification.
* The required method to handle the Alert.
*
* @return string
* @return mixed
*/
abstract protected function getType(): string;
abstract protected function getData(): Collection;

/**
* The name of the alert. This is also the name
Expand All @@ -87,26 +94,11 @@ abstract protected function getType(): string;
abstract protected function getName(): string;

/**
* Fields in a collection row that make the alert
* unique.
* The type of notification.
*
* @return array
*/
abstract protected function getUniqueFields(): array;

/**
* Base constructor.
* @return string
*/
public function __construct()
{

$this->data = $this->getData();
$this->name = $this->getName();
$this->type = $this->getType();

$this->notifier = $this->getNotifier();

}
abstract protected function getType(): string;

/**
* Return the full class of the notifier from the config.
Expand Down Expand Up @@ -154,6 +146,57 @@ public function handle()

}

/**
* @param $data
*
* @return bool
*/
public function isOldNotification($data)
{

$hash = $this->getDataHash($data);

if (cache($this->cacheKey . $hash))
return true;

// Check the database.
$in_db = NotificationHistory::whereHash($hash)
->first();

// If its in the db, add it to the cache
if ($in_db) {

Cache::forever($this->cacheKey . $hash, true);

return true;
}

return false;
}

/**
* @param $data
*
* @return string
*/
public function getDataHash($data)
{

$hashable = collect($data)
->only($this->getUniqueFields())
->implode(',');

return md5($this->type . $this->name . $hashable);
}

/**
* Fields in a collection row that make the alert
* unique.
*
* @return array
*/
abstract protected function getUniqueFields(): array;

/**
* @return \Illuminate\Support\Collection
*/
Expand Down Expand Up @@ -219,49 +262,6 @@ public function affiliationOk($group, $data)

}

/**
* @param $data
*
* @return string
*/
public function getDataHash($data)
{

$hashable = collect($data)
->only($this->getUniqueFields())
->implode(',');

return md5($this->type . $this->name . $hashable);
}

/**
* @param $data
*
* @return bool
*/
public function isOldNotification($data)
{

$hash = $this->getDataHash($data);

if (cache($this->cacheKey . $hash))
return true;

// Check the database.
$in_db = NotificationHistory::whereHash($hash)
->first();

// If its in the db, add it to the cache
if ($in_db) {

Cache::forever($this->cacheKey . $hash, true);

return true;
}

return false;
}

/**
* @param $data
*/
Expand Down
24 changes: 12 additions & 12 deletions src/Alerts/Char/NewMailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,29 @@ class NewMailMessage extends Base
{

/**
* The required method to handle the Alert.
* The field to use from the data when trying
* to infer an affiliation.
*
* @return mixed
* @return string
*/
protected function getData(): Collection
public function getAffiliationField()
{

return MailMessage::with('body')
->where('sentDate', '>', carbon('now')->subMonth())
->get();

return 'characterID';
}

/**
* The field to use from the data when trying
* to infer an affiliation.
* The required method to handle the Alert.
*
* @return string
* @return mixed
*/
public function getAffiliationField()
protected function getData(): Collection
{

return 'characterID';
return MailMessage::with('body')
->where('sentDate', '>', carbon('now')->subMonth())
->get();

}

/**
Expand Down
24 changes: 12 additions & 12 deletions src/Alerts/Corp/MemberApiState.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ class MemberApiState extends Base

use Corporation, Members;

/**
* The field to use from the data when trying
* to infer an affiliation.
*
* @return string
*/
public function getAffiliationField()
{

return 'corporation_id';
}

/**
* The required method to handle the Alert.
*
Expand All @@ -60,18 +72,6 @@ protected function getData(): Collection
return $members;
}

/**
* The field to use from the data when trying
* to infer an affiliation.
*
* @return string
*/
public function getAffiliationField()
{

return 'corporation_id';
}

/**
* The type of notification.
*
Expand Down
22 changes: 11 additions & 11 deletions src/Alerts/Corp/MemberInactivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,28 @@ class MemberInactivity extends Base
{

/**
* The required method to handle the Alert.
* The field to use form the data when trying
* to infer an affiliation.
*
* @return mixed
* @return string
*/
protected function getData(): Collection
public function getAffiliationField()
{

return MemberTracking::where(
'logoffDateTime', '<', DB::raw('date_sub(NOW(), INTERVAL 3 MONTH)'))
->get();
return 'corporationID';
}

/**
* The field to use form the data when trying
* to infer an affiliation.
* The required method to handle the Alert.
*
* @return string
* @return mixed
*/
public function getAffiliationField()
protected function getData(): Collection
{

return 'corporationID';
return MemberTracking::where(
'logoffDateTime', '<', DB::raw('date_sub(NOW(), INTERVAL 3 MONTH)'))
->get();
}

/**
Expand Down
24 changes: 12 additions & 12 deletions src/Alerts/Corp/StarbaseFuel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ class StarbaseFuel extends Base

use Starbases;

/**
* The field to use from the data when trying
* to infer an affiliation.
*
* @return string
*/
public function getAffiliationField()
{

return 'corporation_id';
}

/**
* The required method to handle the Alert.
*
Expand Down Expand Up @@ -79,18 +91,6 @@ function ($starbase) use ($corporation_id, &$low_feul) {

}

/**
* The field to use from the data when trying
* to infer an affiliation.
*
* @return string
*/
public function getAffiliationField()
{

return 'corporation_id';
}

/**
* The type of notification.
*
Expand Down
24 changes: 12 additions & 12 deletions src/Alerts/Corp/StarbaseStateChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ class StarbaseStateChange extends Base

use Starbases, EveRepository;

/**
* The field to use from the data when trying
* to infer an affiliation.
*
* @return string
*/
public function getAffiliationField()
{

return 'corporation_id';
}

/**
* The required method to handle the Alert.
*
Expand Down Expand Up @@ -75,18 +87,6 @@ function ($starbase) use ($corporation_id, &$starbases) {
return $starbases;
}

/**
* The field to use from the data when trying
* to infer an affiliation.
*
* @return string
*/
public function getAffiliationField()
{

return 'corporation_id';
}

/**
* The type of notification.
*
Expand Down
Loading

0 comments on commit 88ac259

Please sign in to comment.