Fix formatting and interfaces in nearly every file
This commit is contained in:
@@ -5,8 +5,15 @@ namespace App\Facades;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* Class Utils
|
||||
* @package App\Facades
|
||||
*/
|
||||
class Utils extends Facade
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'utils';
|
||||
@@ -19,11 +26,11 @@ class Utils extends Facade
|
||||
*/
|
||||
public static function isObject($obj)
|
||||
{
|
||||
if(!$obj) {
|
||||
if (!$obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($obj[0] === '{' || $obj[0] === '[') {
|
||||
if ($obj[0] === '{' || $obj[0] === '[') {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,15 +40,15 @@ class Utils extends Facade
|
||||
/**
|
||||
* Download a URI. If a file is given, it will save the downloaded
|
||||
* content into that file
|
||||
* @param $uri
|
||||
* @param $uri
|
||||
* @param null $file
|
||||
* @return string
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function downloadUrl($uri, $file=null)
|
||||
public static function downloadUrl($uri, $file = null)
|
||||
{
|
||||
$opts = [];
|
||||
if($file !== null) {
|
||||
if ($file !== null) {
|
||||
$opts['sink'] = $file;
|
||||
}
|
||||
|
||||
@@ -49,21 +56,20 @@ class Utils extends Facade
|
||||
$response = $client->request('GET', $uri, $opts);
|
||||
|
||||
$body = $response->getBody()->getContents();
|
||||
if($response->getHeader('content-type') === 'application/json') {
|
||||
if ($response->getHeader('content-type') === 'application/json') {
|
||||
$body = \GuzzleHttp\json_decode($body);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 40 character API key that a user can use
|
||||
* @return string
|
||||
*/
|
||||
public static function generateApiKey()
|
||||
{
|
||||
$key = substr(sha1(time() . mt_rand()), 0, 20);
|
||||
$key = substr(sha1(time().mt_rand()), 0, 20);
|
||||
return $key;
|
||||
}
|
||||
|
||||
@@ -78,7 +84,7 @@ class Utils extends Facade
|
||||
public static function minutesToTimeString($minutes): string
|
||||
{
|
||||
$hm = self::minutesToTimeParts($minutes);
|
||||
return $hm['h']. 'h '. $hm['m'] . 'm';
|
||||
return $hm['h'].'h '.$hm['m'].'m';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,15 +109,15 @@ class Utils extends Facade
|
||||
|
||||
/**
|
||||
* Convert seconds to HH MM format
|
||||
* @param $seconds
|
||||
* @param $seconds
|
||||
* @param bool $incl_sec
|
||||
* @return string
|
||||
*/
|
||||
public static function secondsToTimeString($seconds, $incl_sec=false): string
|
||||
public static function secondsToTimeString($seconds, $incl_sec = false): string
|
||||
{
|
||||
$hms = self::secondsToTimeParts($seconds);
|
||||
$format = $hms['h'].'h '.$hms['m'].'m';
|
||||
if($incl_sec) {
|
||||
if ($incl_sec) {
|
||||
$format .= ' '.$hms['s'].'s';
|
||||
}
|
||||
|
||||
@@ -134,7 +140,7 @@ class Utils extends Facade
|
||||
*/
|
||||
public static function secondsToMinutes($seconds)
|
||||
{
|
||||
return ceil($seconds/60);
|
||||
return ceil($seconds / 60);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,18 +150,18 @@ class Utils extends Facade
|
||||
*/
|
||||
public static function minutesToHours($minutes)
|
||||
{
|
||||
return $minutes/60;
|
||||
return $minutes / 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $hours
|
||||
* @param $hours
|
||||
* @param null $minutes
|
||||
* @return float|int
|
||||
*/
|
||||
public static function hoursToMinutes($hours, $minutes=null)
|
||||
public static function hoursToMinutes($hours, $minutes = null)
|
||||
{
|
||||
$total = (int) $hours * 60;
|
||||
if($minutes) {
|
||||
if ($minutes) {
|
||||
$total += (int) $minutes;
|
||||
}
|
||||
|
||||
@@ -164,12 +170,13 @@ class Utils extends Facade
|
||||
|
||||
/**
|
||||
* Bitwise operator for setting days of week to integer field
|
||||
* @param int $datefield initial datefield
|
||||
* @param int $datefield initial datefield
|
||||
* @param array $day_enums Array of values from config("enum.days")
|
||||
* @return int
|
||||
*/
|
||||
public static function setDays(int $datefield, array $day_enums) {
|
||||
foreach($day_enums as $day) {
|
||||
public static function setDays(int $datefield, array $day_enums)
|
||||
{
|
||||
foreach ($day_enums as $day) {
|
||||
$datefield |= $day;
|
||||
}
|
||||
|
||||
@@ -179,10 +186,11 @@ class Utils extends Facade
|
||||
/**
|
||||
* Bit check if a day exists within a integer bitfield
|
||||
* @param int $datefield datefield from database
|
||||
* @param int $day_enum Value from config("enum.days")
|
||||
* @param int $day_enum Value from config("enum.days")
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasDay(int $datefield, int $day_enum) {
|
||||
public static function hasDay(int $datefield, int $day_enum)
|
||||
{
|
||||
return ($datefield & $day_enum) === $datefield;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user