Remove unused code

This commit is contained in:
Pig Fang 2019-03-22 11:13:21 +08:00
parent 21707dbe5d
commit 6793ccea30
13 changed files with 21 additions and 346 deletions

View File

@ -485,15 +485,6 @@ class OptionFormItem
return $this;
}
/**
* Render option item. Should be extended.
*
* @return \Illuminate\View\View|string
*/
public function render()
{
}
}
class OptionFormText extends OptionFormItem

View File

@ -2,9 +2,7 @@
namespace App\Services;
use ArrayAccess;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Support\Arrayable;
/**
* @property string $name
@ -12,7 +10,7 @@ use Illuminate\Contracts\Support\Arrayable;
* @property string $title
* @property array $author
*/
class Plugin implements Arrayable, ArrayAccess
class Plugin
{
/**
* The full directory of this plugin.
@ -112,14 +110,6 @@ class Plugin implements Arrayable, ArrayAccess
return $this;
}
/**
* @return bool
*/
public function isInstalled()
{
return $this->installed;
}
public function getDirname()
{
return $this->dirname;
@ -230,63 +220,4 @@ class Plugin implements Arrayable, ArrayAccess
{
return $this->path;
}
/**
* Determine if the given option option exists.
*
* @param string $key
* @return bool
*/
public function offsetExists($key)
{
return Arr::has($this->packageInfo, $key);
}
/**
* Get a option option.
*
* @param string $key
* @return mixed
*/
public function offsetGet($key)
{
return $this->packageInfoAttribute($key);
}
/**
* Set a option option.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function offsetSet($key, $value)
{
return Arr::set($this->packageInfo, $key, $value);
}
/**
* Unset a option option.
*
* @param string $key
* @return void
*/
public function offsetUnset($key)
{
unset($this->packageInfo[$key]);
}
/**
* Generates an array result for the object.
*
* @return array
*/
public function toArray()
{
return (array) array_merge([
'name' => $this->name,
'version' => $this->getVersion(),
'path' => $this->path,
], $this->packageInfo);
}
}

View File

@ -136,25 +136,6 @@ class OptionRepository extends Repository
}
}
/**
* Return the options with key in the given array.
*
* @param array $array
* @return array
*/
public function only(array $array)
{
$result = [];
foreach ($this->items as $key => $value) {
if (in_array($key, $array)) {
$result[$key] = $value;
}
}
return $result;
}
/**
* Save all modified options into database.
*/

View File

@ -2,10 +2,9 @@
namespace App\Services\Repositories;
use ArrayAccess;
use Illuminate\Support\Arr;
class Repository implements ArrayAccess // Illuminate\Contracts\Cache\Repository
class Repository
{
/**
* All of the items.
@ -64,102 +63,4 @@ class Repository implements ArrayAccess // Illuminate\Contracts\Cache\Repository
$this->itemsModified[] = $key;
}
}
/**
* Push an item into the repository.
*
* @param mixed $item
* @return void
*/
public function push($item)
{
array_push($this->items, $item);
}
/**
* Get all of the items stored in the repository.
*
* @return array
*/
public function all()
{
return $this->items;
}
/**
* Get an item from the repository, or store the default value.
*
* @param string $key
* @param callable $callback
* @return mixed
*/
public function remember($key, callable $callback)
{
// If the item exists in the repository we will just return this immediately
// otherwise we will execute the given Closure and repository the result
// of that execution for the given number of minutes in storage.
if (! is_null($value = $this->get($key))) {
return $value;
}
$this->set($key, $value = $callback());
return $value;
}
/**
* Remove an item from the repository.
*
* @param string|array $key
* @return void
*/
public function forget($key)
{
Arr::forget($this->items, $key);
}
/**
* Determine if the given option option exists.
*
* @param string $key
* @return bool
*/
public function offsetExists($key)
{
return $this->has($key);
}
/**
* Get a option option.
*
* @param string $key
* @return mixed
*/
public function offsetGet($key)
{
return $this->get($key);
}
/**
* Set a option option.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function offsetSet($key, $value)
{
$this->set($key, $value);
}
/**
* Unset a option option.
*
* @param string $key
* @return void
*/
public function offsetUnset($key)
{
$this->forget($key);
}
}

View File

@ -75,9 +75,4 @@ class UserRepository extends Repository
return current($result);
}
public function getCurrentUser()
{
return auth()->user();
}
}

View File

@ -16,13 +16,6 @@ if (! function_exists('get_base_url')) {
}
}
if (! function_exists('get_current_url')) {
function get_current_url()
{
return get_base_url().$_SERVER['REQUEST_URI'];
}
}
if (! function_exists('avatar')) {
function avatar(User $user, $size)
{
@ -32,25 +25,13 @@ if (! function_exists('avatar')) {
}
}
if (! function_exists('assets')) {
function assets($relativeUri)
{
// Add query string to fresh cache
if (Str::startsWith($relativeUri, 'css') || Str::startsWith($relativeUri, 'js')) {
return url("resources/assets/dist/$relativeUri").'?v='.config('app.version');
} elseif (Str::startsWith($relativeUri, 'lang')) {
return url("resources/$relativeUri");
} else {
return url("resources/assets/$relativeUri");
}
}
}
if (! function_exists('webpack_assets')) {
function webpack_assets($relativeUri)
{
if (app()->environment('development')) {
// @codeCoverageIgnoreStart
return "http://127.0.0.1:8080/public/$relativeUri";
// @codeCoverageIgnoreEnd
} else {
$cdn = option('cdn_address');
return $cdn ? "$cdn/app/$relativeUri" : url("app/$relativeUri");
@ -266,15 +247,6 @@ if (! function_exists('bs_custom_copyright')) {
}
}
if (! function_exists('bs_nickname')) {
function bs_nickname(User $user = null)
{
$user = $user ?: auth()->user();
return ($user->getNickName() == '') ? $user->email : $user->getNickName();
}
}
if (! function_exists('bs_role')) {
function bs_role(User $user = null)
{

View File

@ -61,7 +61,7 @@
<img src="{{ avatar($user, 45) }}" alt="User Image">
</div>
<div class="pull-left info">
<p class="nickname">{{ bs_nickname($user) }}</p>
<p class="nickname">{{ $user->nickname ?? $user->email }}</p>
<i class="fas fa-circle text-success"></i> {{ bs_role($user) }}
</div>
</div>

View File

@ -10,7 +10,7 @@
@endif
<!-- hidden-xs hides the username on small devices so only the image appears. -->
<span class="hidden-xs nickname">{{ bs_nickname($user) }}</span>
<span class="hidden-xs nickname">{{ $user->nickname ?? $user->email }}</span>
</a>
<ul class="dropdown-menu">
<!-- The user image in the menu -->

View File

@ -26,7 +26,11 @@
<div class="box-body">
@if (option('comment_script') != "")
<!-- Comment Start -->
{!! get_string_replaced(option('comment_script'), ['{tid}' => $texture->tid, '{name}' => $texture->name, '{url}' => get_current_url()]) !!}
{!! get_string_replaced(option('comment_script'), [
'{tid}' => $texture->tid,
'{name}' => $texture->name,
'{url}' => get_base_url().$_SERVER['REQUEST_URI']
]) !!}
<!-- Comment End -->
@else
<p style="text-align: center; margin: 30px 0;">@lang('skinlib.show.comment-not-available')</p>

View File

@ -57,7 +57,7 @@
<img src="{{ avatar($user, 45) }}" alt="User Image">
</div>
<div class="pull-left info">
<p class="nickname">{{ bs_nickname($user) }}</p>
<p class="nickname">{{ $user->nickname ?? $user->email }}</p>
<i class="fas fa-circle text-success"></i> {{ bs_role($user) }}
</div>
</div>

View File

@ -24,6 +24,8 @@ class AdminControllerTest extends BrowserKitTestCase
public function testChartData()
{
factory(User::class)->create();
factory(Texture::class)->create();
$this->getJson('/admin/chart')
->seeJson(['labels' => [
trans('admin.index.user-registration'),

View File

@ -14,6 +14,7 @@ class OptionRepositoryTest extends TestCase
$repo = new OptionRepository();
$repo->set('k1', '(null)');
$this->assertNull($repo->get('k1'));
$this->assertNull(option()->get('k1'));
}
public function testSet()
@ -26,18 +27,4 @@ class OptionRepositoryTest extends TestCase
$this->assertEquals('v1', $repo->get('k1'));
$this->assertEquals('v2', $repo->get('k2'));
}
public function testOnly()
{
$repo = new OptionRepository();
$repo->set([
'k1' => 'v1',
'k2' => 'v2',
'k3' => 'v3',
]);
$this->assertArraySubset([
'k1' => 'v1',
'k2' => 'v2',
], $repo->only(['k1', 'k2']));
}
}

View File

@ -9,18 +9,17 @@ class RepositoryTest extends TestCase
public function testHas()
{
$repo = new Repository();
$repo->push('a');
$this->assertTrue($repo->has(0));
$this->assertFalse($repo->has(1));
$repo->set('a', 'b');
$this->assertTrue($repo->has('a'));
$this->assertFalse($repo->has('b'));
}
public function testGet()
{
$repo = new Repository();
$repo->push('a');
$this->assertEquals('a', $repo->get(0));
$this->assertNull($repo->get(1));
$this->assertEquals('b', $repo->get(1, 'b'));
$repo->set('a', 'b');
$this->assertEquals('b', $repo->get('a'));
$this->assertNull($repo->get('b'));
}
public function testSet()
@ -36,92 +35,4 @@ class RepositoryTest extends TestCase
$this->assertEquals('v2', $repo->get('k2'));
$this->assertEquals('v3', $repo->get('k3'));
}
public function testPush()
{
$repo = new Repository();
$repo->push('a');
$this->assertEquals('a', $repo->get(0));
}
public function testAll()
{
$repo = new Repository();
$repo->set('k1', 'v1');
$repo->set([
'k2' => 'v2',
'k3' => 'v3',
]);
$repo->push('a');
$this->assertArraySubset([
'k1' => 'v1',
'k2' => 'v2',
'k3' => 'v3',
0 => 'a',
], $repo->all());
}
public function testRemember()
{
$repo = new Repository();
$repo->set('k1', 'v1');
$this->assertEquals(
'v1',
$repo->remember('k1', function () {
})
);
$this->assertEquals(
'v2',
$repo->remember('k2', function () {
return 'v2';
})
);
}
public function testForget()
{
$repo = new Repository();
$repo->set('k1', 'v1');
$repo->forget('k1');
$this->assertFalse($repo->has('k1'));
$repo->set([
'k2' => 'v2',
'k3' => 'v3',
]);
$repo->forget(['k2', 'k3']);
$this->assertFalse($repo->has('k2'));
$this->assertFalse($repo->has('k3'));
}
public function testOffsetExists()
{
$repo = new Repository();
$repo->set('k1', 'v1');
$this->assertTrue($repo->offsetExists('k1'));
}
public function testOffsetGet()
{
$repo = new Repository();
$repo->push('a');
$this->assertEquals('a', $repo->offsetGet(0));
$this->assertNull($repo->get(1));
}
public function testOffsetSet()
{
$repo = new Repository();
$repo->offsetSet('k1', 'v1');
$this->assertEquals('v1', $repo->get('k1'));
}
public function testOffsetUnset()
{
$repo = new Repository();
$repo->set('k1', 'v1');
$repo->offsetUnset('k1');
$this->assertFalse($repo->has('k1'));
}
}