Apply Laravel coding style

Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions.

You may customize the adopted coding style by adding a [PHP CS Fixer][1] or [PHP CodeSniffer][2] config to your project root. Feel free to use [Shift's Laravel ruleset][3] to help you get started.

For more information on customizing the code style applied by Shift, [watch this short video][4].

[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
[2]: https://github.com/squizlabs/PHP_CodeSniffer
[3]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
[4]: https://laravelshift.com/videos/shift-code-style
This commit is contained in:
Shift
2022-03-19 13:54:32 +00:00
parent 0fe6565346
commit b1dc4d4a41
86 changed files with 1051 additions and 1093 deletions

View File

@@ -2,13 +2,13 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\ClassLoader\ClassMapGenerator;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Builder;
use App\User;
use App\ItemTag;
use App\Application;
use App\ItemTag;
use App\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\ClassLoader\ClassMapGenerator;
class Item extends Model
{
@@ -20,7 +20,7 @@ class Item extends Model
static::addGlobalScope('user_id', function (Builder $builder) {
$current_user = User::currentUser();
if($current_user) {
if ($current_user) {
$builder->where('user_id', $current_user->id)->orWhere('user_id', 0);
} else {
$builder->where('user_id', 0);
@@ -30,7 +30,7 @@ class Item extends Model
//
protected $fillable = [
'title', 'url', 'colour', 'icon', 'appdescription', 'description', 'pinned', 'order', 'type', 'class', 'user_id', 'appid'
'title', 'url', 'colour', 'icon', 'appdescription', 'description', 'pinned', 'order', 'type', 'class', 'user_id', 'appid',
];
/**
@@ -54,31 +54,31 @@ class Item extends Model
public static function checkConfig($config)
{
// die(print_r($config));
if(empty($config)) {
if (empty($config)) {
$config = null;
} else {
$config = json_encode($config);
}
return $config;
}
public function tags()
{
$id = $this->id;
$tags = ItemTag::select('tag_id')->where('item_id', $id)->pluck('tag_id')->toArray();
$tagdetails = Item::select('id', 'title', 'url', 'pinned')->whereIn('id', $tags)->get();
$tagdetails = self::select('id', 'title', 'url', 'pinned')->whereIn('id', $tags)->get();
//print_r($tags);
if(in_array(0, $tags)) {
$details = new Item([
"id" => 0,
"title" => __('app.dashboard'),
"url" => '',
"pinned" => 0
if (in_array(0, $tags)) {
$details = new self([
'id' => 0,
'title' => __('app.dashboard'),
'url' => '',
'pinned' => 0,
]);
$tagdetails->prepend($details);
}
return $tagdetails;
}
@@ -86,6 +86,7 @@ class Item extends Model
{
return $this->belongsToMany('App\Item', 'item_tag', 'item_id', 'tag_id');
}
public function children()
{
return $this->belongsToMany('App\Item', 'item_tag', 'tag_id', 'item_id');
@@ -93,7 +94,7 @@ class Item extends Model
public function getLinkAttribute()
{
if((int)$this->type === 1) {
if ((int) $this->type === 1) {
return url('tag/'.$this->url);
} else {
return $this->url;
@@ -102,7 +103,7 @@ class Item extends Model
public function getDroppableAttribute()
{
if((int)$this->type === 1) {
if ((int) $this->type === 1) {
return ' droppable';
} else {
return '';
@@ -113,24 +114,25 @@ class Item extends Model
{
$target = Setting::fetch('window_target');
if((int)$this->type === 1 || $target === 'current') {
if ((int) $this->type === 1 || $target === 'current') {
return '';
} else {
return ' target="' . $target . '"';
return ' target="'.$target.'"';
}
}
public function getLinkIconAttribute()
{
if((int)$this->type === 1) {
if ((int) $this->type === 1) {
return 'fa-tag';
} else {
return 'fa-arrow-alt-to-right';
}
}
public function getLinkTypeAttribute()
{
if((int)$this->type === 1) {
if ((int) $this->type === 1) {
return 'tags';
} else {
return 'items';
@@ -141,13 +143,13 @@ class Item extends Model
{
$explode = explode('\\', $class);
$name = end($explode);
return $name;
}
public function scopeOfType($query, $type)
{
switch($type) {
switch ($type) {
case 'item':
$typeid = 0;
break;
@@ -172,77 +174,81 @@ class Item extends Model
public static function isEnhanced($class)
{
if($class === null || $class === 'null') return false;
if ($class === null || $class === 'null') {
return false;
}
$app = new $class;
return (bool)($app instanceof \App\EnhancedApps);
return (bool) ($app instanceof \App\EnhancedApps);
}
public static function isSearchProvider($class)
{
$app = new $class;
return ((bool)($app instanceof \App\SearchInterface)) ? $app : false;
return ((bool) ($app instanceof \App\SearchInterface)) ? $app : false;
}
public function enabled()
{
if($this->enhanced()) {
if ($this->enhanced()) {
$config = $this->getconfig();
if($config) {
if ($config) {
return (bool) $config->enabled;
}
}
return false;
}
public function getconfig()
{
// $explode = explode('\\', $this->class);
if(!isset($this->description) || empty($this->description)) {
if (! isset($this->description) || empty($this->description)) {
$config = new \stdClass;
// $config->name = end($explode);
$config->enabled = false;
$config->override_url = null;
$config->apikey = null;
return $config;
}
$config = json_decode($this->description);
// $config->name = end($explode);
$config->url = $this->url;
if(isset($config->override_url) && !empty($config->override_url)) {
if (isset($config->override_url) && ! empty($config->override_url)) {
$config->url = $config->override_url;
} else {
$config->override_url = null;
}
return $config;
}
public static function applicationDetails($class)
{
if(!empty($class)) {
if (! empty($class)) {
$name = self::nameFromClass($class);
$application = Application::where('name', $name)->first();
if($application) return $application;
if ($application) {
return $application;
}
}
return false;
}
public static function getApplicationDescription($class)
{
$details = self::applicationDetails($class);
if($details !== false) {
if ($details !== false) {
return $details->description.' - '.$details->license;
}
return '';
}
@@ -252,7 +258,5 @@ class Item extends Model
public function user()
{
return $this->belongsTo('App\User');
}
}
}