Skip to content

Commit

Permalink
Codesniffer: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jan 4, 2022
1 parent af692b1 commit 92bfb9c
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/Analyser/Database/DatabaseAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ protected function analyseColumns(Table $table): void
$column->setNullable($col['nullable']);
$column->setType(Helpers::columnType($col['nativetype']));
$column->setDefault($col['default']);
$column->setOnUpdate(Strings::contains(isset($col['vendor']['extra']) ? $col['vendor']['extra'] : $col['vendor']['Extra'], 'on update'));
$column->setOnUpdate(Strings::contains($col['vendor']['extra'] ?? $col['vendor']['Extra'], 'on update'));

// Analyse ENUM
if ($col['nativetype'] === ColumnTypes::NATIVE_TYPE_ENUM) {
$enum = Strings::matchAll(isset($col['vendor']['type']) ? $col['vendor']['type'] : $col['vendor']['Type'], ColumnTypes::NATIVE_REGEX_ENUM, PREG_PATTERN_ORDER);
$enum = Strings::matchAll($col['vendor']['type'] ?? $col['vendor']['Type'], ColumnTypes::NATIVE_REGEX_ENUM, PREG_PATTERN_ORDER);
if ($enum) {
$column->setEnum($enum[1]);
$column->setType(ColumnTypes::TYPE_ENUM);
Expand All @@ -95,15 +95,13 @@ protected function analyseIndexes(Table $table): void
$keys = $this->driver->getForeignKeys($tableName);

foreach ($indexes as $index) {

foreach ($index['columns'] as $col) {
$column = $table->getColumn($col);

$column->setPrimary($index['primary']);
$column->setUnique($index['unique']);
$column->setIndex(true);
}

}

foreach ($keys as $key) {
Expand Down
1 change: 1 addition & 0 deletions src/Entity/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function getPrimaryKeyColumns(): array
$primary[] = $column;
}
}

return $primary;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,19 @@ public function generate(): void
if ($this->config->get('generator.generate.entities')) {
$this->entityGenerator->generate($database);
}

if ($this->config->get('generator.generate.repositories')) {
$this->repositoryGenerator->generate($database);
}

if ($this->config->get('generator.generate.mappers')) {
$this->mapperGenerator->generate($database);
}

if ($this->config->get('generator.generate.facades')) {
$this->facadeGenerator->generate($database);
}

if ($this->config->get('generator.generate.model')) {
$this->modelGenerator->generate($database);
}
Expand Down
1 change: 1 addition & 0 deletions src/Generator/Entity/Decorator/ColumnConstantGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function doDecorate(Column $column, ClassType $class, PhpNamespace $names
if (!$this->config->get('entity.generate.column.constant')) {
return;
}

$name = Strings::upper($this->config->get('entity.column.constants.prefix') . $column->getName());
$class->addConstant($name, Helpers::camelCase($column->getName()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Entity/Decorator/ColumnDocumentor.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function doDecorate(Column $column, ClassType $class, PhpNamespace $names
}

// Enum
if (!empty($enum = $column->getEnum())) {
if (!empty($column->getEnum())) {
$doc->setEnum(Strings::upper($column->getName()));
}

Expand Down
1 change: 0 additions & 1 deletion src/Generator/Entity/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function generate(Database $database): void

// Add table columns
foreach ($table->getColumns() as $column) {

if ($this->config->get('generator.entity.exclude.primary')) {
if ($column->isPrimary()) continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/Generator/Model/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function generate(Database $database): void
$doc->setVariable(lcfirst($this->entityResolver->resolveEntityName($table)));
$class->addComment((string) $doc);
}

$this->generateFile($this->modelResolver->resolveModelFilename(), (string) $namespace);
}

Expand Down
1 change: 1 addition & 0 deletions src/Generator/Repository/RepositoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function generate(Database $database): void
$namespace->addUse($extends);
$class->setExtends($extends);
}

$namespace->addUse($this->entityResolver->resolveEntityNamespace($table) . '\\' . $this->entityResolver->resolveEntityName($table));
$entityName = $this->entityResolver->resolveEntityName($table);
$class->addMethod('getEntityClassNames')
Expand Down
1 change: 1 addition & 0 deletions src/Resolver/Impl/SimpleResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected function table(Table $table, bool $singularize = false): string
if ($singularize) {
$name = Inflector::singularize($name);
}

return $name;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Resolver/Impl/SimpleSeparateResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ protected function resolveFilenameFor(string $type, Table $table): string
if ($this->config->get($type . '.name.singularize')) {
$name = Inflector::singularize($name);
}

$name .= $this->config->get($type . '.filename.suffix');
return $this->config->get($type . '.folder') . DIRECTORY_SEPARATOR . $name . '.' . IFilenameResolver::PHP_EXT;
}
Expand All @@ -88,8 +89,8 @@ protected function resolveNameFor(string $type, Table $table): string
if ($this->config->get($type . '.name.singularize')) {
$name = Inflector::singularize($name);
}
$name .= $this->config->get($type . '.name.suffix');
return $name;

return $name . $this->config->get($type . '.name.suffix');
}

}
2 changes: 2 additions & 0 deletions src/Resolver/Impl/SimpleTogetherResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected function resolveName(string $type, Table $table): string
if ($this->config->get($type . '.name.singularize')) {
$name = Inflector::singularize($name);
}

$name .= $this->config->get($type . '.name.suffix');
return $this->normalize($name);
}
Expand All @@ -80,6 +81,7 @@ protected function resolveFilenameFor(string $type, Table $table): string
if ($this->config->get($type . '.name.singularize')) {
$name = Inflector::singularize($name);
}

$filename = $this->normalize($name . $this->config->get($type . '.filename.suffix')) . '.' . IFilenameResolver::PHP_EXT;
return $folder . Helpers::DS . $filename;
}
Expand Down
1 change: 1 addition & 0 deletions src/Utils/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static function columnType(string $type): string
}
}
}

return $cache[$type];
}

Expand Down

0 comments on commit 92bfb9c

Please sign in to comment.