3434 */
3535class 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" '
@@ -189,14 +190,15 @@ public function isStrict()
189190 *
190191 * @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 }
@@ -300,13 +302,12 @@ 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 *
@@ -316,7 +317,7 @@ function __set($name, $value)
316317 *
317318 * @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}
410415DOT ;
411416 }
412-
413417}
0 commit comments