Skip to content

Commit 49765b9

Browse files
committed
Use full namespace laramore classes, fix typos
1 parent 361499f commit 49765b9

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed

resources/views/migration.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Generated with Laramore on {{ $date }}.
44
*
5-
* @var Illuminate\Database\Migrations\Migration
5+
* @var Illuminate\Database\Migrations\Migration
66
@if (isset($model))
77
* @model {{ $model }}
88
@endif

src/Migrations/BlueprintNode.php

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,31 @@
1616
use Illuminate\Database\Schema\{
1717
Blueprint, ColumnDefinition
1818
};
19-
use Laramore\Database\Schema\Builder;
20-
use Metas, Types;
19+
use Laramore\Facades\{
20+
Metas, Types
21+
};
2122

2223
class BlueprintNode extends MetaNode
2324
{
25+
protected $type = 'update';
26+
2427
/**
2528
* Create a node based on a blueprint definition.
2629
*
2730
* @param Blueprint $blueprint
2831
*/
2932
public function __construct(Blueprint $blueprint)
3033
{
31-
$commands = \array_filter($blueprint->getCommands(), function (Fluent $command) {
32-
return $command->name !== 'create';
33-
});
34-
$nodes = \array_merge($blueprint->getColumns(), $commands);
35-
36-
$this->type = (\count($commands) === \count($blueprint->getCommands()) ? 'update' : 'create');
3734
$this->tableNames = [$blueprint->getTable()];
3835

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

42-
/**
43-
* Define the sub nodes/commands.
44-
*
45-
* @param array $nodes
46-
* @return void
47-
*/
48-
protected function setNodes(array $nodes)
49-
{
50-
$this->nodes = \array_map(function ($node) {
51-
if ($node instanceof ColumnDefinition) {
52-
return $this->columnToCommand($node);
53-
} else if ($node instanceof Fluent) {
54-
return $this->commandToConstraint($node);
55-
}
56-
}, $nodes);
41+
$this->setNodes(\array_merge($commands, $constraints));
5742
}
58-
43+
5944
/**
6045
* This method is called when the node is asked to be optimized.
6146
* Only optimize if a meta exists for this table.
@@ -108,25 +93,25 @@ protected function popFromColumn(Fluent $column, string $name)
10893
/**
10994
* Pop the type definition from a column definition.
11095
*
111-
* @param ColumnDefinition $column
96+
* @param ColumnDefinition|Fluent $column
11297
* @return string
11398
*/
114-
protected function popTypeFromColumn(ColumnDefinition $column): string
99+
protected function popTypeFromColumn(Fluent $column): string
115100
{
116101
$type = $this->popFromColumn($column, 'type');
117102

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

123-
$type = Types::unsignedInteger()->getMigrationType();
108+
$type = Types::get('unsigned_integer')->getMigrationType();
124109
}
125110

126111
if ($column->autoIncrement) {
127112
unset($column->autoIncrement);
128113

129-
$type = Types::increment()->getMigrationType();
114+
$type = Types::get('increment')->getMigrationType();
130115
}
131116
}
132117

@@ -156,10 +141,10 @@ protected function getNeedsForCommand(Fluent $command): array
156141
/**
157142
* Transform a column definition to a migration command.
158143
*
159-
* @param ColumnDefinition $column
144+
* @param ColumnDefinition|Fluent $column
160145
* @return Command
161146
*/
162-
public function columnToCommand(ColumnDefinition $column): Command
147+
public function columnToCommand(Fluent $column): Command
163148
{
164149
$this->cleanUnrelevantAttributes($column);
165150

src/Migrations/MetaNode.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
namespace Laramore\Migrations;
1212

1313
use Laramore\Meta;
14-
use Metas, Migrations;
14+
use Laramore\Facades\{
15+
Metas, Migrations
16+
};
1517

1618
class MetaNode extends AbstractNode
1719
{

0 commit comments

Comments
 (0)