Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Extra visual debt #123

Open
wants to merge 1 commit into
base: dev-4.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/Annotation/AnnotationCollection.php
Original file line number Diff line number Diff line change
@@ -17,14 +17,11 @@ class AnnotationCollection extends ArrayObject
{
/**
* Checks if the collection has annotations for a class
*
* @param string $class
* @return bool
*/
public function hasAnnotation($class)
public function hasAnnotation(string $class) : bool
{
foreach ($this as $annotation) {
if (get_class($annotation) == $class) {
if (get_class($annotation) === $class) {
return true;
}
}
20 changes: 5 additions & 15 deletions src/Annotation/AnnotationManager.php
Original file line number Diff line number Diff line change
@@ -37,12 +37,9 @@ class AnnotationManager implements EventManagerAwareInterface
protected $events;

/**
* Set the event manager instance
*
* @param EventManagerInterface $events
* @return AnnotationManager
* {@inheritDoc}
*/
public function setEventManager(EventManagerInterface $events)
public function setEventManager(EventManagerInterface $events) : self
{
$events->setIdentifiers([
__CLASS__,
@@ -54,13 +51,9 @@ public function setEventManager(EventManagerInterface $events)
}

/**
* Retrieve event manager
*
* Lazy loads an instance if none registered.
*
* @return EventManagerInterface
* {@inheritDoc}
*/
public function getEventManager()
public function getEventManager() : EventManagerInterface
{
if (null === $this->events) {
$this->setEventManager(new EventManager());
@@ -71,11 +64,8 @@ public function getEventManager()

/**
* Attach a parser to listen to the createAnnotation event
*
* @param ParserInterface $parser
* @return AnnotationManager
*/
public function attach(ParserInterface $parser)
public function attach(ParserInterface $parser) : self
{
$this->getEventManager()
->attach(self::EVENT_CREATE_ANNOTATION, [$parser, 'onCreateAnnotation']);
15 changes: 4 additions & 11 deletions src/Annotation/Parser/DoctrineAnnotationParser.php
Original file line number Diff line number Diff line change
@@ -55,11 +55,8 @@ public function __construct()

/**
* Set the DocParser instance
*
* @param DocParser $docParser
* @return DoctrineAnnotationParser
*/
public function setDocParser(DocParser $docParser)
public function setDocParser(DocParser $docParser) : self
{
$this->docParser = $docParser;
return $this;
@@ -69,10 +66,8 @@ public function setDocParser(DocParser $docParser)
* Retrieve the DocParser instance
*
* If none is registered, lazy-loads a new instance.
*
* @return DocParser
*/
public function getDocParser()
public function getDocParser() : DocParser
{
if (! $this->docParser instanceof DocParser) {
$this->setDocParser(new DocParser());
@@ -127,9 +122,8 @@ public function onCreateAnnotation(EventInterface $e)
* Specify an allowed annotation class
*
* @param string $annotation
* @return DoctrineAnnotationParser
*/
public function registerAnnotation($annotation)
public function registerAnnotation($annotation) : self
{
$this->allowedAnnotations[$annotation] = true;
return $this;
@@ -141,9 +135,8 @@ public function registerAnnotation($annotation)
* @param array|Traversable $annotations Array or traversable object of
* annotation class names
* @throws Exception\InvalidArgumentException
* @return DoctrineAnnotationParser
*/
public function registerAnnotations($annotations)
public function registerAnnotations($annotations) : self
{
if (! is_array($annotations) && ! $annotations instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
32 changes: 7 additions & 25 deletions src/Annotation/Parser/GenericAnnotationParser.php
Original file line number Diff line number Diff line change
@@ -93,10 +93,9 @@ public function onCreateAnnotation(EventInterface $e)
*
* @param string|AnnotationInterface $annotation String class name of an
* AnnotationInterface implementation, or actual instance
* @return void
* @throws Exception\InvalidArgumentException
*/
public function registerAnnotation($annotation)
public function registerAnnotation($annotation) : void
{
$class = false;
if (is_string($annotation) && class_exists($annotation)) {
@@ -131,9 +130,8 @@ public function registerAnnotation($annotation)
*
* @param array|Traversable $annotations
* @throws Exception\InvalidArgumentException
* @return GenericAnnotationParser
*/
public function registerAnnotations($annotations)
public function registerAnnotations($annotations) : self
{
if (! is_array($annotations) && ! $annotations instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
@@ -152,11 +150,8 @@ public function registerAnnotations($annotations)

/**
* Checks if the manager has annotations for a class
*
* @param string $class
* @return bool
*/
public function hasAnnotation($class)
public function hasAnnotation(string $class) : bool
{
if (in_array($class, $this->annotationNames)) {
return true;
@@ -175,9 +170,8 @@ public function hasAnnotation($class)
* @param string $alias
* @param string $class May be either a registered annotation name or another alias
* @throws Exception\InvalidArgumentException
* @return GenericAnnotationParser
*/
public function setAlias($alias, $class)
public function setAlias(string $alias, string $class) : self
{
if (! in_array($class, $this->annotationNames) && ! $this->hasAlias($class)) {
throw new Exception\InvalidArgumentException(sprintf(
@@ -195,24 +189,15 @@ public function setAlias($alias, $class)
return $this;
}

/**
* Normalize an alias name
*
* @param string $alias
* @return string
*/
protected function normalizeAlias($alias)
protected function normalizeAlias(string $alias) : string
{
return strtolower(str_replace(['-', '_', ' ', '\\', '/'], '', $alias));
}

/**
* Do we have an alias by the provided name?
*
* @param string $alias
* @return bool
*/
protected function hasAlias($alias)
protected function hasAlias(string $alias) : bool
{
$alias = $this->normalizeAlias($alias);

@@ -221,11 +206,8 @@ protected function hasAlias($alias)

/**
* Resolve an alias to a class name
*
* @param string $alias
* @return string
*/
protected function resolveAlias($alias)
protected function resolveAlias(string $alias) : string
{
do {
$normalized = $this->normalizeAlias($alias);
2 changes: 1 addition & 1 deletion src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,6 @@

namespace Zend\Code\Exception;

interface ExceptionInterface
interface ExceptionInterface extends \Throwable
{
}
43 changes: 10 additions & 33 deletions src/Generator/AbstractGenerator.php
Original file line number Diff line number Diff line change
@@ -50,66 +50,43 @@ public function __construct($options = [])
}
}

/**
* @param bool $isSourceDirty
* @return AbstractGenerator
*/
public function setSourceDirty($isSourceDirty = true)
public function setSourceDirty(bool $isSourceDirty = true) : self
{
$this->isSourceDirty = (bool) $isSourceDirty;
$this->isSourceDirty = $isSourceDirty;
return $this;
}

/**
* @return bool
*/
public function isSourceDirty()
public function isSourceDirty() : bool
{
return $this->isSourceDirty;
}

/**
* @param string $indentation
* @return AbstractGenerator
*/
public function setIndentation($indentation)
public function setIndentation(string $indentation) : self
{
$this->indentation = (string) $indentation;
$this->indentation = $indentation;
return $this;
}

/**
* @return string
*/
public function getIndentation()
public function getIndentation() : string
{
return $this->indentation;
}

/**
* @param string $sourceContent
* @return AbstractGenerator
*/
public function setSourceContent($sourceContent)
public function setSourceContent(?string $sourceContent) : self
{
$this->sourceContent = (string) $sourceContent;
$this->sourceContent = $sourceContent;
return $this;
}

/**
* @return string
*/
public function getSourceContent()
public function getSourceContent() : ?string
{
return $this->sourceContent;
}

/**
* @param array|Traversable $options
* @throws Exception\InvalidArgumentException
* @return AbstractGenerator
*/
public function setOptions($options)
public function setOptions(iterable $options) : self
{
if (! is_array($options) && ! $options instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
Loading