Skip to content

Commit 115999d

Browse files
authored
Merge pull request #94 from phpDocumentor/code_style
Fix code style issues
2 parents d02be07 + d4b36f7 commit 115999d

19 files changed

+162
-153
lines changed

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,4 @@ jobs:
172172
composer install --no-progress --prefer-dist --optimize-autoloader
173173
174174
- name: Psalm
175-
run: psalm --output-format=github
175+
run: vendor/bin/psalm.phar --output-format=github

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ phpstan:
2424

2525
.PHONY: psalm
2626
psalm:
27-
docker run -it --rm -v${CURDIR}:/data -w /data php:7.3 ./tools/psalm
27+
docker run -it --rm -v${CURDIR}:/data -w /data php:7.3 vendor/bin/psalm.phar
2828

2929
.PHONY: test
3030
test:
31-
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 vendor/bin/phpunit
31+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.3 vendor/bin/phpunit
3232

3333
.PHONY: pre-commit-test
3434
pre-commit-test: phpcs phpstan psalm test

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"phpunit/phpunit": "^8.2 || ^9.2",
2929
"mockery/mockery": "^1.2",
3030
"phpstan/phpstan": "^0.12",
31-
"ext-simplexml": "*"
31+
"ext-simplexml": "*",
32+
"psalm/phar": "^4.15"
3233
},
3334
"extra": {
3435
"branch-alias": {

phive.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

psalm.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,10 @@
1717
<LessSpecificReturnType errorLevel="info" />
1818

1919
<MissingDependency errorLevel="info" />
20+
<MixedArgumentTypeCoercion>
21+
<errorLevel type="suppress">
22+
<file name="src/phpDocumentor/GraphViz/Graph.php" />
23+
</errorLevel>
24+
</MixedArgumentTypeCoercion>
2025
</issueHandlers>
2126
</psalm>

src/phpDocumentor/GraphViz/Attribute.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(string $key, string $value)
4747
*
4848
* @param string $key The new name of this attribute.
4949
*/
50-
public function setKey(string $key) : self
50+
public function setKey(string $key): self
5151
{
5252
$this->key = $key;
5353

@@ -57,7 +57,7 @@ public function setKey(string $key) : self
5757
/**
5858
* Returns the name for this attribute.
5959
*/
60-
public function getKey() : string
60+
public function getKey(): string
6161
{
6262
return $this->key;
6363
}
@@ -67,7 +67,7 @@ public function getKey() : string
6767
*
6868
* @param string $value The new value.
6969
*/
70-
public function setValue(string $value) : self
70+
public function setValue(string $value): self
7171
{
7272
$this->value = $value;
7373

@@ -77,15 +77,15 @@ public function setValue(string $value) : self
7777
/**
7878
* Returns the value for this attribute.
7979
*/
80-
public function getValue() : string
80+
public function getValue(): string
8181
{
8282
return $this->value;
8383
}
8484

8585
/**
8686
* Returns the attribute definition as is requested by GraphViz.
8787
*/
88-
public function __toString() : string
88+
public function __toString(): string
8989
{
9090
$key = $this->getKey();
9191
if ($key === 'url') {
@@ -105,7 +105,7 @@ public function __toString() : string
105105
/**
106106
* Returns whether the value contains HTML.
107107
*/
108-
public function isValueInHtml() : bool
108+
public function isValueInHtml(): bool
109109
{
110110
$value = $this->getValue();
111111

@@ -115,7 +115,7 @@ public function isValueInHtml() : bool
115115
/**
116116
* Checks whether the value contains any any special characters needing escaping.
117117
*/
118-
public function isValueContainingSpecials() : bool
118+
public function isValueContainingSpecials(): bool
119119
{
120120
return strstr($this->getValue(), '\\') !== false;
121121
}
@@ -125,7 +125,7 @@ public function isValueContainingSpecials() : bool
125125
*
126126
* @see http://www.graphviz.org/doc/info/attrs.html#k:escString
127127
*/
128-
protected function encodeSpecials() : string
128+
protected function encodeSpecials(): string
129129
{
130130
$value = $this->getValue();
131131
$regex = '(\'|"|\\x00|\\\\(?![\\\\NGETHLnlr]))';

src/phpDocumentor/GraphViz/Attributes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait Attributes
2020
/** @var Attribute[] */
2121
protected $attributes = [];
2222

23-
public function setAttribute(string $name, string $value) : self
23+
public function setAttribute(string $name, string $value): self
2424
{
2525
$this->attributes[$name] = new Attribute($name, $value);
2626

@@ -30,7 +30,7 @@ public function setAttribute(string $name, string $value) : self
3030
/**
3131
* @throws AttributeNotFound
3232
*/
33-
public function getAttribute(string $name) : Attribute
33+
public function getAttribute(string $name): Attribute
3434
{
3535
if (!array_key_exists($name, $this->attributes)) {
3636
throw new AttributeNotFound($name);

src/phpDocumentor/GraphViz/Edge.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ public function __construct(Node $from, Node $to)
5555
* @param Node $to Destination node where to create and
5656
* edge to.
5757
*/
58-
public static function create(Node $from, Node $to) : self
58+
public static function create(Node $from, Node $to): self
5959
{
6060
return new self($from, $to);
6161
}
6262

6363
/**
6464
* Returns the source Node for this Edge.
6565
*/
66-
public function getFrom() : Node
66+
public function getFrom(): Node
6767
{
6868
return $this->from;
6969
}
7070

7171
/**
7272
* Returns the destination Node for this Edge.
7373
*/
74-
public function getTo() : Node
74+
public function getTo(): Node
7575
{
7676
return $this->to;
7777
}
@@ -111,7 +111,7 @@ public function __call(string $name, array $arguments)
111111
/**
112112
* Returns the edge definition as is requested by GraphViz.
113113
*/
114-
public function __toString() : string
114+
public function __toString(): string
115115
{
116116
$attributes = [];
117117
foreach ($this->attributes as $value) {

src/phpDocumentor/GraphViz/Graph.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\GraphViz;
1515

1616
use InvalidArgumentException;
17+
1718
use function array_merge;
1819
use function escapeshellarg;
1920
use function exec;
@@ -26,6 +27,7 @@
2627
use function sys_get_temp_dir;
2728
use function tempnam;
2829
use function unlink;
30+
2931
use const DIRECTORY_SEPARATOR;
3032
use const PHP_EOL;
3133

@@ -78,7 +80,7 @@ class Graph
7880
*
7981
* @return Graph
8082
*/
81-
public static function create(string $name = 'G', bool $directional = true) : self
83+
public static function create(string $name = 'G', bool $directional = true): self
8284
{
8385
$graph = new self();
8486
$graph
@@ -93,7 +95,7 @@ public static function create(string $name = 'G', bool $directional = true) : se
9395
*
9496
* @param string $path The path to execute dot from
9597
*/
96-
public function setPath(string $path) : self
98+
public function setPath(string $path): self
9799
{
98100
$realpath = realpath($path);
99101
if ($path && $path === $realpath) {
@@ -111,7 +113,7 @@ public function setPath(string $path) : self
111113
*
112114
* @param string $name The new name for this graph.
113115
*/
114-
public function setName(string $name) : self
116+
public function setName(string $name): self
115117
{
116118
$this->name = $name;
117119

@@ -121,7 +123,7 @@ public function setName(string $name) : self
121123
/**
122124
* Returns the name for this Graph.
123125
*/
124-
public function getName() : string
126+
public function getName(): string
125127
{
126128
return $this->name;
127129
}
@@ -134,7 +136,7 @@ public function getName() : string
134136
* @throws InvalidArgumentException If $type is not "digraph", "graph" or
135137
* "subgraph".
136138
*/
137-
public function setType(string $type) : self
139+
public function setType(string $type): self
138140
{
139141
if (!in_array($type, ['digraph', 'graph', 'subgraph'], true)) {
140142
throw new InvalidArgumentException(
@@ -151,7 +153,7 @@ public function setType(string $type) : self
151153
/**
152154
* Returns the type of this Graph.
153155
*/
154-
public function getType() : string
156+
public function getType(): string
155157
{
156158
return $this->type;
157159
}
@@ -160,14 +162,14 @@ public function getType() : string
160162
* Set if the Graph should be strict. If the graph is strict then
161163
* multiple edges are not allowed between the same pairs of nodes
162164
*/
163-
public function setStrict(bool $isStrict) : self
165+
public function setStrict(bool $isStrict): self
164166
{
165167
$this->strict = $isStrict;
166168

167169
return $this;
168170
}
169171

170-
public function isStrict() : bool
172+
public function isStrict(): bool
171173
{
172174
return $this->strict;
173175
}
@@ -215,7 +217,7 @@ public function __call(string $name, array $arguments)
215217
* @param Graph $graph The graph to add onto this graph as
216218
* subgraph.
217219
*/
218-
public function addGraph(self $graph) : self
220+
public function addGraph(self $graph): self
219221
{
220222
$graph->setType('subgraph');
221223
$this->graphs[$graph->getName()] = $graph;
@@ -228,7 +230,7 @@ public function addGraph(self $graph) : self
228230
*
229231
* @param string $name Name of the graph to find.
230232
*/
231-
public function hasGraph(string $name) : bool
233+
public function hasGraph(string $name): bool
232234
{
233235
return isset($this->graphs[$name]);
234236
}
@@ -238,7 +240,7 @@ public function hasGraph(string $name) : bool
238240
*
239241
* @param string $name Name of the requested graph.
240242
*/
241-
public function getGraph(string $name) : self
243+
public function getGraph(string $name): self
242244
{
243245
return $this->graphs[$name];
244246
}
@@ -253,7 +255,7 @@ public function getGraph(string $name) : self
253255
*
254256
* @param Node $node The node to set onto this Graph.
255257
*/
256-
public function setNode(Node $node) : self
258+
public function setNode(Node $node): self
257259
{
258260
$this->nodes[$node->getName()] = $node;
259261

@@ -265,7 +267,7 @@ public function setNode(Node $node) : self
265267
*
266268
* @param string $name Name of the node to find.
267269
*/
268-
public function findNode(string $name) : ?Node
270+
public function findNode(string $name): ?Node
269271
{
270272
if (isset($this->nodes[$name])) {
271273
return $this->nodes[$name];
@@ -289,7 +291,7 @@ public function findNode(string $name) : ?Node
289291
* @param string $name Name of the node.
290292
* @param Node $value Node to set on the given name.
291293
*/
292-
public function __set(string $name, Node $value) : void
294+
public function __set(string $name, Node $value): void
293295
{
294296
$this->nodes[$name] = $value;
295297
}
@@ -301,7 +303,7 @@ public function __set(string $name, Node $value) : void
301303
*
302304
* @param string $name The name of the node to retrieve.
303305
*/
304-
public function __get(string $name) : ?Node
306+
public function __get(string $name): ?Node
305307
{
306308
return $this->nodes[$name] ?? null;
307309
}
@@ -313,7 +315,7 @@ public function __get(string $name) : ?Node
313315
*
314316
* @param Edge $edge The link between two classes.
315317
*/
316-
public function link(Edge $edge) : self
318+
public function link(Edge $edge): self
317319
{
318320
$this->edges[] = $edge;
319321

@@ -334,7 +336,7 @@ public function link(Edge $edge) : self
334336
*
335337
* @throws Exception If an error occurred in GraphViz.
336338
*/
337-
public function export(string $type, string $filename) : self
339+
public function export(string $type, string $filename): self
338340
{
339341
$type = escapeshellarg($type);
340342
$filename = escapeshellarg($filename);
@@ -368,7 +370,7 @@ public function export(string $type, string $filename) : self
368370
* GraphViz is not used in this method; it is safe to call it even without
369371
* GraphViz installed.
370372
*/
371-
public function __toString() : string
373+
public function __toString(): string
372374
{
373375
$elements = array_merge(
374376
$this->graphs,

src/phpDocumentor/GraphViz/Node.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(string $name, ?string $label = null)
5656
* @param string $name Name of the new node.
5757
* @param string|null $label Optional label text.
5858
*/
59-
public static function create(string $name, ?string $label = null) : self
59+
public static function create(string $name, ?string $label = null): self
6060
{
6161
return new self($name, $label);
6262
}
@@ -68,7 +68,7 @@ public static function create(string $name, ?string $label = null) : self
6868
*
6969
* @param string $name Name for this node.
7070
*/
71-
public function setName(string $name) : self
71+
public function setName(string $name): self
7272
{
7373
$this->name = $name;
7474

@@ -78,7 +78,7 @@ public function setName(string $name) : self
7878
/**
7979
* Returns the name for this node.
8080
*/
81-
public function getName() : string
81+
public function getName(): string
8282
{
8383
return $this->name;
8484
}
@@ -117,7 +117,7 @@ public function __call(string $name, array $arguments)
117117
/**
118118
* Returns the node definition as is requested by GraphViz.
119119
*/
120-
public function __toString() : string
120+
public function __toString(): string
121121
{
122122
$attributes = [];
123123
foreach ($this->attributes as $value) {

0 commit comments

Comments
 (0)