Apply fixes from StyleCI

This commit is contained in:
Nabeel Shahzad
2018-08-26 16:40:04 +00:00
committed by StyleCI Bot
parent 20f46adbc4
commit 9596d88b48
407 changed files with 4032 additions and 3286 deletions

View File

@@ -15,7 +15,6 @@ use Log;
* public function check($parameter=null)
*
* See: http://docs.phpvms.net/customizing/awards
* @package App\Interfaces
*/
abstract class Award
{
@@ -25,7 +24,9 @@ abstract class Award
/**
* Each award class just needs to return true or false if it should actually
* be awarded to a user. This is the only method that needs to be implemented
*
* @param null $parameter Optional parameters that are passed in from the UI
*
* @return bool
*/
abstract public function check($parameter = null): bool;
@@ -34,11 +35,12 @@ abstract class Award
* You don't really need to mess with anything below here
*/
protected $award,
$user;
protected $award;
protected $user;
/**
* AwardInterface constructor.
*
* @param AwardModel $award
* @param User $user
*/
@@ -55,7 +57,7 @@ abstract class Award
*/
final public function handle(): void
{
# Check if the params are a JSON object or array
// Check if the params are a JSON object or array
$param = $this->award->ref_model_params;
if (Utils::isObject($this->award->ref_model_params)) {
$param = json_decode($this->award->ref_model_params);
@@ -68,6 +70,7 @@ abstract class Award
/**
* Add the award to this user, if they don't already have it
*
* @return bool|UserAward
*/
final protected function addAward()
@@ -87,13 +90,13 @@ abstract class Award
try {
$award->save();
} catch(\Exception $e) {
} catch (\Exception $e) {
Log::error(
'Error saving award: '.$e->getMessage(),
$e->getTrace()
);
return null;
return;
}
return $award;

View File

@@ -9,7 +9,6 @@ use Illuminate\Http\Request;
/**
* Class Controller
* @package App\Http\Controllers
*/
abstract class Controller extends \Illuminate\Routing\Controller
{
@@ -17,8 +16,10 @@ abstract class Controller extends \Illuminate\Routing\Controller
/**
* Write a error to the flash and redirect the user to a route
*
* @param $message
* @param $route
*
* @return mixed
*/
public function flashError($message, $route)
@@ -29,15 +30,18 @@ abstract class Controller extends \Illuminate\Routing\Controller
/**
* Shortcut function to get the attributes from a request while running the validations
*
* @param Request $request
* @param array $attrs_or_validations
* @param array $addtl_fields
* @return array
*
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
*
* @return array
*/
public function getFromReq($request, $attrs_or_validations, $addtl_fields = null)
{
# See if a list of values is passed in, or if a validation list is passed in
// See if a list of values is passed in, or if a validation list is passed in
$is_validation = false;
if (\count(array_filter(array_keys($attrs_or_validations), '\is_string')) > 0) {
$is_validation = true;
@@ -73,13 +77,16 @@ abstract class Controller extends \Illuminate\Routing\Controller
/**
* Simple normalized method for forming the JSON responses
*
* @param $message
* @param null|mixed $count
*
* @return \Illuminate\Http\JsonResponse
*/
public function message($message, $count = null)
{
$attrs = [
'message' => $message
'message' => $message,
];
if ($count !== null) {

View File

@@ -4,7 +4,6 @@ namespace App\Interfaces;
/**
* Borrowed some ideas from myclabs/php-enum after this was created
* @package App\Models\Enums
*/
abstract class Enum
{
@@ -13,12 +12,13 @@ abstract class Enum
protected static $labels = [];
/**
* @var integer
* @var int
*/
protected $value;
/**
* Create an instance of this Enum
*
* @param $val
*/
public function __construct($val)
@@ -28,6 +28,7 @@ abstract class Enum
/**
* Return the value that's been set if this is an instance
*
* @return mixed
*/
final public function getValue()
@@ -37,7 +38,9 @@ abstract class Enum
/**
* Return the label, try to return the translated version as well
*
* @param $value
*
* @return mixed
*/
final public static function label($value)
@@ -62,7 +65,9 @@ abstract class Enum
/**
* Get the numeric value from a string code
*
* @param $code
*
* @return mixed|null
*/
public static function getFromCode($code)
@@ -72,14 +77,16 @@ abstract class Enum
/**
* Convert the integer value into one of the codes
*
* @param $value
*
* @return false|int|string
*/
public static function convertToCode($value)
{
$value = (int) $value;
if (!array_key_exists($value, static::$codes)) {
return null;
return;
}
return static::$codes[$value];
@@ -87,7 +94,9 @@ abstract class Enum
/**
* Select box entry items
* @param bool $add_blank
*
* @param bool $add_blank
*
* @return array
*/
public static function select($add_blank = false): array
@@ -106,8 +115,10 @@ abstract class Enum
/**
* Returns all possible values as an array
* @return array Constant name in key, constant value in value
*
* @throws \ReflectionException
*
* @return array Constant name in key, constant value in value
*/
public static function toArray(): array
{
@@ -122,9 +133,10 @@ abstract class Enum
/**
* @param Enum $enum
*
* @return bool
*/
final public function equals(Enum $enum): bool
final public function equals(self $enum): bool
{
return $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum);
}
@@ -132,11 +144,14 @@ abstract class Enum
/**
* Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a
* class constant
*
* @param string $name
* @param array $arguments
* @return static
*
* @throws \BadMethodCallException
* @throws \ReflectionException
*
* @return static
*/
public static function __callStatic($name, $arguments)
{
@@ -144,6 +159,7 @@ abstract class Enum
if (isset($array[$name])) {
return new static($array[$name]);
}
throw new \BadMethodCallException(
"No static method or enum constant '$name' in class ".get_called_class()
);

View File

@@ -4,7 +4,6 @@ namespace App\Interfaces;
/**
* Class FormRequest
* @package App\Interfaces
*/
class FormRequest extends \Illuminate\Foundation\Http\FormRequest
{

View File

@@ -9,14 +9,13 @@ use Validator;
/**
* Common functionality used across all of the importers
* @package App\Interfaces
*/
class ImportExport
{
public $assetType;
public $status = [
'success' => [],
'errors' => [],
'errors' => [],
];
/**
@@ -26,6 +25,7 @@ class ImportExport
/**
* @param mixed $row
*
* @return array
*/
public function export($row): array
@@ -36,8 +36,10 @@ class ImportExport
/**
* @param array $row
* @param mixed $index
* @return bool
*
* @throws \RuntimeException
*
* @return bool
*/
public function import(array $row, $index): bool
{
@@ -46,7 +48,9 @@ class ImportExport
/**
* Get the airline from the ICAO. Create it if it doesn't exist
*
* @param $code
*
* @return Airline
*/
public function getAirline($code)
@@ -68,7 +72,9 @@ class ImportExport
/**
* Do a basic check that the number of columns match
*
* @param $row
*
* @return bool
*/
public function checkColumns($row): bool
@@ -78,8 +84,10 @@ class ImportExport
/**
* Bubble up an error to the interface that we need to stop
*
* @param $error
* @param $e
*
* @throws ValidationException
*/
protected function throwError($error, \Exception $e = null): void
@@ -91,11 +99,13 @@ class ImportExport
$validator = Validator::make([], []);
$validator->errors()->add('csv_file', $error);
throw new ValidationException($validator);
}
/**
* Add to the log messages for this importer
*
* @param $msg
*/
public function log($msg): void
@@ -106,6 +116,7 @@ class ImportExport
/**
* Add to the error log for this import
*
* @param $msg
*/
public function errorLog($msg): void
@@ -116,15 +127,16 @@ class ImportExport
/**
* Set a key-value pair to an array
*
* @param $kvp_str
* @param array $arr
*/
protected function kvpToArray($kvp_str, array &$arr)
{
$item = explode('=', $kvp_str);
if (\count($item) === 1) { # just a list?
if (\count($item) === 1) { // just a list?
$arr[] = trim($item[0]);
} else { # actually a key-value pair
} else { // actually a key-value pair
$k = trim($item[0]);
$v = trim($item[1]);
$arr[$k] = $v;
@@ -140,6 +152,7 @@ class ImportExport
* Converted into a multi-dimensional array
*
* @param $field
*
* @return array|string
*/
public function parseMultiColumnValues($field)
@@ -147,9 +160,9 @@ class ImportExport
$ret = [];
$split_values = explode(';', $field);
# No multiple values in here, just a straight value
// No multiple values in here, just a straight value
if (\count($split_values) === 1) {
if(trim($split_values[0]) === '') {
if (trim($split_values[0]) === '') {
return [];
}
@@ -157,15 +170,15 @@ class ImportExport
}
foreach ($split_values as $value) {
# This isn't in the query string format, so it's
# just a straight key-value pair set
// This isn't in the query string format, so it's
// just a straight key-value pair set
if (strpos($value, '?') === false) {
$this->kvpToArray($value, $ret);
continue;
}
# This contains the query string, which turns it
# into the multi-level array
// This contains the query string, which turns it
// into the multi-level array
$query_str = explode('?', $value);
$parent = trim($query_str[0]);
@@ -173,7 +186,7 @@ class ImportExport
$children = [];
$kvp = explode('&', trim($query_str[1]));
foreach ($kvp as $items) {
if(!$items) {
if (!$items) {
continue;
}
@@ -188,30 +201,31 @@ class ImportExport
/**
* @param $obj
*
* @return mixed
*/
public function objectToMultiString($obj)
{
if(!\is_array($obj)) {
if (!\is_array($obj)) {
return $obj;
}
$ret_list = [];
foreach ($obj as $key => $val) {
if(is_numeric($key) && !\is_array($val)) {
if (is_numeric($key) && !\is_array($val)) {
$ret_list[] = $val;
continue;
}
$key = trim($key);
if(!\is_array($val)) {
if (!\is_array($val)) {
$val = trim($val);
$ret_list[] = "{$key}={$val}";
} else {
$q = [];
foreach($val as $subkey => $subval) {
if(is_numeric($subkey)) {
foreach ($val as $subkey => $subval) {
if (is_numeric($subkey)) {
$q[] = $subval;
} else {
$q[] = "{$subkey}={$subval}";
@@ -219,7 +233,7 @@ class ImportExport
}
$q = implode('&', $q);
if(!empty($q)) {
if (!empty($q)) {
$ret_list[] = "{$key}?{$q}";
} else {
$ret_list[] = $key;

View File

@@ -4,9 +4,7 @@ namespace App\Interfaces;
/**
* Class Listener
* @package App\Interfaces
*/
abstract class Listener
{
}

View File

@@ -7,7 +7,6 @@ use Log;
/**
* Base class for implementing retrieving METARs
* @package App\Interfaces
*/
abstract class Metar
{
@@ -15,20 +14,25 @@ abstract class Metar
* Implement retrieving the METAR- Return the string
* Needs to be protected, since this shouldn't be
* directly called. Call `get_metar($icao)` instead
*
* @param $icao
*
* @return mixed
*/
abstract protected function metar($icao): string;
/**
* @param $icao
*
* @return string
*/
//abstract protected function taf($icao): string;
/**
* Download the METAR, wrap in caching
*
* @param $icao
*
* @return string
*/
public function get_metar($icao): string
@@ -43,7 +47,7 @@ abstract class Metar
Log::error('Error getting METAR: '.$e->getMessage(), $e->getTrace());
return '';
} catch (\Exception $e) {
Log::error('Error getting METAR: '. $e->getMessage(), $e->getTrace());
Log::error('Error getting METAR: '.$e->getMessage(), $e->getTrace());
return '';
}
});

View File

@@ -7,7 +7,6 @@ use DB;
/**
* Class Migration
* @package App\Interfaces
*/
abstract class Migration extends \Illuminate\Database\Migrations\Migration
{
@@ -16,6 +15,7 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
/**
* At a minimum, this function needs to be implemented
*
* @return mixed
*/
abstract public function up();
@@ -25,13 +25,13 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
*/
public function down()
{
}
/**
* Dynamically figure out the offset and the start number for a group.
* This way we don't need to mess with how to order things
* When calling getNextOrderNumber(users) 31, will be returned, then 32, and so on
*
* @param $name
* @param null $offset
* @param int $start_offset
@@ -53,12 +53,12 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
$start_offset = $offset + 1;
}
} else {
# Now find the number to start from
// Now find the number to start from
$start_offset = (int) DB::table('settings')->where('group', $name)->max('order');
if ($start_offset === null) {
$start_offset = $offset + 1;
} else {
++$start_offset;
$start_offset++;
}
$offset = $group->offset;
@@ -71,7 +71,9 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
/**
* Get the next increment number from a group
*
* @param $group
*
* @return int
*/
public function getNextOrderNumber($group): int
@@ -81,7 +83,7 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
}
$idx = $this->counters[$group];
++$this->counters[$group];
$this->counters[$group]++;
return $idx;
}
@@ -114,6 +116,7 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
/**
* Update a setting
*
* @param $key
* @param $value
* @param array $attrs
@@ -128,6 +131,7 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
/**
* Add rows to a table
*
* @param $table
* @param $rows
*/
@@ -137,7 +141,7 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
try {
DB::table($table)->insert($row);
} catch (\Exception $e) {
# setting already exists, just ignore it
// setting already exists, just ignore it
if ($e->getCode() === 23000) {
continue;
}

View File

@@ -4,9 +4,9 @@ namespace App\Interfaces;
/**
* Class Model
*
* @property mixed $id
* @property bool $skip_mutator
* @package App\Interfaces
*/
abstract class Model extends \Illuminate\Database\Eloquent\Model
{
@@ -14,6 +14,7 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model
/**
* For the factories, skip the mutators. Only apply to one instance
*
* @var bool
*/
public $skip_mutator = false;

View File

@@ -6,13 +6,13 @@ use Illuminate\Validation\Validator;
/**
* Class Repository
* @package App\Interfaces
*/
abstract class Repository extends \Prettus\Repository\Eloquent\BaseRepository
{
/**
* @param $id
* @param array $columns
*
* @return mixed|null
*/
public function findWithoutFail($id, $columns = ['*'])
@@ -20,12 +20,13 @@ abstract class Repository extends \Prettus\Repository\Eloquent\BaseRepository
try {
return $this->find($id, $columns);
} catch (\Exception $e) {
return null;
return;
}
}
/**
* @param $values
*
* @return bool
*/
public function validate($values)
@@ -44,8 +45,10 @@ abstract class Repository extends \Prettus\Repository\Eloquent\BaseRepository
/**
* Return N most recent items, sorted by created_at
*
* @param int $count
* @param string $sort_by created_at (default) or updated_at
*
* @return mixed
*/
public function recent($count = null, $sort_by = 'created_at')
@@ -55,16 +58,18 @@ abstract class Repository extends \Prettus\Repository\Eloquent\BaseRepository
/**
* Find records with a WHERE clause but also sort them
*
* @param $where
* @param $sort_by
* @param $order_by
*
* @return $this
*/
public function whereOrder($where, $sort_by, $order_by = 'asc')
{
return $this->scopeQuery(function ($query) use ($where, $sort_by, $order_by) {
$q = $query->where($where);
# See if there are multi-column sorts
// See if there are multi-column sorts
if (\is_array($sort_by)) {
foreach ($sort_by as $key => $sort) {
$q = $q->orderBy($key, $sort);
@@ -79,17 +84,19 @@ abstract class Repository extends \Prettus\Repository\Eloquent\BaseRepository
/**
* Find records where values don't match a list but sort the rest
*
* @param string $col
* @param array $values
* @param string $sort_by
* @param string $order_by
*
* @return $this
*/
public function whereNotInOrder($col, $values, $sort_by, $order_by = 'asc')
{
return $this->scopeQuery(function ($query) use ($col, $values, $sort_by, $order_by) {
$q = $query->whereNotIn($col, $values);
# See if there are multi-column sorts
// See if there are multi-column sorts
if (\is_array($sort_by)) {
foreach ($sort_by as $key => $sort) {
$q = $q->orderBy($key, $sort);

View File

@@ -4,9 +4,7 @@ namespace App\Interfaces;
/**
* Class Service
* @package App\Interfaces
*/
abstract class Service
{
}

View File

@@ -6,7 +6,7 @@ use ArrayAccess;
/**
* Class Unit
* @package App\Interfaces
*
* @property mixed $instance
* @property string $unit
* @property array $units
@@ -20,12 +20,14 @@ class Unit implements ArrayAccess
/**
* All of the units of this class
*
* @var array
*/
public $units;
/**
* Holds an instance of the PhpUnit type
*
* @var
*/
protected $instance;
@@ -40,7 +42,9 @@ class Unit implements ArrayAccess
/**
* Implements ArrayAccess
*
* @param $offset
*
* @return bool
*/
public function offsetExists($offset)
@@ -50,7 +54,9 @@ class Unit implements ArrayAccess
/**
* Implements ArrayAccess
*
* @param $offset
*
* @return mixed
*/
public function offsetGet($offset)
@@ -60,6 +66,7 @@ class Unit implements ArrayAccess
/**
* Implements ArrayAccess
*
* @param $offset
* @param $value
*/
@@ -70,6 +77,7 @@ class Unit implements ArrayAccess
/**
* Implements ArrayAccess
*
* @param $offset
*/
public function offsetUnset($offset)

View File

@@ -6,7 +6,6 @@ use Arrilot\Widgets\AbstractWidget;
/**
* Class Widget
* @package App\Widgets
*/
abstract class Widget extends AbstractWidget
{
@@ -14,8 +13,10 @@ abstract class Widget extends AbstractWidget
/**
* Render the template
*
* @param string $template
* @param array $vars
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function view(string $template, array $vars = [])