コード例 #1
0
ファイル: Graph.php プロジェクト: afilatov1989/php_kata
 /**
  * Adds vertex to a graph. If vertex with the same id already exists,
  * throws and exception
  * @param Vertex $vertex
  * @throws \Exception
  */
 public function addVertex(Vertex $vertex)
 {
     $id = $vertex->getId();
     if (array_key_exists($id, $this->vertices)) {
         throw new \Exception('Vertex with ID="' . $id . '" already exists');
     }
     $this->vertices[$id] = $vertex;
 }