Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Build folder and vendor folder are generated code; no need to version this
build/*
vendor/*
temp/*
composer.phar

# By default the phpunit.xml.dist is provided; you can override this using a local config file
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ install:

test_script:
- cd c:\graphviz
- vendor/bin/phpunit
- vendor/bin/phpunit --no-coverage
9 changes: 5 additions & 4 deletions src/phpDocumentor/GraphViz/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Attribute
/** @var string The name of this attribute */
protected $key = '';

/** @var string The value of this attribute*/
/** @var string The value of this attribute */
protected $value = '';

/**
Expand Down Expand Up @@ -94,7 +94,7 @@ public function getValue()
public function __toString()
{
$key = $this->getKey();
if ($key == 'url') {
if ($key === 'url') {
$key = 'URL';
}

Expand All @@ -104,6 +104,7 @@ public function __toString()
} elseif (!$this->isValueInHtml()) {
$value = '"' . addslashes($value) . '"';
}

return $key . '=' . $value;
}

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

return (bool)(isset($value[0]) && ($value[0] == '<'));
return isset($value[0]) && ($value[0] === '<');
}

/**
Expand All @@ -126,7 +127,7 @@ public function isValueInHtml()
*/
public function isValueContainingSpecials()
{
return strstr($this->getValue(), "\\") !== false;
return strstr($this->getValue(), '\\') !== false;
}

/**
Expand Down
31 changes: 17 additions & 14 deletions src/phpDocumentor/GraphViz/Edge.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class Edge
/** @var \phpDocumentor\GraphViz\Node Node where to to link */
protected $to = null;

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

/**
* Creates a new Edge / Link between the given nodes.
Expand All @@ -38,10 +38,10 @@ class Edge
* @param \phpDocumentor\GraphViz\Node $to Destination node where to create and
* edge to.
*/
function __construct(Node $from, Node $to)
public function __construct(Node $from, Node $to)
{
$this->from = $from;
$this->to = $to;
$this->to = $to;
}

/**
Expand All @@ -55,7 +55,8 @@ function __construct(Node $from, Node $to)
*
* @return \phpDocumentor\GraphViz\Edge
*/
public static function create(Node $from, Node $to) {
public static function create(Node $from, Node $to)
{
return new self($from, $to);
}

Expand Down Expand Up @@ -93,17 +94,18 @@ public function getTo()
* setX or getX.
* @param mixed[] $arguments Arguments for the setter, only 1 is expected: value
*
* @return \phpDocumentor\GraphViz\Attribute[]|\phpDocumentor\GraphViz\Edge|null
* @return \phpDocumentor\GraphViz\Attribute|\phpDocumentor\GraphViz\Edge|null
*/
function __call($name, $arguments)
public function __call($name, $arguments)
{
$key = strtolower(substr($name, 3));
if (strtolower(substr($name, 0, 3)) == 'set') {
if (strtolower(substr($name, 0, 3)) === 'set') {
$this->attributes[$key] = new Attribute($key, $arguments[0]);

return $this;
}
if (strtolower(substr($name, 0, 3)) == 'get') {

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

Expand All @@ -117,18 +119,19 @@ function __call($name, $arguments)
*/
public function __toString()
{
$attributes = array();
$attributes = [];
foreach ($this->attributes as $value) {
$attributes[] = (string)$value;
$attributes[] = (string) $value;
}

$attributes = implode("\n", $attributes);

$from_name = addslashes($this->getFrom()->getName());
$to_name = addslashes($this->getTo()->getName());
$to_name = addslashes($this->getTo()->getName());

return <<<DOT
"$from_name" -> "$to_name" [
$attributes
"${from_name}" -> "${to_name}" [
${attributes}
]
DOT;
}
Expand Down
3 changes: 1 addition & 2 deletions src/phpDocumentor/GraphViz/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@
*/
class Exception extends \Exception
{

}
}
50 changes: 27 additions & 23 deletions src/phpDocumentor/GraphViz/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
*/
class Graph
{

/** @var string Name of this graph */
protected $name = 'G';

Expand All @@ -45,16 +44,16 @@ class Graph
protected $strict = false;

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

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

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

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

/** @var string The path to execute dot from */
protected $path = '';
Expand Down Expand Up @@ -87,9 +86,11 @@ public static function create($name = 'G', $directional = true)
*/
public function setPath($path)
{
if ($path && $path = realpath($path)) {
$realpath = realpath($path);
if ($path && $path === $realpath) {
$this->path = $path . DIRECTORY_SEPARATOR;
}

return $this;
}

Expand Down Expand Up @@ -131,7 +132,7 @@ public function getName()
*/
public function setType($type)
{
if (!in_array($type, array('digraph', 'graph', 'subgraph'))) {
if (!in_array($type, ['digraph', 'graph', 'subgraph'])) {
throw new \InvalidArgumentException(
'The type for a graph must be either "digraph", "graph" or '
. '"subgraph"'
Expand Down Expand Up @@ -187,16 +188,17 @@ public function isStrict()
* @param string $name Name of the method including get/set
* @param mixed[] $arguments The arguments, should be 1: the value
*
* @return \phpDocumentor\GraphViz\Attribute[]|\phpDocumentor\GraphViz\Graph|null
* @return \phpDocumentor\GraphViz\Attribute|\phpDocumentor\GraphViz\Graph|null
*/
function __call($name, $arguments)
public function __call($name, $arguments)
{
$key = strtolower(substr($name, 3));
if (strtolower(substr($name, 0, 3)) === 'set') {
$this->attributes[$key] = new Attribute($key, $arguments[0]);

return $this;
}

if (strtolower(substr($name, 0, 3)) === 'get') {
return $this->attributes[$key];
}
Expand Down Expand Up @@ -272,7 +274,7 @@ public function setNode(Node $node)
*
* @param string $name Name of the node to find.
*
* @return \phpDocumentor\GraphViz\Node
* @return \phpDocumentor\GraphViz\Node|null
*/
public function findNode($name)
{
Expand Down Expand Up @@ -300,23 +302,22 @@ public function findNode($name)
*
* @return \phpDocumentor\GraphViz\Graph
*/
function __set($name, $value)
public function __set($name, $value)
{
$this->nodes[$name] = $value;
return $this;
}


/**
* Returns the requested node by its name.
*
* @param string $name The name of the node to retrieve.
*
* @see \phpDocumentor\GraphViz\Graph::setNode()
*
* @return \phpDocumentor\GraphViz\Node
* @return \phpDocumentor\GraphViz\Node|null
*/
function __get($name)
public function __get($name)
{
return isset($this->nodes[$name]) ? $this->nodes[$name] : null;
}
Expand Down Expand Up @@ -360,18 +361,18 @@ public function export($type, $filename)

// write the dot file to a temporary file
$tmpfile = tempnam(sys_get_temp_dir(), 'gvz');
file_put_contents($tmpfile, (string)$this);
file_put_contents($tmpfile, (string) $this);

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

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

if ($code != 0) {
if ($code !== 0) {
throw new Exception(
'An error occurred while creating the graph; GraphViz returned: '
. implode(PHP_EOL, $output)
Expand All @@ -392,22 +393,25 @@ public function export($type, $filename)
public function __toString()
{
$elements = array_merge(
$this->graphs, $this->attributes, $this->edges, $this->nodes
$this->graphs,
$this->attributes,
$this->edges,
$this->nodes
);

$attributes = array();
$attributes = [];
foreach ($elements as $value) {
$attributes[] = (string)$value;
$attributes[] = (string) $value;
}

$attributes = implode(PHP_EOL, $attributes);

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

return <<<DOT
{$strict}{$this->getType()} "{$this->getName()}" {
$attributes
${attributes}
}
DOT;
}

}
20 changes: 10 additions & 10 deletions src/phpDocumentor/GraphViz/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@
*/
class Node
{

/** @var string Name for this node */
protected $name = '';

/** @var \phpDocumentor\GraphViz\Attribute[] List of attributes for this node */
protected $attributes = array();
protected $attributes = [];

/**
* Creates a new node with name and optional label.
*
* @param string $name Name of the new node.
* @param string|null $label Optional label text.
*/
function __construct($name, $label = null)
public function __construct($name, $label = null)
{
$this->setName($name);
if ($label !== null) {
Expand Down Expand Up @@ -98,17 +97,17 @@ public function getName()
* @param string $name Method name; either getX or setX is expected.
* @param mixed[] $arguments List of arguments; only 1 is expected for setX.
*
* @return \phpDocumentor\GraphViz\Attribute[]|\phpDocumentor\GraphViz\Node|null
* @return \phpDocumentor\GraphViz\Attribute|\phpDocumentor\GraphViz\Node|null
*/
function __call($name, $arguments)
public function __call($name, $arguments)
{
$key = strtolower(substr($name, 3));
if (strtolower(substr($name, 0, 3)) == 'set') {
if (strtolower(substr($name, 0, 3)) === 'set') {
$this->attributes[$key] = new Attribute($key, $arguments[0]);
return $this;
}

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

Expand All @@ -122,17 +121,18 @@ function __call($name, $arguments)
*/
public function __toString()
{
$attributes = array();
$attributes = [];
foreach ($this->attributes as $value) {
$attributes[] = (string)$value;
$attributes[] = (string) $value;
}

$attributes = implode("\n", $attributes);

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

return <<<DOT
"{$name}" [
$attributes
${attributes}
]
DOT;
}
Expand Down
Loading