Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
Do not run autoloader while trying to fetch type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
knesmeyanov committed Aug 17, 2018
1 parent 8723998 commit b79e07e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 55 deletions.
87 changes: 48 additions & 39 deletions src/AbstractDefinition.php
Expand Up @@ -15,6 +15,7 @@
use Railt\Reflection\Common\Serializable;
use Railt\Reflection\Contracts\Definition;
use Railt\Reflection\Contracts\Definition\TypeDefinition;
use Railt\Reflection\Contracts\Dictionary;
use Railt\Reflection\Contracts\Document as DocumentInterface;
use Railt\Reflection\Contracts\Invocation\TypeInvocation;
use Railt\Reflection\Contracts\Type as TypeInterface;
Expand Down Expand Up @@ -121,15 +122,38 @@ public function getDocument(): DocumentInterface
}

/**
* @return int
* @return Dictionary
*/
public function getLine(): int
public function getDictionary(): Dictionary
{
if ($this->line === null) {
$this->line = $this->getFile()->getPosition($this->offset)->getLine();
return $this->document->getDictionary();
}

/**
* @return string
*/
public function __toString(): string
{
return \sprintf('?<%s>', static::getType());
}

/**
* @param string|TypeDefinition $type
* @return string|null
* @throws ExternalFileException
*/
protected function nameOf($type): ?string
{
switch (true) {
case \is_string($type):
return $type;

case $type instanceof TypeDefinition:
return $type->getName();
}

return $this->line;
throw (new ReflectionException('Unsupported argument'))->throwsIn($this->getFile(), $this->getLine(),
$this->getColumn());
}

/**
Expand All @@ -140,6 +164,18 @@ public function getFile(): Readable
return $this->document->getFile();
}

/**
* @return int
*/
public function getLine(): int
{
if ($this->line === null) {
$this->line = $this->getFile()->getPosition($this->offset)->getLine();
}

return $this->line;
}

/**
* @return int
*/
Expand All @@ -153,11 +189,13 @@ public function getColumn(): int
}

/**
* @return string
* @param string|TypeDefinition|null $type
* @return null|TypeDefinition
* @throws ExternalFileException
*/
public function __toString(): string
protected function fetchOrNull($type): ?TypeDefinition
{
return \sprintf('?<%s>', static::getType());
return $type === null ? $this->fetch($type) : null;
}

/**
Expand All @@ -175,37 +213,8 @@ protected function fetch($type): TypeDefinition
return $type;
}

throw (new ReflectionException('Unsupported argument'))
->throwsIn($this->getFile(), $this->getLine(), $this->getColumn());
}

/**
* @param string|TypeDefinition $type
* @return string|null
* @throws ExternalFileException
*/
protected function nameOf($type): ?string
{
switch (true) {
case \is_string($type):
return $type;

case $type instanceof TypeDefinition:
return $type->getName();
}

throw (new ReflectionException('Unsupported argument'))
->throwsIn($this->getFile(), $this->getLine(), $this->getColumn());
}

/**
* @param string|TypeDefinition|null $type
* @return null|TypeDefinition
* @throws ExternalFileException
*/
protected function fetchOrNull($type): ?TypeDefinition
{
return $type === null ? $this->fetch($type) : null;
throw (new ReflectionException('Unsupported argument'))->throwsIn($this->getFile(), $this->getLine(),
$this->getColumn());
}

/**
Expand Down
8 changes: 0 additions & 8 deletions src/AbstractTypeDefinition.php
Expand Up @@ -76,14 +76,6 @@ public function renameTo(string $name): TypeDefinition
return $this;
}

/**
* @return Dictionary
*/
public function getDictionary(): Dictionary
{
return $this->document->getDictionary();
}

/**
* @return string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Jsonable.php
Expand Up @@ -71,7 +71,7 @@ private function jsonNonRenderableFields(): iterable

// File information exclusion
yield 'offset';
yield 'line';
//yield 'line';
yield 'column';

// Reverse superfluous inheritance information
Expand Down
5 changes: 5 additions & 0 deletions src/Contracts/Definition.php
Expand Up @@ -27,6 +27,11 @@ public function getFile(): Readable;
* @return Document
*/
public function getDocument(): Document;

/**
* @return Dictionary
*/
public function getDictionary(): Dictionary;

/**
* @return string
Expand Down
5 changes: 0 additions & 5 deletions src/Contracts/Definition/TypeDefinition.php
Expand Up @@ -33,9 +33,4 @@ public function getName(): string;
* @return string
*/
public function getDescription(): string;

/**
* @return Dictionary
*/
public function getDictionary(): Dictionary;
}
2 changes: 0 additions & 2 deletions src/Dictionary/CallbackDictionary.php
Expand Up @@ -64,8 +64,6 @@ private function invoke(string $name, Definition $from = null): void
*/
public function find(string $name): ?TypeDefinition
{
$this->invoke($name);

return parent::find($name);
}
}

0 comments on commit b79e07e

Please sign in to comment.