Skip to content

Commit 2596137

Browse files
authored
Merge pull request #18 from ashnazg/ci
ecs & phpstan fixes
2 parents 6e20ec2 + 5cdad66 commit 2596137

File tree

11 files changed

+142
-150
lines changed

11 files changed

+142
-150
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Build folder and vendor folder are generated code; no need to version this
1010
build/*
1111
vendor/*
12+
temp/*
1213
composer.phar
1314

1415
# By default the phpunit.xml.dist is provided; you can override this using a local config file

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ install:
5353

5454
test_script:
5555
- cd c:\graphviz
56-
- vendor/bin/phpunit
56+
- vendor/bin/phpunit --no-coverage

src/phpDocumentor/GraphViz/Attribute.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Attribute
2525
/** @var string The name of this attribute */
2626
protected $key = '';
2727

28-
/** @var string The value of this attribute*/
28+
/** @var string The value of this attribute */
2929
protected $value = '';
3030

3131
/**
@@ -94,7 +94,7 @@ public function getValue()
9494
public function __toString()
9595
{
9696
$key = $this->getKey();
97-
if ($key == 'url') {
97+
if ($key === 'url') {
9898
$key = 'URL';
9999
}
100100

@@ -104,6 +104,7 @@ public function __toString()
104104
} elseif (!$this->isValueInHtml()) {
105105
$value = '"' . addslashes($value) . '"';
106106
}
107+
107108
return $key . '=' . $value;
108109
}
109110

@@ -116,7 +117,7 @@ public function isValueInHtml()
116117
{
117118
$value = $this->getValue();
118119

119-
return (bool)(isset($value[0]) && ($value[0] == '<'));
120+
return isset($value[0]) && ($value[0] === '<');
120121
}
121122

122123
/**
@@ -126,7 +127,7 @@ public function isValueInHtml()
126127
*/
127128
public function isValueContainingSpecials()
128129
{
129-
return strstr($this->getValue(), "\\") !== false;
130+
return strstr($this->getValue(), '\\') !== false;
130131
}
131132

132133
/**

src/phpDocumentor/GraphViz/Edge.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class Edge
2828
/** @var \phpDocumentor\GraphViz\Node Node where to to link */
2929
protected $to = null;
3030

31-
/** @var \phpDocumentor\GraphViz\Attribute List of attributes for this edge */
32-
protected $attributes = array();
31+
/** @var \phpDocumentor\GraphViz\Attribute[] List of attributes for this edge */
32+
protected $attributes = [];
3333

3434
/**
3535
* Creates a new Edge / Link between the given nodes.
@@ -38,10 +38,10 @@ class Edge
3838
* @param \phpDocumentor\GraphViz\Node $to Destination node where to create and
3939
* edge to.
4040
*/
41-
function __construct(Node $from, Node $to)
41+
public function __construct(Node $from, Node $to)
4242
{
4343
$this->from = $from;
44-
$this->to = $to;
44+
$this->to = $to;
4545
}
4646

4747
/**
@@ -55,7 +55,8 @@ function __construct(Node $from, Node $to)
5555
*
5656
* @return \phpDocumentor\GraphViz\Edge
5757
*/
58-
public static function create(Node $from, Node $to) {
58+
public static function create(Node $from, Node $to)
59+
{
5960
return new self($from, $to);
6061
}
6162

@@ -93,17 +94,18 @@ public function getTo()
9394
* setX or getX.
9495
* @param mixed[] $arguments Arguments for the setter, only 1 is expected: value
9596
*
96-
* @return \phpDocumentor\GraphViz\Attribute[]|\phpDocumentor\GraphViz\Edge|null
97+
* @return \phpDocumentor\GraphViz\Attribute|\phpDocumentor\GraphViz\Edge|null
9798
*/
98-
function __call($name, $arguments)
99+
public function __call($name, $arguments)
99100
{
100101
$key = strtolower(substr($name, 3));
101-
if (strtolower(substr($name, 0, 3)) == 'set') {
102+
if (strtolower(substr($name, 0, 3)) === 'set') {
102103
$this->attributes[$key] = new Attribute($key, $arguments[0]);
103104

104105
return $this;
105106
}
106-
if (strtolower(substr($name, 0, 3)) == 'get') {
107+
108+
if (strtolower(substr($name, 0, 3)) === 'get') {
107109
return $this->attributes[$key];
108110
}
109111

@@ -117,18 +119,19 @@ function __call($name, $arguments)
117119
*/
118120
public function __toString()
119121
{
120-
$attributes = array();
122+
$attributes = [];
121123
foreach ($this->attributes as $value) {
122-
$attributes[] = (string)$value;
124+
$attributes[] = (string) $value;
123125
}
126+
124127
$attributes = implode("\n", $attributes);
125128

126129
$from_name = addslashes($this->getFrom()->getName());
127-
$to_name = addslashes($this->getTo()->getName());
130+
$to_name = addslashes($this->getTo()->getName());
128131

129132
return <<<DOT
130-
"$from_name" -> "$to_name" [
131-
$attributes
133+
"${from_name}" -> "${to_name}" [
134+
${attributes}
132135
]
133136
DOT;
134137
}

src/phpDocumentor/GraphViz/Exception.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@
2222
*/
2323
class Exception extends \Exception
2424
{
25-
26-
}
25+
}

src/phpDocumentor/GraphViz/Graph.php

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
*/
3535
class Graph
3636
{
37-
3837
/** @var string Name of this graph */
3938
protected $name = 'G';
4039

@@ -45,16 +44,16 @@ class Graph
4544
protected $strict = false;
4645

4746
/** @var \phpDocumentor\GraphViz\Attribute[] A list of attributes for this Graph */
48-
protected $attributes = array();
47+
protected $attributes = [];
4948

5049
/** @var \phpDocumentor\GraphViz\Graph[] A list of subgraphs for this Graph */
51-
protected $graphs = array();
50+
protected $graphs = [];
5251

5352
/** @var \phpDocumentor\GraphViz\Node[] A list of nodes for this Graph */
54-
protected $nodes = array();
53+
protected $nodes = [];
5554

5655
/** @var \phpDocumentor\GraphViz\Edge[] A list of edges / arrows for this Graph */
57-
protected $edges = array();
56+
protected $edges = [];
5857

5958
/** @var string The path to execute dot from */
6059
protected $path = '';
@@ -87,9 +86,11 @@ public static function create($name = 'G', $directional = true)
8786
*/
8887
public function setPath($path)
8988
{
90-
if ($path && $path = realpath($path)) {
89+
$realpath = realpath($path);
90+
if ($path && $path === $realpath) {
9191
$this->path = $path . DIRECTORY_SEPARATOR;
9292
}
93+
9394
return $this;
9495
}
9596

@@ -131,7 +132,7 @@ public function getName()
131132
*/
132133
public function setType($type)
133134
{
134-
if (!in_array($type, array('digraph', 'graph', 'subgraph'))) {
135+
if (!in_array($type, ['digraph', 'graph', 'subgraph'])) {
135136
throw new \InvalidArgumentException(
136137
'The type for a graph must be either "digraph", "graph" or '
137138
. '"subgraph"'
@@ -187,16 +188,17 @@ public function isStrict()
187188
* @param string $name Name of the method including get/set
188189
* @param mixed[] $arguments The arguments, should be 1: the value
189190
*
190-
* @return \phpDocumentor\GraphViz\Attribute[]|\phpDocumentor\GraphViz\Graph|null
191+
* @return \phpDocumentor\GraphViz\Attribute|\phpDocumentor\GraphViz\Graph|null
191192
*/
192-
function __call($name, $arguments)
193+
public function __call($name, $arguments)
193194
{
194195
$key = strtolower(substr($name, 3));
195196
if (strtolower(substr($name, 0, 3)) === 'set') {
196197
$this->attributes[$key] = new Attribute($key, $arguments[0]);
197198

198199
return $this;
199200
}
201+
200202
if (strtolower(substr($name, 0, 3)) === 'get') {
201203
return $this->attributes[$key];
202204
}
@@ -272,7 +274,7 @@ public function setNode(Node $node)
272274
*
273275
* @param string $name Name of the node to find.
274276
*
275-
* @return \phpDocumentor\GraphViz\Node
277+
* @return \phpDocumentor\GraphViz\Node|null
276278
*/
277279
public function findNode($name)
278280
{
@@ -300,23 +302,22 @@ public function findNode($name)
300302
*
301303
* @return \phpDocumentor\GraphViz\Graph
302304
*/
303-
function __set($name, $value)
305+
public function __set($name, $value)
304306
{
305307
$this->nodes[$name] = $value;
306308
return $this;
307309
}
308310

309-
310311
/**
311312
* Returns the requested node by its name.
312313
*
313314
* @param string $name The name of the node to retrieve.
314315
*
315316
* @see \phpDocumentor\GraphViz\Graph::setNode()
316317
*
317-
* @return \phpDocumentor\GraphViz\Node
318+
* @return \phpDocumentor\GraphViz\Node|null
318319
*/
319-
function __get($name)
320+
public function __get($name)
320321
{
321322
return isset($this->nodes[$name]) ? $this->nodes[$name] : null;
322323
}
@@ -360,18 +361,18 @@ public function export($type, $filename)
360361

361362
// write the dot file to a temporary file
362363
$tmpfile = tempnam(sys_get_temp_dir(), 'gvz');
363-
file_put_contents($tmpfile, (string)$this);
364+
file_put_contents($tmpfile, (string) $this);
364365

365366
// escape the temp file for use as argument
366367
$tmpfileArg = escapeshellarg($tmpfile);
367368

368369
// create the dot output
369-
$output = array();
370+
$output = [];
370371
$code = 0;
371-
exec($this->path . "dot -T$type -o$filename < $tmpfileArg 2>&1", $output, $code);
372+
exec($this->path . "dot -T${type} -o${filename} < ${tmpfileArg} 2>&1", $output, $code);
372373
unlink($tmpfile);
373374

374-
if ($code != 0) {
375+
if ($code !== 0) {
375376
throw new Exception(
376377
'An error occurred while creating the graph; GraphViz returned: '
377378
. implode(PHP_EOL, $output)
@@ -392,22 +393,25 @@ public function export($type, $filename)
392393
public function __toString()
393394
{
394395
$elements = array_merge(
395-
$this->graphs, $this->attributes, $this->edges, $this->nodes
396+
$this->graphs,
397+
$this->attributes,
398+
$this->edges,
399+
$this->nodes
396400
);
397401

398-
$attributes = array();
402+
$attributes = [];
399403
foreach ($elements as $value) {
400-
$attributes[] = (string)$value;
404+
$attributes[] = (string) $value;
401405
}
406+
402407
$attributes = implode(PHP_EOL, $attributes);
403408

404409
$strict = ($this->isStrict() ? 'strict ' : '');
405410

406411
return <<<DOT
407412
{$strict}{$this->getType()} "{$this->getName()}" {
408-
$attributes
413+
${attributes}
409414
}
410415
DOT;
411416
}
412-
413417
}

src/phpDocumentor/GraphViz/Node.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,19 @@
2424
*/
2525
class Node
2626
{
27-
2827
/** @var string Name for this node */
2928
protected $name = '';
3029

3130
/** @var \phpDocumentor\GraphViz\Attribute[] List of attributes for this node */
32-
protected $attributes = array();
31+
protected $attributes = [];
3332

3433
/**
3534
* Creates a new node with name and optional label.
3635
*
3736
* @param string $name Name of the new node.
3837
* @param string|null $label Optional label text.
3938
*/
40-
function __construct($name, $label = null)
39+
public function __construct($name, $label = null)
4140
{
4241
$this->setName($name);
4342
if ($label !== null) {
@@ -98,17 +97,17 @@ public function getName()
9897
* @param string $name Method name; either getX or setX is expected.
9998
* @param mixed[] $arguments List of arguments; only 1 is expected for setX.
10099
*
101-
* @return \phpDocumentor\GraphViz\Attribute[]|\phpDocumentor\GraphViz\Node|null
100+
* @return \phpDocumentor\GraphViz\Attribute|\phpDocumentor\GraphViz\Node|null
102101
*/
103-
function __call($name, $arguments)
102+
public function __call($name, $arguments)
104103
{
105104
$key = strtolower(substr($name, 3));
106-
if (strtolower(substr($name, 0, 3)) == 'set') {
105+
if (strtolower(substr($name, 0, 3)) === 'set') {
107106
$this->attributes[$key] = new Attribute($key, $arguments[0]);
108107
return $this;
109108
}
110109

111-
if (strtolower(substr($name, 0, 3)) == 'get') {
110+
if (strtolower(substr($name, 0, 3)) === 'get') {
112111
return $this->attributes[$key];
113112
}
114113

@@ -122,17 +121,18 @@ function __call($name, $arguments)
122121
*/
123122
public function __toString()
124123
{
125-
$attributes = array();
124+
$attributes = [];
126125
foreach ($this->attributes as $value) {
127-
$attributes[] = (string)$value;
126+
$attributes[] = (string) $value;
128127
}
128+
129129
$attributes = implode("\n", $attributes);
130130

131131
$name = addslashes($this->getName());
132132

133133
return <<<DOT
134134
"{$name}" [
135-
$attributes
135+
${attributes}
136136
]
137137
DOT;
138138
}

0 commit comments

Comments
 (0)