1
0
Fork 0

use of null coalescing operator

pull/451/head
Nicolas MURE 2017-08-10 22:03:16 +02:00
parent 6a36828069
commit e34d8e15dd
No known key found for this signature in database
GPG Key ID: E5B036F9145C4CAA
1 changed files with 3 additions and 22 deletions

View File

@ -136,7 +136,7 @@ class Index implements ReadableIndex, \Serializable
*/ */
public function getDefinitionsForNamespace(string $namespace): \Generator public function getDefinitionsForNamespace(string $namespace): \Generator
{ {
foreach ($this->doGetDefinitionsForNamespace($namespace) as $fqn => $definition) { foreach ($this->namespaceDefinitions[$namespace] ?? [] as $fqn => $definition) {
yield $fqn => $definition; yield $fqn => $definition;
} }
} }
@ -151,7 +151,7 @@ class Index implements ReadableIndex, \Serializable
public function getDefinition(string $fqn, bool $globalFallback = false) public function getDefinition(string $fqn, bool $globalFallback = false)
{ {
$namespace = $this->extractNamespace($fqn); $namespace = $this->extractNamespace($fqn);
$definitions = $this->doGetDefinitionsForNamespace($namespace); $definitions = $this->namespaceDefinitions[$namespace] ?? [];
if (isset($definitions[$fqn])) { if (isset($definitions[$fqn])) {
return $definitions[$fqn]; return $definitions[$fqn];
@ -213,12 +213,7 @@ class Index implements ReadableIndex, \Serializable
*/ */
public function getReferenceUris(string $fqn): \Generator public function getReferenceUris(string $fqn): \Generator
{ {
$uris = isset($this->references[$fqn]) foreach ($this->references[$fqn] ?? [] as $uri) {
? $this->references[$fqn]
: []
;
foreach ($uris as $uri) {
yield $uri; yield $uri;
} }
} }
@ -331,18 +326,4 @@ class Index implements ReadableIndex, \Serializable
return $fqn; return $fqn;
} }
/**
* Returns the Definitions that are in the given namespace
*
* @param string $namespace
* @return Definition[]
*/
private function doGetDefinitionsForNamespace(string $namespace): array
{
return isset($this->namespaceDefinitions[$namespace])
? $this->namespaceDefinitions[$namespace]
: []
;
}
} }