Skip to content

Commit

Permalink
Fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
ilestis committed Nov 17, 2023
1 parent 6288f65 commit 0d64fc5
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 27 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ public function unmentioned(Campaign $campaign, $id)
]);
}

// @phpstan-ignore-next-line
$entities = \App\Models\Entity::unmentioned()
->inTags($widget->tags->pluck('id')->toArray())
->type($widget->conf('entity'))
->with(['updater'])
->type($widget->conf('entity'))
->paginate(10);

return view('dashboard.widgets._recent_list')
Expand Down
2 changes: 2 additions & 0 deletions app/Services/Campaign/Import/ImportMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function ($matches) {
$newUuid = ImportIdMapper::getGallery($uuid);
$text = Str::replace($uuid, $newUuid, $text);
$text = Str::replace(
// @phpstan-ignore-next-line
'/campaigns/' . $this->data['campaign_id'] . '/',
'/campaigns/' . $this->campaign->id . '/',
$text
Expand All @@ -75,6 +76,7 @@ protected function mapImageMentions(mixed $model): self

foreach ($this->imageMentions as $uuid) {
$men = new ImageMention();
// @phpstan-ignore-next-line
$men->entity_id = $this->entity->id;
$men->image_id = $uuid;
if ($model instanceof Post) {
Expand Down
15 changes: 11 additions & 4 deletions app/Services/Campaign/Import/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use App\Services\Campaign\Import\Mappers\JournalMapper;
use App\Services\Campaign\Import\Mappers\LocationMapper;
use App\Services\Campaign\Import\Mappers\MapMapper;
use App\Services\Campaign\Import\Mappers\MiscMapper;
use App\Services\Campaign\Import\Mappers\NoteMapper;
use App\Services\Campaign\Import\Mappers\OrganisationMapper;
use App\Services\Campaign\Import\Mappers\QuestMapper;
Expand Down Expand Up @@ -226,7 +227,7 @@ protected function gallery(): self
if (!Str::endsWith($file, '.json')) {
continue;
}
$filePath = Str::replace($this->dataPath, null, $file);
$filePath = Str::replace($this->dataPath, '', $file);
$data = $this->open($filePath);
$this->gallery
->path($path)
Expand All @@ -243,14 +244,18 @@ protected function gallery(): self

protected function entities(): self
{
/**
* @var string $model
* @var mixed $mapper
*/
foreach ($this->mappers as $model => $mapper) {
$this->logs[] = 'Processing ' . $model;
$count = 0;
foreach ($this->files($model) as $file) {
if (!Str::endsWith($file, '.json')) {
continue;
}
$filePath = Str::replace($this->dataPath, null, $file);
$filePath = Str::replace($this->dataPath, '', $file);
$data = $this->open($filePath);
$mapper
->path($this->dataPath . '/')
Expand All @@ -275,8 +280,9 @@ protected function entities(): self
if (!Str::endsWith($file, '.json')) {
continue;
}
$filePath = Str::replace($this->dataPath, null, $file);
$filePath = Str::replace($this->dataPath, '', $file);
$data = $this->open($filePath);
// @phpstan-ignore-next-line
$mapper
->path($this->dataPath . '/')
->data($data)
Expand All @@ -298,11 +304,12 @@ protected function entities(): self
if (!Str::endsWith($file, '.json')) {
continue;
}
$filePath = Str::replace($this->dataPath, null, $file);
$filePath = Str::replace($this->dataPath, '', $file);
$data = $this->open($filePath);
if (empty($data['entity']['mentions'])) {
continue;
}
// @phpstan-ignore-next-line
$mapper
->path($this->dataPath . '/')
->data($data)
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Campaign/Import/Mappers/CalendarMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function first(): void

public function second(): void
{
// @phpstan-ignore-next-line
$this->loadModel()
->weather()
->entitySecond()
Expand All @@ -35,7 +36,7 @@ public function tree(): self
// We need the nested trait to trigger for this so it's going to be inefficient
$models = Calendar::whereIn('id', $children)->get();
foreach ($models as $model) {
$model->setParentId($this->mapping[$parent]);
$model->calendar_id = $this->mapping[$parent];
$model->save();
}
}
Expand Down
1 change: 1 addition & 0 deletions app/Services/Campaign/Import/Mappers/CharacterMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function first(): void

public function second(): void
{
// @phpstan-ignore-next-line
$this
->loadModel()
->foreign('locations', 'location_id')
Expand Down
9 changes: 6 additions & 3 deletions app/Services/Campaign/Import/Mappers/EntityMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Models\EntityMention;
use App\Models\EntityTag;
use App\Models\Inventory;
use App\Models\Location;
use App\Models\Post;
use App\Models\Relation;
use App\Services\EntityMappingService;
Expand All @@ -37,6 +38,7 @@ protected function prepareModel(): self
$this->model = app()->make($this->className);
$this->model->campaign_id = $this->campaign->id;
foreach ($this->data as $field => $value) {
// @phpstan-ignore-next-line
if (is_array($value) || in_array($field, $this->ignore)) {
continue;
}
Expand Down Expand Up @@ -140,7 +142,7 @@ protected function image(): self
$destination = 'w/' . $this->campaign->id . '/' . $imageName;

if (!Storage::disk('local')->exists($this->path . $img)) {
dd('image ' . $this->path . $img . ' doesnt exist');
//dd('image ' . $this->path . $img . ' doesnt exist');
return $this;
}

Expand All @@ -162,7 +164,7 @@ protected function header(): self
$destination = 'w/' . $this->campaign->id . '/' . $imageName;

if (!Storage::disk('local')->exists($this->path . $img)) {
dd('header image ' . $this->path . $img . ' doesnt exist');
//dd('header image ' . $this->path . $img . ' doesnt exist');
return $this;
}

Expand Down Expand Up @@ -253,7 +255,7 @@ protected function assets(): self
$destination = 'w/' . $this->campaign->id . '/entity-assets/' . uniqid() . '.' . $ext;

if (!Storage::disk('local')->exists($this->path . $img)) {
dd('image ' . $this->path . $img . ' doesnt exist');
//dd('image ' . $this->path . $img . ' doesnt exist');
continue;
}
Storage::writeStream($destination, Storage::disk('local')->readStream($this->path . $img));
Expand Down Expand Up @@ -501,6 +503,7 @@ public function fixTree(): self
if (!method_exists($base, 'recalculateTreeBounds')) {
return $this;
}
// @phpstan-ignore-next-line
$base->fixCampaignTree($this->campaign->id);
return $this;
}
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Campaign/Import/Mappers/GalleryMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Image;
use App\Traits\CampaignAware;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -92,7 +93,7 @@ protected function importImage(): void
$destination = 'campaigns/' . $this->campaign->id . '/' . $this->image->id . '.' . $this->data['ext'];

if (!Storage::disk('local')->exists($imagePath)) {
dd('image ' . $imagePath . ' doesnt exist');
Log::info('image ' . $imagePath . ' doesnt exist');
return;
}

Expand Down
16 changes: 3 additions & 13 deletions app/Services/Campaign/Import/Mappers/MapMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\MapLayer;
use App\Models\MapMarker;
use App\Models\Map;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

Expand All @@ -29,6 +30,7 @@ public function first(): void

public function second(): void
{
// @phpstan-ignore-next-line
$this->loadModel()
->groups()
->layers()
Expand Down Expand Up @@ -64,12 +66,6 @@ protected function groups(): self
foreach ($this->data['groups'] as $data) {
$el = new MapGroup();
$el->map_id = $this->model->id;
if (!empty($data['entity_id'])) {
if (!ImportIdMapper::hasEntity($data['entity_id'])) {
continue;
}
$el->entity_id = ImportIdMapper::getEntity($data['entity_id']);
}
foreach ($fields as $field) {
$el->$field = $data[$field];
}
Expand All @@ -89,12 +85,6 @@ protected function layers(): self
foreach ($this->data['layers'] as $data) {
$el = new MapLayer();
$el->map_id = $this->model->id;
if (!empty($data['entity_id'])) {
if (!ImportIdMapper::hasEntity($data['entity_id'])) {
continue;
}
$el->entity_id = ImportIdMapper::getEntity($data['entity_id']);
}
foreach ($fields as $field) {
$el->$field = $data[$field];
}
Expand All @@ -106,7 +96,7 @@ protected function layers(): self
$destination = 'w/' . $this->campaign->id . '/maps/' . $el->map_id . '/' . $imageName;

if (!Storage::disk('local')->exists($this->path . $el->image)) {
dd('map layer image ' . $this->path . $el->image . ' doesnt exist');
Log::error('map layer image ' . $this->path . $el->image . ' doesnt exist');
return $this;
}

Expand Down
1 change: 1 addition & 0 deletions app/Services/Campaign/Import/Mappers/QuestMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function first(): void

public function second(): void
{
// @phpstan-ignore-next-line
$this->loadModel()
->foreign('locations', 'location_id')
->saveModel()
Expand Down
1 change: 1 addition & 0 deletions app/Services/Campaign/Import/Mappers/TimelineMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function first(): void

public function second(): void
{
// @phpstan-ignore-next-line
$this->loadModel()
->eras()
->elements()
Expand Down
1 change: 1 addition & 0 deletions app/Services/MentionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ protected function extractAndReplace()
$replace = '<a href="' . $url . '"'
. ' class="' . implode(' ', $cssClasses) . '"'
. ' data-entity-tags="' . implode(' ', $tagClasses) . '"'
// @phpstan-ignore-next-line
. ' data-entity-type="' . $entity->type() . '"'
. ' data-toggle="tooltip-ajax"'
. ' data-id="' . $entity->id . '"'
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Users/PurgeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function empty(): int
DeleteUser::dispatch($user);
}
}
}, 'users.id', 'id');
});
return $this->count;
}

Expand Down
6 changes: 3 additions & 3 deletions app/Traits/ExportableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected function baseExportData(): self
continue;
}
foreach ($baseFields as $baseField) {
// @phpstan-ignore-next-line
$this->exportData[$baseField] = $this->$baseField;
}
}
Expand All @@ -55,7 +56,7 @@ protected function baseExportData(): self

protected function entityExportData(): self
{
if ($this->entity) {
if (isset($this->entity) && $this->entity) {
$this->exportData['entity'] = $this->entity->export();
}
return $this;
Expand All @@ -80,8 +81,7 @@ protected function foreignExportData(): self
$this->exportData[$foreign][] = $model->toArray();
}
} catch (Exception $e) {
dd('e');
throw new Exception("Unknown relation '{$foreign}' on model " . get_class($this));
throw new Exception("Unknown relation '{$foreign}' on model " . get_class($this) . '(' . $e->getMessage() . ')');
}
}
}
Expand Down

0 comments on commit 0d64fc5

Please sign in to comment.