From b39b1fc291e1c5760784663f88d34171abeeaef5 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Mon, 13 Dec 2021 19:49:08 +0100 Subject: [PATCH 1/2] Fix code style issues --- Makefile | 2 +- src/phpDocumentor/GraphViz/Attribute.php | 16 +++--- src/phpDocumentor/GraphViz/Attributes.php | 4 +- src/phpDocumentor/GraphViz/Edge.php | 8 +-- src/phpDocumentor/GraphViz/Graph.php | 38 +++++++------- src/phpDocumentor/GraphViz/Node.php | 8 +-- .../AttributeGetterMethodReflection.php | 43 +++++++-------- .../AttributeSetterMethodReflection.php | 47 +++++++++-------- .../PHPStan/GraphNodeReflectionExtension.php | 4 +- .../PHPStan/MethodReflectionExtension.php | 17 +++--- .../GraphViz/Test/AttributeTest.php | 16 +++--- .../phpDocumentor/GraphViz/Test/EdgeTest.php | 16 +++--- .../phpDocumentor/GraphViz/Test/GraphTest.php | 52 ++++++++++--------- .../phpDocumentor/GraphViz/Test/NodeTest.php | 16 +++--- .../PHPStan/MethodReflectionExtensionTest.php | 10 ++-- 15 files changed, 153 insertions(+), 144 deletions(-) diff --git a/Makefile b/Makefile index f863fdf..c185d9a 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ psalm: .PHONY: test test: - docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 vendor/bin/phpunit + docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.3 vendor/bin/phpunit .PHONY: pre-commit-test pre-commit-test: phpcs phpstan psalm test diff --git a/src/phpDocumentor/GraphViz/Attribute.php b/src/phpDocumentor/GraphViz/Attribute.php index 28b8d56..d55f35a 100644 --- a/src/phpDocumentor/GraphViz/Attribute.php +++ b/src/phpDocumentor/GraphViz/Attribute.php @@ -47,7 +47,7 @@ public function __construct(string $key, string $value) * * @param string $key The new name of this attribute. */ - public function setKey(string $key) : self + public function setKey(string $key): self { $this->key = $key; @@ -57,7 +57,7 @@ public function setKey(string $key) : self /** * Returns the name for this attribute. */ - public function getKey() : string + public function getKey(): string { return $this->key; } @@ -67,7 +67,7 @@ public function getKey() : string * * @param string $value The new value. */ - public function setValue(string $value) : self + public function setValue(string $value): self { $this->value = $value; @@ -77,7 +77,7 @@ public function setValue(string $value) : self /** * Returns the value for this attribute. */ - public function getValue() : string + public function getValue(): string { return $this->value; } @@ -85,7 +85,7 @@ public function getValue() : string /** * Returns the attribute definition as is requested by GraphViz. */ - public function __toString() : string + public function __toString(): string { $key = $this->getKey(); if ($key === 'url') { @@ -105,7 +105,7 @@ public function __toString() : string /** * Returns whether the value contains HTML. */ - public function isValueInHtml() : bool + public function isValueInHtml(): bool { $value = $this->getValue(); @@ -115,7 +115,7 @@ public function isValueInHtml() : bool /** * Checks whether the value contains any any special characters needing escaping. */ - public function isValueContainingSpecials() : bool + public function isValueContainingSpecials(): bool { return strstr($this->getValue(), '\\') !== false; } @@ -125,7 +125,7 @@ public function isValueContainingSpecials() : bool * * @see http://www.graphviz.org/doc/info/attrs.html#k:escString */ - protected function encodeSpecials() : string + protected function encodeSpecials(): string { $value = $this->getValue(); $regex = '(\'|"|\\x00|\\\\(?![\\\\NGETHLnlr]))'; diff --git a/src/phpDocumentor/GraphViz/Attributes.php b/src/phpDocumentor/GraphViz/Attributes.php index af690f2..4b42896 100644 --- a/src/phpDocumentor/GraphViz/Attributes.php +++ b/src/phpDocumentor/GraphViz/Attributes.php @@ -20,7 +20,7 @@ trait Attributes /** @var Attribute[] */ protected $attributes = []; - public function setAttribute(string $name, string $value) : self + public function setAttribute(string $name, string $value): self { $this->attributes[$name] = new Attribute($name, $value); @@ -30,7 +30,7 @@ public function setAttribute(string $name, string $value) : self /** * @throws AttributeNotFound */ - public function getAttribute(string $name) : Attribute + public function getAttribute(string $name): Attribute { if (!array_key_exists($name, $this->attributes)) { throw new AttributeNotFound($name); diff --git a/src/phpDocumentor/GraphViz/Edge.php b/src/phpDocumentor/GraphViz/Edge.php index f4ba6eb..0606087 100644 --- a/src/phpDocumentor/GraphViz/Edge.php +++ b/src/phpDocumentor/GraphViz/Edge.php @@ -55,7 +55,7 @@ public function __construct(Node $from, Node $to) * @param Node $to Destination node where to create and * edge to. */ - public static function create(Node $from, Node $to) : self + public static function create(Node $from, Node $to): self { return new self($from, $to); } @@ -63,7 +63,7 @@ public static function create(Node $from, Node $to) : self /** * Returns the source Node for this Edge. */ - public function getFrom() : Node + public function getFrom(): Node { return $this->from; } @@ -71,7 +71,7 @@ public function getFrom() : Node /** * Returns the destination Node for this Edge. */ - public function getTo() : Node + public function getTo(): Node { return $this->to; } @@ -111,7 +111,7 @@ public function __call(string $name, array $arguments) /** * Returns the edge definition as is requested by GraphViz. */ - public function __toString() : string + public function __toString(): string { $attributes = []; foreach ($this->attributes as $value) { diff --git a/src/phpDocumentor/GraphViz/Graph.php b/src/phpDocumentor/GraphViz/Graph.php index 8288174..f848d06 100644 --- a/src/phpDocumentor/GraphViz/Graph.php +++ b/src/phpDocumentor/GraphViz/Graph.php @@ -14,6 +14,7 @@ namespace phpDocumentor\GraphViz; use InvalidArgumentException; + use function array_merge; use function escapeshellarg; use function exec; @@ -26,6 +27,7 @@ use function sys_get_temp_dir; use function tempnam; use function unlink; + use const DIRECTORY_SEPARATOR; use const PHP_EOL; @@ -78,7 +80,7 @@ class Graph * * @return Graph */ - public static function create(string $name = 'G', bool $directional = true) : self + public static function create(string $name = 'G', bool $directional = true): self { $graph = new self(); $graph @@ -93,7 +95,7 @@ public static function create(string $name = 'G', bool $directional = true) : se * * @param string $path The path to execute dot from */ - public function setPath(string $path) : self + public function setPath(string $path): self { $realpath = realpath($path); if ($path && $path === $realpath) { @@ -111,7 +113,7 @@ public function setPath(string $path) : self * * @param string $name The new name for this graph. */ - public function setName(string $name) : self + public function setName(string $name): self { $this->name = $name; @@ -121,7 +123,7 @@ public function setName(string $name) : self /** * Returns the name for this Graph. */ - public function getName() : string + public function getName(): string { return $this->name; } @@ -134,7 +136,7 @@ public function getName() : string * @throws InvalidArgumentException If $type is not "digraph", "graph" or * "subgraph". */ - public function setType(string $type) : self + public function setType(string $type): self { if (!in_array($type, ['digraph', 'graph', 'subgraph'], true)) { throw new InvalidArgumentException( @@ -151,7 +153,7 @@ public function setType(string $type) : self /** * Returns the type of this Graph. */ - public function getType() : string + public function getType(): string { return $this->type; } @@ -160,14 +162,14 @@ public function getType() : string * Set if the Graph should be strict. If the graph is strict then * multiple edges are not allowed between the same pairs of nodes */ - public function setStrict(bool $isStrict) : self + public function setStrict(bool $isStrict): self { $this->strict = $isStrict; return $this; } - public function isStrict() : bool + public function isStrict(): bool { return $this->strict; } @@ -215,7 +217,7 @@ public function __call(string $name, array $arguments) * @param Graph $graph The graph to add onto this graph as * subgraph. */ - public function addGraph(self $graph) : self + public function addGraph(self $graph): self { $graph->setType('subgraph'); $this->graphs[$graph->getName()] = $graph; @@ -228,7 +230,7 @@ public function addGraph(self $graph) : self * * @param string $name Name of the graph to find. */ - public function hasGraph(string $name) : bool + public function hasGraph(string $name): bool { return isset($this->graphs[$name]); } @@ -238,7 +240,7 @@ public function hasGraph(string $name) : bool * * @param string $name Name of the requested graph. */ - public function getGraph(string $name) : self + public function getGraph(string $name): self { return $this->graphs[$name]; } @@ -253,7 +255,7 @@ public function getGraph(string $name) : self * * @param Node $node The node to set onto this Graph. */ - public function setNode(Node $node) : self + public function setNode(Node $node): self { $this->nodes[$node->getName()] = $node; @@ -265,7 +267,7 @@ public function setNode(Node $node) : self * * @param string $name Name of the node to find. */ - public function findNode(string $name) : ?Node + public function findNode(string $name): ?Node { if (isset($this->nodes[$name])) { return $this->nodes[$name]; @@ -289,7 +291,7 @@ public function findNode(string $name) : ?Node * @param string $name Name of the node. * @param Node $value Node to set on the given name. */ - public function __set(string $name, Node $value) : void + public function __set(string $name, Node $value): void { $this->nodes[$name] = $value; } @@ -301,7 +303,7 @@ public function __set(string $name, Node $value) : void * * @param string $name The name of the node to retrieve. */ - public function __get(string $name) : ?Node + public function __get(string $name): ?Node { return $this->nodes[$name] ?? null; } @@ -313,7 +315,7 @@ public function __get(string $name) : ?Node * * @param Edge $edge The link between two classes. */ - public function link(Edge $edge) : self + public function link(Edge $edge): self { $this->edges[] = $edge; @@ -334,7 +336,7 @@ public function link(Edge $edge) : self * * @throws Exception If an error occurred in GraphViz. */ - public function export(string $type, string $filename) : self + public function export(string $type, string $filename): self { $type = escapeshellarg($type); $filename = escapeshellarg($filename); @@ -368,7 +370,7 @@ public function export(string $type, string $filename) : self * GraphViz is not used in this method; it is safe to call it even without * GraphViz installed. */ - public function __toString() : string + public function __toString(): string { $elements = array_merge( $this->graphs, diff --git a/src/phpDocumentor/GraphViz/Node.php b/src/phpDocumentor/GraphViz/Node.php index 6b13e7c..4956802 100644 --- a/src/phpDocumentor/GraphViz/Node.php +++ b/src/phpDocumentor/GraphViz/Node.php @@ -56,7 +56,7 @@ public function __construct(string $name, ?string $label = null) * @param string $name Name of the new node. * @param string|null $label Optional label text. */ - public static function create(string $name, ?string $label = null) : self + public static function create(string $name, ?string $label = null): self { return new self($name, $label); } @@ -68,7 +68,7 @@ public static function create(string $name, ?string $label = null) : self * * @param string $name Name for this node. */ - public function setName(string $name) : self + public function setName(string $name): self { $this->name = $name; @@ -78,7 +78,7 @@ public function setName(string $name) : self /** * Returns the name for this node. */ - public function getName() : string + public function getName(): string { return $this->name; } @@ -117,7 +117,7 @@ public function __call(string $name, array $arguments) /** * Returns the node definition as is requested by GraphViz. */ - public function __toString() : string + public function __toString(): string { $attributes = []; foreach ($this->attributes as $value) { diff --git a/src/phpDocumentor/PHPStan/AttributeGetterMethodReflection.php b/src/phpDocumentor/PHPStan/AttributeGetterMethodReflection.php index 3ae9663..01ea3eb 100644 --- a/src/phpDocumentor/PHPStan/AttributeGetterMethodReflection.php +++ b/src/phpDocumentor/PHPStan/AttributeGetterMethodReflection.php @@ -39,32 +39,32 @@ public function __construct(ClassReflection $classReflection, string $name) $this->name = $name; } - public function getDeclaringClass() : ClassReflection + public function getDeclaringClass(): ClassReflection { return $this->classReflection; } - public function isStatic() : bool + public function isStatic(): bool { return false; } - public function isPrivate() : bool + public function isPrivate(): bool { return false; } - public function isPublic() : bool + public function isPublic(): bool { return true; } - public function getName() : string + public function getName(): string { return $this->name; } - public function getPrototype() : ClassMemberReflection + public function getPrototype(): ClassMemberReflection { return $this; } @@ -72,49 +72,50 @@ public function getPrototype() : ClassMemberReflection /** * @return ParametersAcceptor[] */ - public function getVariants() : array + public function getVariants(): array { - return [new FunctionVariant( - TemplateTypeMap::createEmpty(), - null, - [], - false, - new ObjectType(Attribute::class) - ), + return [ + new FunctionVariant( + TemplateTypeMap::createEmpty(), + null, + [], + false, + new ObjectType(Attribute::class) + ), ]; } - public function getDocComment() : ?string + public function getDocComment(): ?string { return null; } - public function isDeprecated() : TrinaryLogic + public function isDeprecated(): TrinaryLogic { return TrinaryLogic::createNo(); } - public function getDeprecatedDescription() : ?string + public function getDeprecatedDescription(): ?string { return null; } - public function isFinal() : TrinaryLogic + public function isFinal(): TrinaryLogic { return TrinaryLogic::createNo(); } - public function isInternal() : TrinaryLogic + public function isInternal(): TrinaryLogic { return TrinaryLogic::createNo(); } - public function getThrowType() : ?Type + public function getThrowType(): ?Type { return new ObjectType(AttributeNotFound::class); } - public function hasSideEffects() : TrinaryLogic + public function hasSideEffects(): TrinaryLogic { return TrinaryLogic::createMaybe(); } diff --git a/src/phpDocumentor/PHPStan/AttributeSetterMethodReflection.php b/src/phpDocumentor/PHPStan/AttributeSetterMethodReflection.php index 429b1f1..961150a 100644 --- a/src/phpDocumentor/PHPStan/AttributeSetterMethodReflection.php +++ b/src/phpDocumentor/PHPStan/AttributeSetterMethodReflection.php @@ -42,32 +42,32 @@ public function __construct(ClassReflection $classReflection, string $name, Type $this->attributeType = $attributeType; } - public function getDeclaringClass() : ClassReflection + public function getDeclaringClass(): ClassReflection { return $this->classReflection; } - public function isStatic() : bool + public function isStatic(): bool { return false; } - public function isPrivate() : bool + public function isPrivate(): bool { return false; } - public function isPublic() : bool + public function isPublic(): bool { return true; } - public function getName() : string + public function getName(): string { return $this->name; } - public function getPrototype() : ClassMemberReflection + public function getPrototype(): ClassMemberReflection { return $this; } @@ -75,51 +75,52 @@ public function getPrototype() : ClassMemberReflection /** * @return ParametersAcceptor[] */ - public function getVariants() : array + public function getVariants(): array { - return [new FunctionVariant( - TemplateTypeMap::createEmpty(), - TemplateTypeMap::createEmpty(), - [ - new DummyParameter('value', $this->attributeType, false, null, false, null), - ], - false, - new ObjectType($this->classReflection->getName()) - ), + return [ + new FunctionVariant( + TemplateTypeMap::createEmpty(), + TemplateTypeMap::createEmpty(), + [ + new DummyParameter('value', $this->attributeType, false, null, false, null), + ], + false, + new ObjectType($this->classReflection->getName()) + ), ]; } - public function getDocComment() : ?string + public function getDocComment(): ?string { return null; } - public function isDeprecated() : TrinaryLogic + public function isDeprecated(): TrinaryLogic { return TrinaryLogic::createNo(); } - public function getDeprecatedDescription() : ?string + public function getDeprecatedDescription(): ?string { return null; } - public function isFinal() : TrinaryLogic + public function isFinal(): TrinaryLogic { return TrinaryLogic::createNo(); } - public function isInternal() : TrinaryLogic + public function isInternal(): TrinaryLogic { return TrinaryLogic::createNo(); } - public function getThrowType() : ?Type + public function getThrowType(): ?Type { return new ObjectType(AttributeNotFound::class); } - public function hasSideEffects() : TrinaryLogic + public function hasSideEffects(): TrinaryLogic { return TrinaryLogic::createYes(); } diff --git a/src/phpDocumentor/PHPStan/GraphNodeReflectionExtension.php b/src/phpDocumentor/PHPStan/GraphNodeReflectionExtension.php index 70f3818..b6793e4 100644 --- a/src/phpDocumentor/PHPStan/GraphNodeReflectionExtension.php +++ b/src/phpDocumentor/PHPStan/GraphNodeReflectionExtension.php @@ -23,12 +23,12 @@ final class GraphNodeReflectionExtension implements PropertiesClassReflectionExtension { - public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool + public function hasProperty(ClassReflection $classReflection, string $propertyName): bool { return $classReflection->getName() === Graph::class; } - public function getProperty(ClassReflection $classReflection, string $propertyName) : PropertyReflection + public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection { return new AnnotationPropertyReflection( $classReflection, diff --git a/src/phpDocumentor/PHPStan/MethodReflectionExtension.php b/src/phpDocumentor/PHPStan/MethodReflectionExtension.php index 149c4da..951b3b8 100644 --- a/src/phpDocumentor/PHPStan/MethodReflectionExtension.php +++ b/src/phpDocumentor/PHPStan/MethodReflectionExtension.php @@ -26,6 +26,7 @@ use PHPStan\Type\Type; use RuntimeException; use SimpleXMLElement; + use function array_key_exists; use function array_map; use function file_get_contents; @@ -45,7 +46,7 @@ final class MethodReflectionExtension implements MethodsClassReflectionExtension Edge::class => 'edge', ]; - public function hasMethod(ClassReflection $classReflection, string $methodName) : bool + public function hasMethod(ClassReflection $classReflection, string $methodName): bool { if (!array_key_exists($classReflection->getName(), self::SUPPORTED_CLASSES)) { return false; @@ -57,7 +58,7 @@ public function hasMethod(ClassReflection $classReflection, string $methodName) return in_array($expectedAttribute, $methods, true); } - public function getMethod(ClassReflection $classReflection, string $methodName) : MethodReflection + public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection { if (stripos($methodName, 'get') === 0) { return new AttributeGetterMethodReflection($classReflection, $methodName); @@ -75,7 +76,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName) /** * @return string[] */ - private function getMethodsFromSpec(string $className) : array + private function getMethodsFromSpec(string $className): array { $simpleXml = $this->getAttributesXmlDoc(); @@ -88,14 +89,14 @@ private function getMethodsFromSpec(string $className) : array } return array_map( - static function (SimpleXMLElement $attribute) : string { + static function (SimpleXMLElement $attribute): string { return strtolower((string) $attribute['ref']); }, $elements ); } - private function getAttributeInputType(string $ref) : Type + private function getAttributeInputType(string $ref): Type { $simpleXml = $this->getAttributesXmlDoc(); $attributes = $simpleXml->xpath(sprintf("xsd:attribute[@name='%s']", $ref)); @@ -109,15 +110,17 @@ private function getAttributeInputType(string $ref) : Type switch ($type) { case 'boolean': return new BooleanType(); + case 'decimal': return new FloatType(); + case 'string': default: return new StringType(); } } - private function getAttributesXmlDoc() : SimpleXMLElement + private function getAttributesXmlDoc(): SimpleXMLElement { $fileContent = file_get_contents(__DIR__ . '/assets/attributes.xml'); @@ -133,7 +136,7 @@ private function getAttributesXmlDoc() : SimpleXMLElement return $xml; } - private function getAttributeFromMethodName(string $methodName) : string + private function getAttributeFromMethodName(string $methodName): string { return strtolower(substr($methodName, 3)); } diff --git a/tests/phpDocumentor/GraphViz/Test/AttributeTest.php b/tests/phpDocumentor/GraphViz/Test/AttributeTest.php index d45c899..3c1d5a4 100644 --- a/tests/phpDocumentor/GraphViz/Test/AttributeTest.php +++ b/tests/phpDocumentor/GraphViz/Test/AttributeTest.php @@ -27,7 +27,7 @@ class AttributeTest extends TestCase /** * Initializes the fixture for this test. */ - protected function setUp() : void + protected function setUp(): void { $this->fixture = new Attribute('a', '1'); } @@ -38,7 +38,7 @@ protected function setUp() : void * @covers \phpDocumentor\GraphViz\Attribute::__construct * @returnn void */ - public function testConstruct() : void + public function testConstruct(): void { $fixture = new Attribute('MyKey', 'MyValue'); $this->assertInstanceOf( @@ -55,7 +55,7 @@ public function testConstruct() : void * @covers \phpDocumentor\GraphViz\Attribute::getKey * @covers \phpDocumentor\GraphViz\Attribute::setKey */ - public function testKey() : void + public function testKey(): void { $this->assertSame( $this->fixture->getKey(), @@ -80,7 +80,7 @@ public function testKey() : void * @covers \phpDocumentor\GraphViz\Attribute::getValue * @covers \phpDocumentor\GraphViz\Attribute::setValue */ - public function testValue() : void + public function testValue(): void { $this->assertSame( $this->fixture->getValue(), @@ -104,7 +104,7 @@ public function testValue() : void * * @covers \phpDocumentor\GraphViz\Attribute::isValueInHtml */ - public function testIsValueInHtml() : void + public function testIsValueInHtml(): void { $this->fixture->setValue('a'); $this->assertFalse( @@ -124,7 +124,7 @@ public function testIsValueInHtml() : void * * @covers \phpDocumentor\GraphViz\Attribute::__toString */ - public function testToString() : void + public function testToString(): void { $this->fixture = new Attribute('a', 'b'); $this->assertSame( @@ -161,7 +161,7 @@ public function testToString() : void * @covers \phpDocumentor\GraphViz\Attribute::__toString * @covers \phpDocumentor\GraphViz\Attribute::encodeSpecials */ - public function testToStringWithSpecials() : void + public function testToStringWithSpecials(): void { $this->fixture = new Attribute('a', 'b'); @@ -190,7 +190,7 @@ public function testToStringWithSpecials() : void * * @covers \phpDocumentor\GraphViz\Attribute::isValueContainingSpecials */ - public function testIsValueContainingSpecials() : void + public function testIsValueContainingSpecials(): void { $this->fixture->setValue('+ name : string\l+ home_country : string\l'); $this->assertTrue($this->fixture->isValueContainingSpecials()); diff --git a/tests/phpDocumentor/GraphViz/Test/EdgeTest.php b/tests/phpDocumentor/GraphViz/Test/EdgeTest.php index fe4c122..4145e0a 100644 --- a/tests/phpDocumentor/GraphViz/Test/EdgeTest.php +++ b/tests/phpDocumentor/GraphViz/Test/EdgeTest.php @@ -28,7 +28,7 @@ class EdgeTest extends TestCase * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() : void + protected function tearDown(): void { m::close(); } @@ -38,7 +38,7 @@ protected function tearDown() : void * * @covers \phpDocumentor\GraphViz\Edge::__construct */ - public function testConstruct() : void + public function testConstruct(): void { $fromNode = m::mock(Node::class); $toNode = m::mock(Node::class); @@ -63,7 +63,7 @@ public function testConstruct() : void * * @covers \phpDocumentor\GraphViz\Edge::create */ - public function testCreate() : void + public function testCreate(): void { $this->assertInstanceOf( Edge::class, @@ -77,7 +77,7 @@ public function testCreate() : void * * @covers \phpDocumentor\GraphViz\Edge::getFrom */ - public function testGetFrom() : void + public function testGetFrom(): void { $from = new Node('from'); $edge = Edge::create($from, new Node('to')); @@ -90,7 +90,7 @@ public function testGetFrom() : void * * @covers \phpDocumentor\GraphViz\Edge::getTo */ - public function testGetTo() : void + public function testGetTo(): void { $to = new Node('to'); $edge = Edge::create(new Node('from'), $to); @@ -106,7 +106,7 @@ public function testGetTo() : void * @covers \phpDocumentor\GraphViz\Edge::setAttribute * @covers \phpDocumentor\GraphViz\Edge::getAttribute */ - public function testCall() : void + public function testCall(): void { $label = 'my label'; $fixture = new Edge(new Node('from'), new Node('to')); @@ -119,7 +119,7 @@ public function testCall() : void * @covers \phpDocumentor\GraphViz\Edge::getAttribute * @covers \phpDocumentor\GraphViz\AttributeNotFound::__construct */ - public function testGetNonExistingAttributeThrowsAttributeNotFound() : void + public function testGetNonExistingAttributeThrowsAttributeNotFound(): void { $fixture = new Edge(new Node('from'), new Node('to')); @@ -135,7 +135,7 @@ public function testGetNonExistingAttributeThrowsAttributeNotFound() : void * * @covers \phpDocumentor\GraphViz\Edge::__toString */ - public function testToString() : void + public function testToString(): void { $fixture = new Edge(new Node('from'), new Node('to')); $fixture->setLabel('MyLabel'); diff --git a/tests/phpDocumentor/GraphViz/Test/GraphTest.php b/tests/phpDocumentor/GraphViz/Test/GraphTest.php index a7039e1..242d01d 100644 --- a/tests/phpDocumentor/GraphViz/Test/GraphTest.php +++ b/tests/phpDocumentor/GraphViz/Test/GraphTest.php @@ -22,10 +22,12 @@ use phpDocumentor\GraphViz\Node; use PHPUnit\Framework\TestCase; use RuntimeException; + use function is_readable; use function preg_replace; use function sys_get_temp_dir; use function tempnam; + use const PHP_EOL; /** @@ -40,7 +42,7 @@ class GraphTest extends TestCase * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() : void + protected function setUp(): void { $this->fixture = new Graph(); } @@ -49,7 +51,7 @@ protected function setUp() : void * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() : void + protected function tearDown(): void { m::close(); } @@ -57,7 +59,7 @@ protected function tearDown() : void /** * @covers \phpDocumentor\GraphViz\Graph::create */ - public function testCreate() : void + public function testCreate(): void { $fixture = Graph::create(); $this->assertInstanceOf( @@ -87,7 +89,7 @@ public function testCreate() : void /** * @covers \phpDocumentor\GraphViz\Graph::setName */ - public function testSetName() : void + public function testSetName(): void { $this->assertSame( $this->fixture, @@ -99,7 +101,7 @@ public function testSetName() : void /** * @covers \phpDocumentor\GraphViz\Graph::getName */ - public function testGetName() : void + public function testGetName(): void { $this->assertSame( $this->fixture->getName(), @@ -117,7 +119,7 @@ public function testGetName() : void /** * @covers \phpDocumentor\GraphViz\Graph::setType */ - public function testSetType() : void + public function testSetType(): void { $this->assertSame( $this->fixture, @@ -139,7 +141,7 @@ public function testSetType() : void /** * @covers \phpDocumentor\GraphViz\Graph::setType */ - public function testSetTypeException() : void + public function testSetTypeException(): void { $this->expectException(InvalidArgumentException::class); $this->fixture->setType('fakegraphg'); @@ -148,7 +150,7 @@ public function testSetTypeException() : void /** * @covers \phpDocumentor\GraphViz\Graph::getType */ - public function testGetType() : void + public function testGetType(): void { $this->assertSame( $this->fixture->getType(), @@ -161,7 +163,7 @@ public function testGetType() : void ); } - public function testSetStrict() : void + public function testSetStrict(): void { $this->assertSame( $this->fixture, @@ -175,7 +177,7 @@ public function testSetStrict() : void ); } - public function testIsStrict() : void + public function testIsStrict(): void { $this->assertSame( $this->fixture->isStrict(), @@ -188,7 +190,7 @@ public function testIsStrict() : void ); } - public function testSetPath() : void + public function testSetPath(): void { $this->assertSame( $this->fixture, @@ -202,7 +204,7 @@ public function testSetPath() : void * @covers \phpDocumentor\GraphViz\Graph::getAttribute * @covers \phpDocumentor\GraphViz\Graph::setAttribute */ - public function test__call() : void + public function test__call(): void { $this->assertNull($this->fixture->MyMethod()); $this->assertSame($this->fixture, $this->fixture->setBgColor('black')); @@ -213,7 +215,7 @@ public function test__call() : void * @covers \phpDocumentor\GraphViz\Graph::getAttribute * @covers \phpDocumentor\GraphViz\AttributeNotFound::__construct */ - public function testGetNonExistingAttributeThrowsAttributeNotFound() : void + public function testGetNonExistingAttributeThrowsAttributeNotFound(): void { $this->expectException(AttributeNotFound::class); $this->expectExceptionMessage('Attribute with name "notexisting" was not found'); @@ -224,7 +226,7 @@ public function testGetNonExistingAttributeThrowsAttributeNotFound() : void /** * @covers \phpDocumentor\GraphViz\Graph::addGraph */ - public function testAddGraph() : void + public function testAddGraph(): void { $mock = m::mock(Graph::class); $mock->expects('setType'); @@ -239,7 +241,7 @@ public function testAddGraph() : void /** * @covers \phpDocumentor\GraphViz\Graph::hasGraph */ - public function testHasGraph() : void + public function testHasGraph(): void { $mock = m::mock(Graph::class); $mock->expects('getName')->andReturn('MyName'); @@ -253,7 +255,7 @@ public function testHasGraph() : void /** * @covers \phpDocumentor\GraphViz\Graph::getGraph */ - public function testGetGraph() : void + public function testGetGraph(): void { $mock = m::mock(Graph::class); $mock->expects('setType'); @@ -269,7 +271,7 @@ public function testGetGraph() : void /** * @covers \phpDocumentor\GraphViz\Graph::setNode */ - public function testSetNode() : void + public function testSetNode(): void { $mock = m::mock(Node::class); $mock->expects('getName')->andReturn('MyName'); @@ -283,7 +285,7 @@ public function testSetNode() : void /** * @covers \phpDocumentor\GraphViz\Graph::findNode */ - public function testFindNode() : void + public function testFindNode(): void { $this->assertNull($this->fixture->findNode('MyNode')); @@ -312,7 +314,7 @@ public function testFindNode() : void /** * @covers \phpDocumentor\GraphViz\Graph::__set */ - public function test__set() : void + public function test__set(): void { $mock = m::mock(Node::class); @@ -324,7 +326,7 @@ public function test__set() : void /** * @covers \phpDocumentor\GraphViz\Graph::__get */ - public function test__get() : void + public function test__get(): void { $mock = m::mock(Node::class); @@ -338,7 +340,7 @@ public function test__get() : void /** * @covers \phpDocumentor\GraphViz\Graph::link */ - public function testLink() : void + public function testLink(): void { $mock = m::mock(Edge::class); @@ -351,7 +353,7 @@ public function testLink() : void /** * @covers \phpDocumentor\GraphViz\Graph::export */ - public function testExportException() : void + public function testExportException(): void { $graph = Graph::create('My First Graph'); $filename = tempnam(sys_get_temp_dir(), 'tst'); @@ -369,7 +371,7 @@ public function testExportException() : void /** * @covers \phpDocumentor\GraphViz\Graph::export */ - public function testExport() : void + public function testExport(): void { $graph = Graph::create('My First Graph'); $filename = tempnam(sys_get_temp_dir(), 'tst'); @@ -390,7 +392,7 @@ public function testExport() : void /** * @covers \phpDocumentor\GraphViz\Graph::__toString */ - public function test__toString() : void + public function test__toString(): void { $graph = Graph::create('My First Graph'); $this->assertSame( @@ -416,7 +418,7 @@ public function test__toString() : void /** * Help avoid issue of "#Warning: Strings contain different line endings!" on Windows. */ - private function normalizeLineEndings(string $string) : string + private function normalizeLineEndings(string $string): string { $result = preg_replace('~\R~u', "\r\n", $string); if ($result === null) { diff --git a/tests/phpDocumentor/GraphViz/Test/NodeTest.php b/tests/phpDocumentor/GraphViz/Test/NodeTest.php index 244f22e..5fe1316 100644 --- a/tests/phpDocumentor/GraphViz/Test/NodeTest.php +++ b/tests/phpDocumentor/GraphViz/Test/NodeTest.php @@ -28,7 +28,7 @@ class NodeTest extends TestCase /** * Initializes the fixture for this test. */ - protected function setUp() : void + protected function setUp(): void { $this->fixture = new Node('name', 'label'); } @@ -39,7 +39,7 @@ protected function setUp() : void * @covers \phpDocumentor\GraphViz\Node::__construct * @returnn void */ - public function testConstruct() : void + public function testConstruct(): void { $fixture = new Node('MyName', 'MyLabel'); $this->assertInstanceOf( @@ -56,7 +56,7 @@ public function testConstruct() : void * @covers \phpDocumentor\GraphViz\Node::create * @returnn void */ - public function testCreate() : void + public function testCreate(): void { $this->assertInstanceOf( Node::class, @@ -70,7 +70,7 @@ public function testCreate() : void * @covers \phpDocumentor\GraphViz\Node::getName * @covers \phpDocumentor\GraphViz\Node::setName */ - public function testName() : void + public function testName(): void { $this->assertSame( $this->fixture->getName(), @@ -98,7 +98,7 @@ public function testName() : void * @covers \phpDocumentor\GraphViz\Node::getAttribute * @covers \phpDocumentor\GraphViz\Node::setAttribute */ - public function testCall() : void + public function testCall(): void { $fontname = 'Bitstream Vera Sans'; $this->assertInstanceOf(Node::class, $this->fixture->setfontname($fontname)); @@ -110,7 +110,7 @@ public function testCall() : void * @covers \phpDocumentor\GraphViz\Node::getAttribute * @covers \phpDocumentor\GraphViz\AttributeNotFound::__construct */ - public function testGetNonExistingAttributeThrowsAttributeNotFound() : void + public function testGetNonExistingAttributeThrowsAttributeNotFound(): void { $this->expectException(AttributeNotFound::class); $this->expectExceptionMessage('Attribute with name "fontname" was not found'); @@ -124,7 +124,7 @@ public function testGetNonExistingAttributeThrowsAttributeNotFound() : void * * @covers \phpDocumentor\GraphViz\Node::__toString */ - public function testToString() : void + public function testToString(): void { $this->fixture->setfontsize(12); $this->fixture->setfontname('Bitstream Vera Sans'); @@ -146,7 +146,7 @@ public function testToString() : void * * @covers \phpDocumentor\GraphViz\Node::__toString */ - public function testToStringWithLabelContainingSlashes() : void + public function testToStringWithLabelContainingSlashes(): void { $this->fixture->setfontsize(12); $this->fixture->setfontname('Bitstream Vera Sans'); diff --git a/tests/phpDocumentor/PHPStan/MethodReflectionExtensionTest.php b/tests/phpDocumentor/PHPStan/MethodReflectionExtensionTest.php index d9e01eb..cc4e422 100644 --- a/tests/phpDocumentor/PHPStan/MethodReflectionExtensionTest.php +++ b/tests/phpDocumentor/PHPStan/MethodReflectionExtensionTest.php @@ -26,7 +26,7 @@ final class MethodReflectionExtensionTest extends TestCase /** @var MethodReflectionExtension */ private $fixture; - public function setUp() : void + public function setUp(): void { $this->fixture = new MethodReflectionExtension(); } @@ -34,7 +34,7 @@ public function setUp() : void /** * @dataProvider existingMethodProvider */ - public function testNodeHasMethodReturnsTrue(string $className, string $methodName) : void + public function testNodeHasMethodReturnsTrue(string $className, string $methodName): void { $classReflection = m::mock(ClassReflection::class); $classReflection->shouldReceive('getName')->andReturn($className); @@ -45,7 +45,7 @@ public function testNodeHasMethodReturnsTrue(string $className, string $methodNa /** * @return array> */ - public function existingMethodProvider() : array + public function existingMethodProvider(): array { return [ 'node::getLabel' => [ @@ -67,7 +67,7 @@ public function existingMethodProvider() : array ]; } - public function testAttributeType() : void + public function testAttributeType(): void { $classReflection = m::mock(ClassReflection::class); $classReflection->shouldReceive('getName')->andReturn(Node::class); @@ -77,7 +77,7 @@ public function testAttributeType() : void $this->assertInstanceOf(FloatType::class, $method->getVariants()[0]->getParameters()[0]->getType()); } - public function testAttributeTypeOfNoneExisting() : void + public function testAttributeTypeOfNoneExisting(): void { $classReflection = m::mock(ClassReflection::class); $classReflection->shouldReceive('getName')->andReturn(Node::class); From d4b36f78d0d0f85cc2896d1b837b8065a4eb575b Mon Sep 17 00:00:00 2001 From: Jaapio Date: Mon, 13 Dec 2021 20:00:52 +0100 Subject: [PATCH 2/2] Move to composer based psalm --- .github/workflows/push.yml | 2 +- Makefile | 2 +- composer.json | 3 ++- phive.xml | 6 ------ psalm.xml | 5 +++++ 5 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 phive.xml diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 2ca5441..38013d0 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -172,4 +172,4 @@ jobs: composer install --no-progress --prefer-dist --optimize-autoloader - name: Psalm - run: psalm --output-format=github + run: vendor/bin/psalm.phar --output-format=github diff --git a/Makefile b/Makefile index c185d9a..0cd7a08 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ phpstan: .PHONY: psalm psalm: - docker run -it --rm -v${CURDIR}:/data -w /data php:7.3 ./tools/psalm + docker run -it --rm -v${CURDIR}:/data -w /data php:7.3 vendor/bin/psalm.phar .PHONY: test test: diff --git a/composer.json b/composer.json index 56e8cc9..a0ea712 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "phpunit/phpunit": "^8.2 || ^9.2", "mockery/mockery": "^1.2", "phpstan/phpstan": "^0.12", - "ext-simplexml": "*" + "ext-simplexml": "*", + "psalm/phar": "^4.15" }, "extra": { "branch-alias": { diff --git a/phive.xml b/phive.xml deleted file mode 100644 index 078a08d..0000000 --- a/phive.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/psalm.xml b/psalm.xml index 648b6d2..18636c6 100644 --- a/psalm.xml +++ b/psalm.xml @@ -17,5 +17,10 @@ + + + + +