Skip to content

Commit 9f43685

Browse files
committed
Code: fixes
1 parent 95c5b80 commit 9f43685

11 files changed

Lines changed: 38 additions & 28 deletions

File tree

src/Analyser/Database/DatabaseAnalyser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DatabaseAnalyser implements IAnalyser
2020

2121
private Driver $driver;
2222

23-
public function __construct(string $dns, string $username, ?string $password = null)
23+
public function __construct(string $dns, ?string $username = null, ?string $password = null)
2424
{
2525
$this->connection = new Connection($dns, $username, $password);
2626
$this->driver = $this->connection->getDriver();
@@ -67,7 +67,7 @@ protected function analyseColumns(Table $table): void
6767
$column->setNullable($col['nullable']);
6868
$column->setType(Helpers::columnType($col['nativetype']));
6969
$column->setDefault($col['default']);
70-
$column->setOnUpdate(str_contains($col['vendor']['extra'] ?? $col['vendor']['Extra'], 'on update'));
70+
$column->setOnUpdate(str_contains($col['vendor']['extra'] ?? $col['vendor']['Extra'] ?? '', 'on update'));
7171

7272
// Analyse ENUM
7373
if ($col['nativetype'] === ColumnTypes::NATIVE_TYPE_ENUM) {

src/Config/Config.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ public function getString(string $name): string
110110
return $ret;
111111
}
112112

113+
public function getStringNull(string $name): ?string
114+
{
115+
$ret = $this->offsetGet($name);
116+
assert(is_string($ret) || $ret === null);
117+
118+
return $ret;
119+
}
120+
113121
public function getBool(string $name): bool
114122
{
115123
$ret = $this->offsetGet($name);

src/Entity/Column.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class Column
2929

3030
private ?bool $primary = null;
3131

32-
private bool $unique;
32+
private bool $unique = false;
3333

34-
private bool $index;
34+
private bool $index = false;
3535

36-
private ForeignKey $foreignKey;
36+
private ?ForeignKey $foreignKey = null;
3737

3838
public function attach(Table $table): void
3939
{
@@ -110,7 +110,7 @@ public function getDefault(): ?string
110110
return $this->default;
111111
}
112112

113-
public function setDefault(string $default): void
113+
public function setDefault(?string $default): void
114114
{
115115
$this->default = $default;
116116
}

src/Entity/PhpDoc.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
class PhpDoc
88
{
99

10-
private string $annotation;
10+
private ?string $annotation = null;
1111

12-
private string $type;
12+
private ?string $type = null;
1313

14-
private string $variable;
14+
private ?string $variable = null;
1515

16-
private string $enum;
16+
private ?string $enum = null;
1717

18-
private ?string $default;
18+
private ?string $default = null;
1919

20-
private bool $virtual;
20+
private bool $virtual = false;
2121

22-
private bool $primary;
22+
private bool $primary = false;
2323

2424
private ?PhpRelDoc $relation = null;
2525

26-
public function getAnnotation(): string
26+
public function getAnnotation(): ?string
2727
{
2828
return $this->annotation;
2929
}
@@ -33,7 +33,7 @@ public function setAnnotation(string $annotation): void
3333
$this->annotation = $annotation;
3434
}
3535

36-
public function getType(): string
36+
public function getType(): ?string
3737
{
3838
return $this->type;
3939
}
@@ -43,7 +43,7 @@ public function setType(string $type): void
4343
$this->type = $type;
4444
}
4545

46-
public function getVariable(): string
46+
public function getVariable(): ?string
4747
{
4848
return $this->variable;
4949
}
@@ -53,7 +53,7 @@ public function setVariable(string $variable): void
5353
$this->variable = $variable;
5454
}
5555

56-
public function getEnum(): string
56+
public function getEnum(): ?string
5757
{
5858
return $this->enum;
5959
}
@@ -108,7 +108,7 @@ public function __toString(): string
108108
$b = new DocBuilder();
109109

110110
// Anotation (@..)
111-
if ($this->annotation !== '') {
111+
if ($this->annotation !== null && $this->annotation !== '') {
112112
$b->append($this->annotation);
113113
} else {
114114
if ($this->virtual) {
@@ -119,7 +119,9 @@ public function __toString(): string
119119
}
120120

121121
// Type (int, string..)
122-
$b->append($this->type);
122+
if ($this->type !== null) {
123+
$b->append($this->type);
124+
}
123125

124126
// Variable ($..)
125127
$b->append(sprintf('$%s', $this->variable));

src/Generator/Entity/Decorator/ColumnConstantGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(Config $config)
2121

2222
public function doDecorate(Column $column, ClassType $class, PhpNamespace $namespace): void
2323
{
24-
if ($this->config->getString('entity.generate.column.constant') === '') {
24+
if (!$this->config->getBool('entity.generate.column.constant')) {
2525
return;
2626
}
2727

src/Generator/Entity/EntityGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function generate(Database $database): void
7878
$class->setExtends($extends);
7979

8080
// Save file
81-
$this->generateFile($this->resolver->resolveFilename(Helpers::extractShortName($this->config->getString('entity.extends')), $this->config->getString('entity.folder')), (string) $namespace);
81+
$this->generateFile($this->resolver->resolveFilename(Helpers::extractShortName($this->config->getString('entity.extends')), $this->config->getStringNull('entity.folder')), (string) $namespace);
8282
}
8383
}
8484

src/Generator/Facade/FacadeGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function generate(Database $database): void
4646
$class->setAbstract(true);
4747

4848
// Save file
49-
$this->generateFile($this->resolver->resolveFilename(Helpers::extractShortName($this->config->getString('facade.extends')), $this->config->getString('facade.folder')), (string) $namespace);
49+
$this->generateFile($this->resolver->resolveFilename(Helpers::extractShortName($this->config->getString('facade.extends')), $this->config->getStringNull('facade.folder')), (string) $namespace);
5050
}
5151
}
5252

src/Generator/Mapper/MapperGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function generate(Database $database): void
5656
$class->setExtends($extends);
5757

5858
// Save file
59-
$this->generateFile($this->resolver->resolveFilename(Helpers::extractShortName($this->config->getString('mapper.extends')), $this->config->getString('mapper.folder')), (string) $namespace);
59+
$this->generateFile($this->resolver->resolveFilename(Helpers::extractShortName($this->config->getString('mapper.extends')), $this->config->getStringNull('mapper.folder')), (string) $namespace);
6060
}
6161
}
6262

src/Generator/Repository/RepositoryGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function generate(Database $database): void
6363
$class->setExtends($extends);
6464

6565
// Save file
66-
$this->generateFile($this->resolver->resolveFilename(Helpers::extractShortName($this->config->getString('repository.extends')), $this->config->getString('repository.folder')), (string) $namespace);
66+
$this->generateFile($this->resolver->resolveFilename(Helpers::extractShortName($this->config->getString('repository.extends')), $this->config->getStringNull('repository.folder')), (string) $namespace);
6767
}
6868
}
6969

src/Resolver/Impl/SimpleSeparateResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function resolveFilenameFor(string $type, Table $table): string
7979
$name = InflectorFactory::create()->build()->singularize($name);
8080
}
8181

82-
$name .= $this->config->getString($type . '.filename.suffix');
82+
$name .= $this->config->get($type . '.filename.suffix');
8383

8484
return $this->config->getString($type . '.folder') . DIRECTORY_SEPARATOR . $name . '.' . IFilenameResolver::PHP_EXT;
8585
}
@@ -91,7 +91,7 @@ protected function resolveNameFor(string $type, Table $table): string
9191
$name = InflectorFactory::create()->build()->singularize($name);
9292
}
9393

94-
return $name . $this->config->getString($type . '.name.suffix');
94+
return $name . $this->config->get($type . '.name.suffix');
9595
}
9696

9797
}

0 commit comments

Comments
 (0)