Skip to content

Commit 0ef84da

Browse files
ISSUE-1467: Fixed empty namespace generating
1 parent 5a33136 commit 0ef84da

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Added trailing semicolon to scaffolding crud views getters [#1477](https://github.com/phalcon/phalcon-devtools/issues/1477)
55
- Fixed optional options (namespace, abstract) checks on model create [#1491](https://github.com/phalcon/phalcon-devtools/issues/1491)
66
- Fixed wrong request filtering [#1468](https://github.com/phalcon/phalcon-devtools/issues/1468)
7+
- Fixed empty namespace generation [#1467](https://github.com/phalcon/phalcon-devtools/issues/1467)
78

89
# [4.0.5](https://github.com/phalcon/cphalcon/releases/tag/v4.0.5) (2021-03-14)
910
## Fixed

src/Builder/Component/Controller.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ public function build()
103103
*/
104104
protected function constructNamespace(): string
105105
{
106-
$namespace = $this->options->get('namespace');
106+
$namespace = $this->options->has('namespace')
107+
? (string) $this->options->get('namespace') : null;
108+
107109
if ($namespace === null) {
108110
return '';
109111
}
110112

111-
if ($this->checkNamespace((string)$namespace)) {
113+
if ($this->checkNamespace($namespace) && !empty(trim($namespace))) {
112114
return 'namespace ' . $this->options->get('namespace') . ';' . PHP_EOL . PHP_EOL;
113115
}
114116

src/Builder/Component/Model.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ public function build(): void
111111
require_once $config->devtools->loader;
112112
}
113113

114-
$namespace = '';
115-
if ($this->modelOptions->hasOption('namespace') &&
116-
$this->checkNamespace((string)$this->modelOptions->getOption('namespace'))) {
114+
$namespace = $this->modelOptions->hasOption('namespace')
115+
? (string) $this->modelOptions->getOption('namespace') : '';
116+
117+
if ($this->checkNamespace($namespace) && !empty(trim($namespace))) {
117118
$namespace = 'namespace ' . $this->modelOptions->getOption('namespace') . ';' . PHP_EOL . PHP_EOL;
118119
}
119120

src/Builder/Component/Scaffold.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,13 @@ private function makeController(): void
459459
$code = file_get_contents($this->options->get('templatePath') . '/scaffold/no-forms/Controller.php');
460460
$usesNamespaces = false;
461461

462-
$controllerNamespace = (string)$this->options->get('controllersNamespace');
463-
if ($this->options->has('controllersNamespace') &&
464-
$controllerNamespace &&
465-
$this->checkNamespace($controllerNamespace)
466-
) {
462+
$controllerNamespace = $this->options->has('controllersNamespace')
463+
? (string) $this->options->get('controllersNamespace') : '';
464+
465+
if (!empty(trim($controllerNamespace)) && $this->checkNamespace($controllerNamespace)) {
467466
$code = str_replace(
468467
'$namespace$',
469-
'namespace ' . $this->options->get('controllersNamespace').';' . PHP_EOL,
468+
'namespace ' . $controllerNamespace.';' . PHP_EOL,
470469
$code
471470
);
472471
$usesNamespaces = true;

0 commit comments

Comments
 (0)