Skip to content

Commit

Permalink
Use full namespace laramore classes, fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
NastuzziSamy committed Dec 7, 2019
1 parent 361499f commit 49765b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 35 deletions.
2 changes: 1 addition & 1 deletion resources/views/migration.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Generated with Laramore on {{ $date }}.
*
* @var Illuminate\Database\Migrations\Migration
* @var Illuminate\Database\Migrations\Migration
@if (isset($model))
* @model {{ $model }}
@endif
Expand Down
51 changes: 18 additions & 33 deletions src/Migrations/BlueprintNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,31 @@
use Illuminate\Database\Schema\{
Blueprint, ColumnDefinition
};
use Laramore\Database\Schema\Builder;
use Metas, Types;
use Laramore\Facades\{
Metas, Types
};

class BlueprintNode extends MetaNode
{
protected $type = 'update';

/**
* Create a node based on a blueprint definition.
*
* @param Blueprint $blueprint
*/
public function __construct(Blueprint $blueprint)
{
$commands = \array_filter($blueprint->getCommands(), function (Fluent $command) {
return $command->name !== 'create';
});
$nodes = \array_merge($blueprint->getColumns(), $commands);

$this->type = (\count($commands) === \count($blueprint->getCommands()) ? 'update' : 'create');
$this->tableNames = [$blueprint->getTable()];

$this->setNodes($nodes);
}
$constraints = \array_map([$this, 'commandToConstraint'], \array_filter($blueprint->getCommands(), function (Fluent $command) {
return $command->name !== 'create';
}));
$commands = \array_map([$this, 'columnToCommand'], $blueprint->getColumns());

/**
* Define the sub nodes/commands.
*
* @param array $nodes
* @return void
*/
protected function setNodes(array $nodes)
{
$this->nodes = \array_map(function ($node) {
if ($node instanceof ColumnDefinition) {
return $this->columnToCommand($node);
} else if ($node instanceof Fluent) {
return $this->commandToConstraint($node);
}
}, $nodes);
$this->setNodes(\array_merge($commands, $constraints));
}

/**
* This method is called when the node is asked to be optimized.
* Only optimize if a meta exists for this table.
Expand Down Expand Up @@ -108,25 +93,25 @@ protected function popFromColumn(Fluent $column, string $name)
/**
* Pop the type definition from a column definition.
*
* @param ColumnDefinition $column
* @param ColumnDefinition|Fluent $column
* @return string
*/
protected function popTypeFromColumn(ColumnDefinition $column): string
protected function popTypeFromColumn(Fluent $column): string
{
$type = $this->popFromColumn($column, 'type');

// Here, if our field is an integer, we need to handle unsigned and increment integers.
if ($type === Types::integer()->getMigrationType()) {
if ($type === Types::get('integer')->getMigrationType()) {
if ($column->unsigned) {
unset($column->unsigned);

$type = Types::unsignedInteger()->getMigrationType();
$type = Types::get('unsigned_integer')->getMigrationType();
}

if ($column->autoIncrement) {
unset($column->autoIncrement);

$type = Types::increment()->getMigrationType();
$type = Types::get('increment')->getMigrationType();
}
}

Expand Down Expand Up @@ -156,10 +141,10 @@ protected function getNeedsForCommand(Fluent $command): array
/**
* Transform a column definition to a migration command.
*
* @param ColumnDefinition $column
* @param ColumnDefinition|Fluent $column
* @return Command
*/
public function columnToCommand(ColumnDefinition $column): Command
public function columnToCommand(Fluent $column): Command
{
$this->cleanUnrelevantAttributes($column);

Expand Down
4 changes: 3 additions & 1 deletion src/Migrations/MetaNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
namespace Laramore\Migrations;

use Laramore\Meta;
use Metas, Migrations;
use Laramore\Facades\{
Metas, Migrations
};

class MetaNode extends AbstractNode
{
Expand Down

0 comments on commit 49765b9

Please sign in to comment.