Skip to content

Commit

Permalink
Fix phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapio committed Jan 21, 2019
1 parent 870f5eb commit 81a7a60
Show file tree
Hide file tree
Showing 24 changed files with 74 additions and 85 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"require": {
"php": ">=7.1.3",
"ext-dom": "*",
"ext-iconv": "*",
"ext-json": "*",
"erusev/parsedown": "~1.0",
Expand Down
3 changes: 2 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker/phpstan/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM phpstan/phpstan:phar
FROM phpstan/phpstan:0.11
RUN apk add --no-cache \
php7-intl \
php7-xsl \
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ parameters:
- '#Constructor of class phpDocumentor\\Plugin\\Twig\\Extension has an unused parameter \$transformation#'
- '#Call to an undefined method League\\Flysystem\\Filesystem::find()#'
- '#Call to an undefined method Zend\\Cache\\Storage\\Adapter\\AdapterOptions::setCacheDir()#'
- '#PHPDoc tag [a-zA-Z0-9@]+ has invalid value ([a-zA-Z0-9`\.@\s\(\)\{]+): Unexpected token "`", expected TOKEN_IDENTIFIER at offset#'
- '#Access to an undefined property phpDocumentor\\Descriptor\\Collection::\$[a-z]+#'
excludes_analyse:
#test data
Expand Down
13 changes: 9 additions & 4 deletions src/phpDocumentor/Application/Stage/Transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use phpDocumentor\Transformer\Event\PreTransformEvent;
use phpDocumentor\Transformer\Event\WriterInitializationEvent;
use phpDocumentor\Transformer\Transformer;
use phpDocumentor\Transformer\Writer\WriterAbstract;
use Psr\Log\LoggerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Stopwatch\Stopwatch;
Expand Down Expand Up @@ -181,15 +182,19 @@ function (PreTransformEvent $event) {
Dispatcher::getInstance()->addListener(
Transformer::EVENT_PRE_INITIALIZATION,
function (WriterInitializationEvent $event) {
$this->logger->info(' Initialize writer "' . get_class($event->getWriter()) . '"');
if ($event->getWriter() instanceof WriterAbstract) {
$this->logger->info(' Initialize writer "' . get_class($event->getWriter()) . '"');
}
}
);
Dispatcher::getInstance()->addListener(
Transformer::EVENT_PRE_TRANSFORMATION,
function (PreTransformationEvent $event) {
$this->logger->info(
' Execute transformation using writer "' . $event->getTransformation()->getWriter() . '"'
);
if ($event->getTransformation()->getWriter() instanceof WriterAbstract) {
$this->logger->info(
' Execute transformation using writer "' . $event->getTransformation()->getWriter() . '"'
);
}
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

use phpDocumentor\Descriptor\ClassDescriptor;
use phpDocumentor\Descriptor\Collection;
use phpDocumentor\Descriptor\ConstantDescriptor;
use phpDocumentor\Descriptor\MethodDescriptor;
use phpDocumentor\Descriptor\PropertyDescriptor;
use phpDocumentor\Reflection\Php\Class_;
use phpDocumentor\Reflection\Php\Constant;
use phpDocumentor\Reflection\Php\Method;
Expand Down Expand Up @@ -72,7 +75,7 @@ protected function addConstants(array $constants, ClassDescriptor $classDescript
{
foreach ($constants as $constant) {
$constantDescriptor = $this->getBuilder()->buildDescriptor($constant);
if ($constantDescriptor) {
if ($constantDescriptor instanceof ConstantDescriptor) {
$constantDescriptor->setParent($classDescriptor);
$classDescriptor->getConstants()->set($constantDescriptor->getName(), $constantDescriptor);
}
Expand All @@ -88,7 +91,7 @@ protected function addProperties(array $properties, ClassDescriptor $classDescri
{
foreach ($properties as $property) {
$propertyDescriptor = $this->getBuilder()->buildDescriptor($property);
if ($propertyDescriptor) {
if ($propertyDescriptor instanceof PropertyDescriptor) {
$propertyDescriptor->setParent($classDescriptor);
$classDescriptor->getProperties()->set($propertyDescriptor->getName(), $propertyDescriptor);
}
Expand All @@ -104,7 +107,7 @@ protected function addMethods(array $methods, ClassDescriptor $classDescriptor):
{
foreach ($methods as $method) {
$methodDescriptor = $this->getBuilder()->buildDescriptor($method);
if ($methodDescriptor) {
if ($methodDescriptor instanceof MethodDescriptor) {
$methodDescriptor->setParent($classDescriptor);
$classDescriptor->getMethods()->set($methodDescriptor->getName(), $methodDescriptor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

namespace phpDocumentor\Descriptor\Builder\Reflector;

use phpDocumentor\Descriptor\ConstantDescriptor;
use phpDocumentor\Descriptor\InterfaceDescriptor;
use phpDocumentor\Descriptor\MethodDescriptor;
use phpDocumentor\Reflection\Php\Constant;
use phpDocumentor\Reflection\Php\Interface_;
use phpDocumentor\Reflection\Php\Method;
Expand Down Expand Up @@ -64,7 +66,7 @@ protected function addConstants(array $constants, InterfaceDescriptor $interface
{
foreach ($constants as $constant) {
$constantDescriptor = $this->getBuilder()->buildDescriptor($constant);
if ($constantDescriptor) {
if ($constantDescriptor instanceof ConstantDescriptor) {
$constantDescriptor->setParent($interfaceDescriptor);
$interfaceDescriptor->getConstants()->set($constantDescriptor->getName(), $constantDescriptor);
}
Expand All @@ -80,7 +82,7 @@ protected function addMethods(array $methods, InterfaceDescriptor $interfaceDesc
{
foreach ($methods as $method) {
$methodDescriptor = $this->getBuilder()->buildDescriptor($method);
if ($methodDescriptor) {
if ($methodDescriptor instanceof MethodDescriptor) {
$methodDescriptor->setParent($interfaceDescriptor);
$interfaceDescriptor->getMethods()->set($methodDescriptor->getName(), $methodDescriptor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace phpDocumentor\Descriptor\Builder\Reflector;

use phpDocumentor\Descriptor\MethodDescriptor;
use phpDocumentor\Descriptor\PropertyDescriptor;
use phpDocumentor\Descriptor\TraitDescriptor;
use phpDocumentor\Reflection\Php\Method;
use phpDocumentor\Reflection\Php\Property;
Expand Down Expand Up @@ -63,7 +65,7 @@ protected function addProperties(array $properties, TraitDescriptor $traitDescri
{
foreach ($properties as $property) {
$propertyDescriptor = $this->getBuilder()->buildDescriptor($property);
if ($propertyDescriptor) {
if ($propertyDescriptor instanceof PropertyDescriptor) {
$propertyDescriptor->setParent($traitDescriptor);
$traitDescriptor->getProperties()->set($propertyDescriptor->getName(), $propertyDescriptor);
}
Expand All @@ -79,7 +81,7 @@ protected function addMethods(array $methods, TraitDescriptor $traitDescriptor):
{
foreach ($methods as $method) {
$methodDescriptor = $this->getBuilder()->buildDescriptor($method);
if ($methodDescriptor) {
if ($methodDescriptor instanceof MethodDescriptor) {
$methodDescriptor->setParent($traitDescriptor);
$traitDescriptor->getMethods()->set($methodDescriptor->getName(), $methodDescriptor);
}
Expand Down
2 changes: 1 addition & 1 deletion src/phpDocumentor/Descriptor/DescriptorAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public function __call($name, $arguments)
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return (string) $this->getFullyQualifiedStructuralElementName();
}
Expand Down
4 changes: 2 additions & 2 deletions src/phpDocumentor/Descriptor/InterfaceDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function __construct()
}

/**
* {@inheritDoc}
* @param Collection $parents
*/
public function setParent($parents)
{
$this->parents = $parents;
}

/**
* {@inheritDoc}
* @return Collection
*/
public function getParent()
{
Expand Down
1 change: 1 addition & 0 deletions src/phpDocumentor/Descriptor/Interfaces/TypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@

interface TypeInterface
{
public function __toString(): string;
}
2 changes: 1 addition & 1 deletion src/phpDocumentor/Descriptor/Type/BooleanDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getName()
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->getName();
}
Expand Down
4 changes: 2 additions & 2 deletions src/phpDocumentor/Descriptor/Type/CollectionDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public function getKeyTypes()
*
* @return string
*/
public function __toString()
public function __toString(): string
{
$name = $this->getName();
$name = (string) $this->getName();

$keyTypes = [];
foreach ($this->getKeyTypes() as $type) {
Expand Down
2 changes: 1 addition & 1 deletion src/phpDocumentor/Descriptor/Type/FloatDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getName()
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->getName();
}
Expand Down
2 changes: 1 addition & 1 deletion src/phpDocumentor/Descriptor/Type/IntegerDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getName()
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->getName();
}
Expand Down
2 changes: 1 addition & 1 deletion src/phpDocumentor/Descriptor/Type/StringDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getName()
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->getName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getName()
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->getName();
}
Expand Down
12 changes: 8 additions & 4 deletions src/phpDocumentor/Plugin/Core/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ private function registerWriters(Application $app)
$writerCollection = $this->getWriterCollection($app);

$writerCollection['FileIo'] = new Writer\FileIo();
$writerCollection['checkstyle'] = new Writer\Checkstyle();
$writerCollection['sourcecode'] = new Writer\Sourcecode();
$writerCollection['statistics'] = new Writer\Statistics();
$writerCollection['xml'] = new Writer\Xml($app['transformer.routing.standard']);
$writerCollection['xsl'] = new Writer\Xsl($app['monolog']);

$writerCollection['checkstyle']->setTranslator($this->getTranslator($app));
$writerCollection['xml']->setTranslator($this->getTranslator($app));
$checkstyleWriter = new Writer\Checkstyle();
$checkstyleWriter->setTranslator($this->getTranslator($app));

$xmlWriter = new Writer\Xml($app['transformer.routing.standard']);
$xmlWriter->setTranslator($this->getTranslator($app));

$writerCollection['checkstyle'] = $checkstyleWriter;
$writerCollection['xml'] = $xmlWriter;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/phpDocumentor/Plugin/Twig/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function register(Container $app): void

/** @var Collection $writerCollection */
$writerCollection = $app['transformer.writer.collection'];
$writerCollection['twig'] = new Writer\Twig($app[\Twig\Environment::class]);
$writerCollection['twig']->setTranslator($translator);
$twigWriter = new Writer\Twig($app[\Twig\Environment::class]);
$twigWriter->setTranslator($translator);

$writerCollection['twig'] = $twigWriter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

namespace phpDocumentor\Transformer\Event;

use phpDocumentor\Event\EventAbstract;

/**
* Event that happens after each individual transformation.
*
* @author Mike van Riel <mike.vanriel@naenius.com>
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
*/
class PostTransformationEvent extends PreTransformationEvent
class PostTransformationEvent extends EventAbstract
{
}
29 changes: 6 additions & 23 deletions src/phpDocumentor/Transformer/Event/PreTransformationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,22 @@
*/
class PreTransformationEvent extends EventAbstract
{
/** @var \DOMDocument remembers the XML-based AST so that it can be used from the listener */
protected $source;

/** @var Transformation */
protected $transformation;

/**
* Returns the Abstract Syntax Tree as DOMDocument.
*/
public function getSource(): ?\DOMDocument
public function __construct($subject, Transformation $transformation)
{
return $this->source;
parent::__construct($subject);
$this->transformation = $transformation;
}

/**
* Sets the Abstract Syntax Tree as DOMDocument.
*/
public function setSource(\DOMDocument $source): self
public static function create($subject, Transformation $transformation)
{
$this->source = $source;

return $this;
return new static($subject, $transformation);
}

public function getTransformation(): ?Transformation
public function getTransformation(): Transformation
{
return $this->transformation;
}

public function setTransformation(Transformation $transformation): self
{
$this->transformation = $transformation;

return $this;
}
}
3 changes: 1 addition & 2 deletions src/phpDocumentor/Transformer/Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ private function applyTransformationToProject(Transformation $transformation, Pr
);

/** @var PreTransformationEvent $preTransformationEvent */
$preTransformationEvent = PreTransformationEvent::createInstance($this);
$preTransformationEvent->setTransformation($transformation);
$preTransformationEvent = PreTransformationEvent::create($this, $transformation);
Dispatcher::getInstance()->dispatch(self::EVENT_PRE_TRANSFORMATION, $preTransformationEvent);

$writer = $this->writers[$transformation->getWriter()];
Expand Down
5 changes: 5 additions & 0 deletions src/phpDocumentor/Transformer/Writer/WriterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ protected function checkForSpacesInPath($path)
* @param Transformation $transformation Transformation to execute.
*/
abstract public function transform(ProjectDescriptor $project, Transformation $transformation);

public function __toString(): string
{
return get_class($this);
}
}
Loading

0 comments on commit 81a7a60

Please sign in to comment.