Skip to content

Commit 39cfb3f

Browse files
committed
Move directory parameter to constructor
1 parent 1e21504 commit 39cfb3f

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

bin/graph-composer

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ require_once __DIR__ . '/../vendor/autoload.php';
66
// directory to scan
77
$dir = isset($argv[1]) ? $argv[1] : '.';
88

9-
$graph = new Clue\GraphComposer();
10-
$graph->displayGraph($dir);
9+
$graph = new Clue\GraphComposer($dir);
10+
$graph->displayGraph();

src/Clue/GraphComposer.php

+17-8
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,28 @@ class GraphComposer
2828
'style' => 'dashed'
2929
);
3030

31+
private $dependencyGraph;
32+
3133
/**
3234
*
3335
* @param string $dir
34-
* @return \Fhaculty\Graph\Graph
3536
*/
36-
public function createGraph($dir)
37+
public function __construct($dir)
3738
{
3839
$analyzer = new \JMS\Composer\DependencyAnalyzer();
39-
$dependencyGraph = $analyzer->analyze($dir);
40-
40+
$this->dependencyGraph = $analyzer->analyze($dir);
41+
}
42+
43+
/**
44+
*
45+
* @param string $dir
46+
* @return \Fhaculty\Graph\Graph
47+
*/
48+
public function createGraph()
49+
{
4150
$graph = new Graph();
4251

43-
foreach ($dependencyGraph->getPackages() as $package) {
52+
foreach ($this->dependencyGraph->getPackages() as $package) {
4453
$name = $package->getName();
4554
$start = $graph->createVertex($name, true);
4655

@@ -65,14 +74,14 @@ public function createGraph($dir)
6574
}
6675
}
6776

68-
$graph->getVertex($dependencyGraph->getRootPackage()->getName())->setLayout($this->layoutVertexRoot);
77+
$graph->getVertex($this->dependencyGraph->getRootPackage()->getName())->setLayout($this->layoutVertexRoot);
6978

7079
return $graph;
7180
}
7281

73-
public function displayGraph($dir)
82+
public function displayGraph()
7483
{
75-
$graph = $this->createGraph($dir);
84+
$graph = $this->createGraph();
7685

7786
$graphviz = new GraphViz($graph);
7887
$graphviz->setFormat('svg');

tests/GraphComposerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public function testCreateGraph()
88
{
99
$dir = __DIR__ . '/../';
1010

11-
$graphComposer = new Clue\GraphComposer();
12-
$graph = $graphComposer->createGraph($dir);
11+
$graphComposer = new Clue\GraphComposer($dir);
12+
$graph = $graphComposer->createGraph();
1313

1414
$this->assertInstanceOf('Fhaculty\Graph\Graph', $graph);
1515
$this->assertTrue($graph->getNumberOfVertices() > 0);

0 commit comments

Comments
 (0)