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

@@ -1,44 +1,49 @@
<?php namespace App;
<?php
namespace App;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
use App\Item;
use App\Setting;
use Form;
use Cache;
use Form;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Yaml;
abstract class Search
{
/**
* List of all search providers
*
* @return Array
*
* @return array
*/
public static function providers()
{
$providers = self::standardProviders();
$providers = $providers + self::appProviders();
return collect($providers);
}
/**
* Gets details for a single provider
*
* @return Object
*
* @return object
*/
public static function providerDetails($provider)
{
$providers = self::providers();
if(!isset($providers[$provider])) return false;
return (object)$providers[$provider] ?? false;
if (! isset($providers[$provider])) {
return false;
}
return (object) $providers[$provider] ?? false;
}
/**
* Array of the standard providers
*
* @return Array
*
* @return array
*/
public static function standardProviders()
{
@@ -46,7 +51,7 @@ abstract class Search
// print_r($providers);
$providers = Yaml::parseFile(storage_path('app/searchproviders.yaml'));
$all = [];
foreach($providers as $key => $provider) {
foreach ($providers as $key => $provider) {
$all[$key] = $provider;
$all[$key]['type'] = 'standard';
}
@@ -57,16 +62,18 @@ abstract class Search
/**
* Loops through users apps to see if app is a search provider, might be worth
* looking into caching this at some point
*
* @return Array
*
* @return array
*/
public static function appProviders()
{
$providers = [];
$userapps = Item::all();
foreach($userapps as $app) {
if(empty($app->class)) continue;
if(($provider = Item::isSearchProvider($app->class)) !== false) {
foreach ($userapps as $app) {
if (empty($app->class)) {
continue;
}
if (($provider = Item::isSearchProvider($app->class)) !== false) {
$name = Item::nameFromClass($app->class);
$providers[$app->id] = [
'id' => $app->id,
@@ -76,17 +83,17 @@ abstract class Search
'name' => $app->title,
'colour' => $app->colour,
'icon' => $app->icon,
'description' => $app->description
'description' => $app->description,
];
}
}
return $providers;
}
/**
* Outputs the search form
*
*
* @return html
*/
public static function form()
@@ -96,15 +103,16 @@ abstract class Search
$search_provider = Setting::where('key', '=', 'search_provider')->first();
$user_search_provider = Setting::fetch('search_provider');
//die(print_r($search_provider));
//die(var_dump($user_search_provider));
// return early if search isn't applicable
if((bool)$homepage_search !== true) return $output;
if ((bool) $homepage_search !== true) {
return $output;
}
$user_search_provider = $user_search_provider ?? 'none';
if((bool)$homepage_search && (bool)$search_provider) {
if((bool)$user_search_provider) {
if ((bool) $homepage_search && (bool) $search_provider) {
if ((bool) $user_search_provider) {
$name = 'app.options.'.$user_search_provider;
$provider = self::providerDetails($user_search_provider);
@@ -112,8 +120,8 @@ abstract class Search
$output .= '<form action="'.url('search').'"'.getLinkTargetAttribute().' method="get">';
$output .= '<div id="search-container" class="input-container">';
$output .= '<select name="provider">';
foreach(self::providers() as $key => $searchprovider) {
$selected = ((string)$key === (string)$user_search_provider) ? ' selected="selected"' : '';
foreach (self::providers() as $key => $searchprovider) {
$selected = ((string) $key === (string) $user_search_provider) ? ' selected="selected"' : '';
$output .= '<option value="'.$key.'"'.$selected.'>'.$searchprovider['name'].'</option>';
}
$output .= '</select>';
@@ -124,8 +132,7 @@ abstract class Search
$output .= '</div>';
}
}
return $output;
}
}