Skip to content

Commit

Permalink
Apply fixes from StyleCI (#4)
Browse files Browse the repository at this point in the history
This pull request applies code style fixes from an analysis carried out
by [StyleCI](https://github.styleci.io).

---

For more information, click
[here](https://github.styleci.io/analyses/Zn1k5R).
  • Loading branch information
Crypta-Eve authored Apr 3, 2024
2 parents 3af8481 + 64b9074 commit ab18922
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 134 deletions.
225 changes: 111 additions & 114 deletions src/Commands/UpgradeFits.php
Original file line number Diff line number Diff line change
@@ -1,114 +1,111 @@
<?php


namespace CryptaTech\Seat\Fitting\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use CryptaTech\Seat\Fitting\Models\Fitting;
use CryptaTech\Seat\Fitting\Models\Doctrine;
use CryptaTech\Seat\Fitting\Models\OldFitting;
use CryptaTech\Seat\Fitting\Models\OldDoctrine;
use Exception;

/**
* Class UpgradeFits.
*
* @package CryptaTech\Seat\Fitting\Commands
*/
class UpgradeFits extends Command
{

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'cryptatech:fittings:upgrade';

/**
* The console command description.
*
* @var string
*/
protected $description = 'upgrade previous seat-fitting fittings to the new modelling';

/**
* Execute the console command.
*/
public function handle()
{

$this->info("Finding fits to upgrade!");

$oldFits = OldFitting::all();
$c = count($oldFits);

$this->info("Found " . $c . " fits to process");

$bar = $this->getProgressBar($c);
$failedUpgrades = 0;

$mapping = [];

foreach ($oldFits as $oldFit) {
try { // If a fit fails then we just add it to a list of errors.
$f = Fitting::createFromEve($oldFit->eftfitting);
$mapping[$oldFit->id] = $f->fitting_id;
} catch (Exception $e) {
Log::error(['fit' => $oldFit->eftfitting, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString()]);
$failedUpgrades += 1;
}
$bar->advance();
}

$bar->finish();
$this->line('');

$this->info('Fitting Migration Complete!');
$this->info('Success: ' . $c - $failedUpgrades);
$this->warn('Failure : ' . $failedUpgrades);

$this->line('');


$this->info("Updating Doctrine Fitting Mapping!");
$oldDocs = OldDoctrine::all();
$bar = $this->getProgressBar(count($oldDocs));

foreach( $oldDocs as $oldDoc){
$newDoc = Doctrine::create([
'name' => $oldDoc->name,
]);
foreach ($oldDoc->fittings()->get() as $oldFit) {
$newDoc->fittings()->attach($mapping[$oldFit->id]);
}
$bar->advance();

}

$bar->finish();
$this->line('');

$this->info('Doctrine Migration Complete!');

}


/**
* Get a new progress bar to display based on the
* amount of iterations we expect to use.
*
* @param $iterations
* @return \Symfony\Component\Console\Helper\ProgressBar
*/
public function getProgressBar($iterations)
{

$bar = $this->output->createProgressBar($iterations);

$bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s% %memory:6s%');

return $bar;
}
}
<?php

namespace CryptaTech\Seat\Fitting\Commands;

use CryptaTech\Seat\Fitting\Models\Doctrine;
use CryptaTech\Seat\Fitting\Models\Fitting;
use CryptaTech\Seat\Fitting\Models\OldDoctrine;
use CryptaTech\Seat\Fitting\Models\OldFitting;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

/**
* Class UpgradeFits.
*
* @package CryptaTech\Seat\Fitting\Commands
*/
class UpgradeFits extends Command
{

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'cryptatech:fittings:upgrade';

/**
* The console command description.
*
* @var string
*/
protected $description = 'upgrade previous seat-fitting fittings to the new modelling';

/**
* Execute the console command.
*/
public function handle()
{

$this->info('Finding fits to upgrade!');

$oldFits = OldFitting::all();
$c = count($oldFits);

$this->info('Found ' . $c . ' fits to process');

$bar = $this->getProgressBar($c);
$failedUpgrades = 0;

$mapping = [];

foreach ($oldFits as $oldFit) {
try { // If a fit fails then we just add it to a list of errors.
$f = Fitting::createFromEve($oldFit->eftfitting);
$mapping[$oldFit->id] = $f->fitting_id;
} catch (Exception $e) {
Log::error(['fit' => $oldFit->eftfitting, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString()]);
$failedUpgrades += 1;
}
$bar->advance();
}

$bar->finish();
$this->line('');

$this->info('Fitting Migration Complete!');
$this->info('Success: ' . $c - $failedUpgrades);
$this->warn('Failure : ' . $failedUpgrades);

$this->line('');

$this->info('Updating Doctrine Fitting Mapping!');
$oldDocs = OldDoctrine::all();
$bar = $this->getProgressBar(count($oldDocs));

foreach($oldDocs as $oldDoc){
$newDoc = Doctrine::create([
'name' => $oldDoc->name,
]);
foreach ($oldDoc->fittings()->get() as $oldFit) {
$newDoc->fittings()->attach($mapping[$oldFit->id]);
}
$bar->advance();

}

$bar->finish();
$this->line('');

$this->info('Doctrine Migration Complete!');

}

/**
* Get a new progress bar to display based on the
* amount of iterations we expect to use.
*
* @param $iterations
* @return \Symfony\Component\Console\Helper\ProgressBar
*/
public function getProgressBar($iterations)
{

$bar = $this->output->createProgressBar($iterations);

$bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s% %memory:6s%');

return $bar;
}
}
6 changes: 3 additions & 3 deletions src/FittingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace CryptaTech\Seat\Fitting;

use Seat\Services\AbstractSeatPlugin;
use CryptaTech\Seat\Fitting\Commands\UpgradeFits;
use Seat\Services\AbstractSeatPlugin;

class FittingServiceProvider extends AbstractSeatPlugin
{
Expand All @@ -21,7 +21,7 @@ public function boot()

$this->publishes(
[
__DIR__ . '/Config/fitting.exportlinks.php' => config_path('fitting.exportlinks.php')
__DIR__ . '/Config/fitting.exportlinks.php' => config_path('fitting.exportlinks.php'),
],
['config', 'seat']
);
Expand All @@ -36,7 +36,7 @@ public function boot()
*/
public function add_routes()
{
if (!$this->app->routesAreCached()) {
if (! $this->app->routesAreCached()) {
include __DIR__ . '/Http/routes.php';
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/Helpers/CalculateEft.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace CryptaTech\Seat\Fitting\Helpers;

use CryptaTech\Seat\Fitting\Models\FittingItem;
use Seat\Eveapi\Models\Sde\DgmTypeAttribute;
use Seat\Eveapi\Models\Sde\InvType;

use CryptaTech\Seat\Fitting\Models\FittingItem;

// There are some large performance gains to be had in this file... Simply through letting the DB do all the work for us.
// However until such a time that pepole complain about speed, or I get bored, I will not be updating this.
// The one exception is probably the Doctrine Report is too slow... Anyways..
// The one exception is probably the Doctrine Report is too slow... Anyways..

// Also need to replace the dogma section.

Expand All @@ -24,7 +23,7 @@ trait CalculateEft
public function calculate($fitting)
{
$items = collect($fitting->fitItems->all());
$types = $items->map(function (FittingItem $v, $k){
$types = $items->map(function (FittingItem $v, $k) {
return $v->type_id;
})->unique();
$this->getReqSkillsByTypeIDs($types);
Expand All @@ -36,7 +35,7 @@ public function calculate($fitting)
public function calculateIndividual(int $typeID)
{
$this->getReqSkillsByTypeIDs([$typeID]);

return $this->getSkillNames($this->requiredSkills);
}

Expand Down Expand Up @@ -124,7 +123,7 @@ private function getReqSkillsByTypeIDs($typeIDs)
$attributeids = array_merge(array_keys(self::REQ_SKILLS_ATTR_LEVELS), array_values(self::REQ_SKILLS_ATTR_LEVELS));

foreach ($typeIDs as $type) {
if (gettype($type) == "array")
if (gettype($type) == 'array')
$type = $type['typeID'];
$res = DgmTypeAttribute::where('typeid', $type)->wherein('attributeID', $attributeids)->get();

Expand Down
1 change: 0 additions & 1 deletion src/Models/OldDoctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ public function fittings()
{
return $this->belongsToMany(OldFitting::class, 'seat_doctrine_fitting', 'doctrine_id', 'fitting_id');
}

}
3 changes: 1 addition & 2 deletions src/Models/Sde/DgmTypeEffect.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php


namespace CryptaTech\Seat\Fitting\Models\Sde;

use Illuminate\Database\Eloquent\Model;
use Seat\Eveapi\Traits\HasCompositePrimaryKey;
use Seat\Eveapi\Traits\IsReadOnly;

/**
* Class DgmEffect
* Class DgmEffect.
*
* @package CryptaTech\Seat\Fitting\Models\Sde
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Models/Sde/InvFlag.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace CryptaTech\Seat\Fitting\Models\Sde;

use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -35,4 +34,4 @@ class InvFlag extends Model
*/
public $timestamps = false;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*
Expand Down Expand Up @@ -56,4 +55,4 @@ public function down()
{
Schema::dropIfExists('crypta_tech_seat_fittings');
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*
Expand Down Expand Up @@ -63,4 +62,4 @@ public function down()
{
Schema::dropIfExists('crypta_tech_seat_fitting_items');
}
};
};

0 comments on commit ab18922

Please sign in to comment.