Skip to content

Commit

Permalink
Merge pull request #94 from phpDocumentor/code_style
Browse files Browse the repository at this point in the history
Fix code style issues
  • Loading branch information
jaapio authored Dec 13, 2021
2 parents d02be07 + d4b36f7 commit 115999d
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ 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:
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
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 0 additions & 6 deletions phive.xml

This file was deleted.

5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@
<LessSpecificReturnType errorLevel="info" />

<MissingDependency errorLevel="info" />
<MixedArgumentTypeCoercion>
<errorLevel type="suppress">
<file name="src/phpDocumentor/GraphViz/Graph.php" />
</errorLevel>
</MixedArgumentTypeCoercion>
</issueHandlers>
</psalm>
16 changes: 8 additions & 8 deletions src/phpDocumentor/GraphViz/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;

Expand All @@ -77,15 +77,15 @@ public function setValue(string $value) : self
/**
* Returns the value for this attribute.
*/
public function getValue() : string
public function getValue(): string
{
return $this->value;
}

/**
* Returns the attribute definition as is requested by GraphViz.
*/
public function __toString() : string
public function __toString(): string
{
$key = $this->getKey();
if ($key === 'url') {
Expand All @@ -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();

Expand All @@ -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;
}
Expand All @@ -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]))';
Expand Down
4 changes: 2 additions & 2 deletions src/phpDocumentor/GraphViz/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/phpDocumentor/GraphViz/Edge.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ 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);
}

/**
* Returns the source Node for this Edge.
*/
public function getFrom() : Node
public function getFrom(): Node
{
return $this->from;
}

/**
* Returns the destination Node for this Edge.
*/
public function getTo() : Node
public function getTo(): Node
{
return $this->to;
}
Expand Down Expand Up @@ -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) {
Expand Down
38 changes: 20 additions & 18 deletions src/phpDocumentor/GraphViz/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace phpDocumentor\GraphViz;

use InvalidArgumentException;

use function array_merge;
use function escapeshellarg;
use function exec;
Expand All @@ -26,6 +27,7 @@
use function sys_get_temp_dir;
use function tempnam;
use function unlink;

use const DIRECTORY_SEPARATOR;
use const PHP_EOL;

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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;

Expand All @@ -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;
}
Expand All @@ -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(
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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]);
}
Expand All @@ -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];
}
Expand All @@ -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;

Expand All @@ -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];
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/phpDocumentor/GraphViz/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 115999d

Please sign in to comment.