Skip to content

Commit

Permalink
run composer lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Nov 14, 2023
1 parent e021f14 commit 007fb9d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/Users/GrantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public function getPets() {
/**
* Gets all variants of a pet.
*
* @param \Illuminate\Http\Request $request
*
* @param mixed $id
*/
public function getPetVariants($id) {
$pet = Pet::find($id);

return $pet->variants->pluck('variant_name', 'id')->toArray();
}

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Users/PetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use App\Services\PetDropService;
use App\Services\PetManager;
use Auth;
use Log;
use Illuminate\Http\Request;

class PetController extends Controller {
Expand Down Expand Up @@ -67,6 +66,7 @@ public function getStack(Request $request, $id) {
if (in_array('default', $tag->data['variant_ids'])) {
return true;
}

return PetVariant::whereIn('id', $tag->data['variant_ids'])->where('pet_id', $stack->pet_id)->exists();
} else {
return true;
Expand Down Expand Up @@ -260,6 +260,7 @@ public function getPetPage($id) {
if (in_array('default', $tag->data['variant_ids'])) {
return true;
}

return PetVariant::whereIn('id', $tag->data['variant_ids'])->where('pet_id', $pet->pet_id)->exists();
} else {
return true;
Expand Down
10 changes: 5 additions & 5 deletions app/Models/User/UserPet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Models\User;

use Carbon\Carbon;
use App\Models\Model;
use App\Models\Pet\PetDrop;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\SoftDeletes;

class UserPet extends Model {
Expand Down Expand Up @@ -89,8 +89,8 @@ public function drops() {
'parameters' => $this->pet->dropData->rollParameters(),
'drops_available' => 0,
'next_day' => Carbon::now()
->add($this->pet->dropData->frequency, $this->pet->dropData->interval)
->startOf($this->pet->dropData->interval),
->add($this->pet->dropData->frequency, $this->pet->dropData->interval)
->startOf($this->pet->dropData->interval),
]);
// if we delete old drop data, populate with new
} elseif (!PetDrop::where('user_pet_id', $this->id)->where('drop_id', $this->pet->dropData->id)->first()) {
Expand All @@ -101,8 +101,8 @@ public function drops() {
'parameters' => $this->pet->dropData->rollParameters(),
'drops_available' => 0,
'next_day' => Carbon::now()
->add($this->pet->dropData->frequency, $this->pet->dropData->interval)
->startOf($this->pet->dropData->interval),
->add($this->pet->dropData->frequency, $this->pet->dropData->interval)
->startOf($this->pet->dropData->interval),
]);
}

Expand Down
13 changes: 5 additions & 8 deletions app/Services/Item/SpliceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,21 @@ public function getEditData() {
/**
* Processes the data attribute of the tag and returns it in the preferred format.
*
* @param $tag
*
* @return mixed
*/
public function getTagData($tag) {
$displayVariants = [];
if ($tag->data['variant_ids']) {
foreach ($tag->data['variant_ids'] as $variantId) {
if ($variantId == "default") {
if ($variantId == 'default') {
$displayVariants[] = 'Default';
}
else {
} else {
$variant = PetVariant::find($variantId);
$displayVariants[] = '<a href="'. $variant->pet->url .'" target="_blank">'. $variant->variant_name .' ('. $variant->pet->name .')</a>';
$displayVariants[] = '<a href="'.$variant->pet->url.'" target="_blank">'.$variant->variant_name.' ('.$variant->pet->name.')</a>';
}
}
}

return [
'variant_ids' => $tag->data['variant_ids'] ?? null,
'variants' => $tag->data['variant_ids'] ? PetVariant::whereIn('id', $tag->data['variant_ids'])->get() : null,
Expand All @@ -65,15 +63,14 @@ public function getTagData($tag) {
* Processes the data attribute of the tag and returns it in the preferred format.
*
* @param mixed $tag
* @param array $data
* @param array $data
*
* @return bool
*/
public function updateData($tag, $data) {
DB::beginTransaction();

try {

$tag->data = json_encode([
'variant_ids' => $data['variant_ids'],
]);
Expand Down
21 changes: 10 additions & 11 deletions app/Services/PetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function grantPets($data, $staff) {

$keyed_variant = [];
array_walk($data['pet_ids'], function ($id, $key) use (&$keyed_variant, $data) {
if ($id != null && ! in_array($id, array_keys($keyed_variant), true)) {
if ($id != null && !in_array($id, array_keys($keyed_variant), true)) {
$keyed_variant[$id] = $data['variant'][$key];
}
});
Expand Down Expand Up @@ -363,7 +363,9 @@ public function editVariant($id, $pet, $stack_id, $isStaff = false) {
throw new \Exception('No item selected.');
}

if ($id == 0) $id = "default";
if ($id == 0) {
$id = 'default';
}

// check if user has item
$item = UserItem::find($stack_id);
Expand All @@ -385,7 +387,7 @@ public function editVariant($id, $pet, $stack_id, $isStaff = false) {
}
// else logAdminAction($pet->user, 'Pet Variant Changed', ['pet' => $pet->id, 'variant' => $id]); // for when develop is merged

$pet['variant_id'] = $id == "default" ? null : $id;
$pet['variant_id'] = $id == 'default' ? null : $id;
$pet->save();

return $this->commitReturn(true);
Expand Down Expand Up @@ -510,6 +512,7 @@ public function editCustomImageDescription($pet, $data) {
* @param array $data
* @param \App\Models\Pet\Pet $pet
* @param int $quantity
* @param mixed $variant_id
*
* @return bool
*/
Expand All @@ -518,19 +521,16 @@ public function creditPet($sender, $recipient, $type, $data, $pet, $quantity, $v

try {
for ($i = 0; $i < $quantity; $i++) {

if ($variant_id == 'randomize' && count($pet->variants)) {
// randomly get a variant
$variant = $pet->variants->random();
// 25% chance to be no variant
if (rand(1, 4) == 1) {
$variant = null;
}
}
else if ($variant_id == 'none') {
} elseif ($variant_id == 'none') {
$variant = null;
}
else {
} else {
$variant = $pet->variants->where('id', $variant_id)->first();
}

Expand All @@ -540,7 +540,6 @@ public function creditPet($sender, $recipient, $type, $data, $pet, $quantity, $v
'data' => json_encode($data),
'variant_id' => $variant?->id,
]);

}

// Create drop information for the pet, if relevant
Expand All @@ -551,8 +550,8 @@ public function creditPet($sender, $recipient, $type, $data, $pet, $quantity, $v
'parameters' => $user_pet->pet->dropData->rollParameters(),
'drops_available' => 0,
'next_day' => Carbon::now()
->add($user_pet->pet->dropData->frequency, $user_pet->pet->dropData->interval)
->startOf($user_pet->pet->dropData->interval),
->add($user_pet->pet->dropData->frequency, $user_pet->pet->dropData->interval)
->startOf($user_pet->pet->dropData->interval),
]);
if (!$drop) {
throw new \Exception('Failed to create drop.');
Expand Down

0 comments on commit 007fb9d

Please sign in to comment.