1111use Fhaculty \Graph \Edge \Base ;
1212use Fhaculty \Graph \Graph ;
1313use Fhaculty \Graph \Vertex ;
14- use Graphp \Algorithms \ShortestPath \Dijkstra ;
1514
1615/**
1716 * This class can analyze a database model.
@@ -47,8 +46,8 @@ class SchemaAnalyzer
4746
4847 /**
4948 * @param AbstractSchemaManager $schemaManager
50- * @param Cache|null $cache The Doctrine cache service to use to cache results (optional)
51- * @param string|null $schemaCacheKey The unique identifier for the schema manager. Compulsory if cache is set.
49+ * @param Cache|null $cache The Doctrine cache service to use to cache results (optional)
50+ * @param string|null $schemaCacheKey The unique identifier for the schema manager. Compulsory if cache is set.
5251 */
5352 public function __construct (AbstractSchemaManager $ schemaManager , Cache $ cache = null , $ schemaCacheKey = null )
5453 {
@@ -66,7 +65,7 @@ public function __construct(AbstractSchemaManager $schemaManager, Cache $cache =
6665
6766 /**
6867 * Detect all junctions tables in the schema.
69- * A table is a junction table if:
68+ * A table is a junction table if:.
7069 *
7170 * - it has exactly 2 foreign keys
7271 * - it has only 2 columns (or 3 columns if the third one is an autoincremented primary key).
@@ -76,18 +75,19 @@ public function __construct(AbstractSchemaManager $schemaManager, Cache $cache =
7675 */
7776 public function detectJunctionTables ()
7877 {
79- $ junctionTablesKey = $ this ->cachePrefix ." _junctiontables " ;
78+ $ junctionTablesKey = $ this ->cachePrefix .' _junctiontables ' ;
8079 $ junctionTables = $ this ->cache ->fetch ($ junctionTablesKey );
8180 if ($ junctionTables === false ) {
8281 $ junctionTables = array_filter ($ this ->getSchema ()->getTables (), [$ this , 'isJunctionTable ' ]);
8382 $ this ->cache ->save ($ junctionTablesKey , $ junctionTables );
8483 }
84+
8585 return $ junctionTables ;
8686 }
8787
8888 /**
8989 * Returns true if $table is a junction table.
90- * I.e:
90+ * I.e:.
9191 *
9292 * - it must have exactly 2 foreign keys
9393 * - it must have only 2 columns (or 3 columns if the third one is an autoincremented primary key).
@@ -147,17 +147,20 @@ private function isJunctionTable(Table $table)
147147 *
148148 * @param string $fromTable
149149 * @param string $toTable
150+ *
150151 * @return \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
152+ *
151153 * @throws SchemaAnalyzerException
152154 */
153155 public function getShortestPath ($ fromTable , $ toTable )
154156 {
155- $ cacheKey = $ this ->cachePrefix ." _shortest_ " .$ fromTable ." ``` " .$ toTable ;
157+ $ cacheKey = $ this ->cachePrefix .' _shortest_ ' .$ fromTable .' ``` ' .$ toTable ;
156158 $ path = $ this ->cache ->fetch ($ cacheKey );
157159 if ($ path === false ) {
158160 $ path = $ this ->getShortestPathWithoutCache ($ fromTable , $ toTable );
159161 $ this ->cache ->save ($ cacheKey , $ path );
160162 }
163+
161164 return $ path ;
162165 }
163166
@@ -166,7 +169,9 @@ public function getShortestPath($fromTable, $toTable)
166169 *
167170 * @param string $fromTable
168171 * @param string $toTable
172+ *
169173 * @return \Doctrine\DBAL\Schema\ForeignKeyConstraint[]
174+ *
170175 * @throws SchemaAnalyzerException
171176 */
172177 private function getShortestPathWithoutCache ($ fromTable , $ toTable )
@@ -255,33 +260,37 @@ private function buildSchemaGraph()
255260 }
256261
257262 /**
258- * Returns the schema (from the schema manager or the cache if needed)
263+ * Returns the schema (from the schema manager or the cache if needed).
264+ *
259265 * @return Schema
260266 */
261- private function getSchema () {
267+ private function getSchema ()
268+ {
262269 if ($ this ->schema === null ) {
263- $ schemaKey = $ this ->cachePrefix ." _schema " ;
270+ $ schemaKey = $ this ->cachePrefix .' _schema ' ;
264271 $ this ->schema = $ this ->cache ->fetch ($ schemaKey );
265272 if (empty ($ this ->schema )) {
266273 $ this ->schema = $ this ->schemaManager ->createSchema ();
267274 $ this ->cache ->save ($ schemaKey , $ this ->schema );
268275 }
269276 }
277+
270278 return $ this ->schema ;
271279 }
272280
273281 /**
274282 * Returns the full exception message when an ambiguity arises.
275283 *
276284 * @param Base[][] $paths
277- * @param Vertex $startVertex
285+ * @param Vertex $startVertex
278286 */
279- private function getAmbiguityExceptionMessage (array $ paths , Vertex $ startVertex , Vertex $ endVertex ) {
287+ private function getAmbiguityExceptionMessage (array $ paths , Vertex $ startVertex , Vertex $ endVertex )
288+ {
280289 $ textPaths = [];
281290 $ i = 1 ;
282291 foreach ($ paths as $ path ) {
283- $ textPaths [] = " Path " .$ i ." : " .$ this ->getTextualPath ($ path , $ startVertex );
284- $ i ++ ;
292+ $ textPaths [] = ' Path ' .$ i .' : ' .$ this ->getTextualPath ($ path , $ startVertex );
293+ ++ $ i ;
285294 }
286295
287296 $ msg = sprintf ("There are many possible shortest paths between table '%s' and table '%s' \n\n" ,
@@ -298,7 +307,8 @@ private function getAmbiguityExceptionMessage(array $paths, Vertex $startVertex,
298307 * @param Base[] $path
299308 * @param Vertex $startVertex
300309 */
301- private function getTextualPath (array $ path , Vertex $ startVertex ) {
310+ private function getTextualPath (array $ path , Vertex $ startVertex )
311+ {
302312 $ currentVertex = $ startVertex ;
303313 $ currentTable = $ currentVertex ->getId ();
304314
@@ -317,9 +327,9 @@ private function getTextualPath(array $path, Vertex $startVertex) {
317327
318328 $ columns = implode (', ' , $ fk ->getLocalColumns ());
319329
320- $ textPath .= " " .(!$ isForward? " < " : "" );
321- $ textPath .= " --( " .$ columns ." )-- " ;
322- $ textPath .= ($ isForward? " > " : "" ). " " ;
330+ $ textPath .= ' ' .(!$ isForward ? ' < ' : '' );
331+ $ textPath .= ' --( ' .$ columns .' )-- ' ;
332+ $ textPath .= ($ isForward ? ' > ' : '' ). ' ' ;
323333 $ textPath .= $ currentTable ;
324334 } elseif ($ junctionTable = $ edge ->getAttribute ('junction ' )) {
325335 /* @var $junctionTable Table */
@@ -331,7 +341,7 @@ private function getTextualPath(array $path, Vertex $startVertex) {
331341 } else {
332342 $ currentTable = $ fk ->getForeignTableName ();
333343 }
334- $ textPath .= " <=( " .$ junctionTable ->getName ()." )=> " .$ currentTable ;
344+ $ textPath .= ' <=( ' .$ junctionTable ->getName ().' )=> ' .$ currentTable ;
335345 } else {
336346 // @codeCoverageIgnoreStart
337347 throw new SchemaAnalyzerException ('Unexpected edge. We should have a fk or a junction attribute. ' );
0 commit comments