Skip to content

Commit 4ec9724

Browse files
Merge pull request PHP-Hearth#24 from PHP-Hearth/feature/release-cleanup
The primary purpose of this pull request appears to be to address (2) bugs, not superficial cleanup prior to release. Merging and closing related issues, just noting.
2 parents b2233ab + 51ca9d7 commit 4ec9724

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Hearth/Target/Resolver.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,15 @@ public function lookup(array $targetArgs)
139139

140140
$lastChildYaml = $this->loadConfigFile($lastChildYmlPath);
141141

142-
$namespace = $lastChildYaml['namespace'];
142+
$namespace = isset($lastChildYaml['namespace']) ? $lastChildYaml['namespace'] : null;
143+
$qualifiedNamespace = !empty($namespace) && $namespace[0] !== '\\' ? '\\' . $namespace : $namespace;
143144

144145
$this->setTargetName($targetName);
145146
$this->setTargetsPath(
146147
realpath(dirname($lastChildYmlPath)) . DIRECTORY_SEPARATOR
147148
. $lastChildYaml['targets']
148149
);
149-
$this->setTargetsNamespace($namespace);
150+
$this->setTargetsNamespace($qualifiedNamespace);
150151
$this->setLastChildTargetsPath(
151152
DIRECTORY_SEPARATOR . $lastChildYaml['targets']
152153
);
@@ -231,7 +232,7 @@ protected function indexConfig($config)
231232
$targets['targets'] = '';
232233
}
233234

234-
if (!is_array($config['children'])) {
235+
if (!isset($config['children']) || !is_array($config['children'])) {
235236
return $targets;
236237
}
237238

@@ -375,7 +376,7 @@ public function getTargetsNamespace()
375376
*/
376377
public function setTargetsNamespace($namespace)
377378
{
378-
if (!is_string($namespace)) {
379+
if (!is_string($namespace) && $namespace !== null) {
379380
throw new \InvalidArgumentException(
380381
'Unexpected ' . gettype($namespace) . '. Expected a string'
381382
);
@@ -448,7 +449,7 @@ public function getLastChildTargetsPath()
448449
*/
449450
public function getTargetClassName()
450451
{
451-
$className = '\\' . $this->getTargetsNamespace();
452+
$className = $this->getTargetsNamespace();
452453
$className .= preg_replace('#/#', '\\', trim($this->getLastChildTargetsPath(), '.'));
453454
$className .= '\\' . $this->getTargetName();
454455

0 commit comments

Comments
 (0)