Skip to content

Commit

Permalink
Merge pull request #91 from jose-ba/main
Browse files Browse the repository at this point in the history
fix: allow paths with hyphens
  • Loading branch information
smeghead authored Dec 10, 2024
2 parents f890e39 + e86ad05 commit 6ad67c4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Php/PhpClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getLogicalName(): string
*/
public function getClassNameAlias(): string
{
return str_replace(['.', '[', ']'], '_', $this->getLogicalName());
return str_replace(['-', '.', '[', ']'], ['', '_', '_', '_'], $this->getLogicalName());
}

public function getClassType(): PhpType
Expand Down
31 changes: 31 additions & 0 deletions test/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,37 @@ class "Name" as product_Name
EOS;
$this->assertSame($expected, implode(PHP_EOL, $rel->dump()), 'output PlantUML script.');
}

public function testDump_paths_with_hyphens_To_avoid_PlantUML_errors(): void
{
$directory = sprintf('%s/paths-with-hyphens', $this->fixtureDir);
$options = new Options([
'disable-class-properties' => true,
'disable-class-methods' => true,
]);
$files = [
'product-with-hyphens/Product.php',
'product-with-hyphens/Price.php',
'product-with-hyphens/Name.php',
];

$rel = $this->getRelation($files, $directory, $options);

$expected = <<<EOS
@startuml class-diagram
package product-with-hyphens as product-with-hyphens {
class "Product" as productwithhyphens_Product
class "Price" as productwithhyphens_Price
class "Name" as productwithhyphens_Name
}
productwithhyphens_Product ..> productwithhyphens_Name
productwithhyphens_Product ..> productwithhyphens_Price
productwithhyphens_Product ..> productwithhyphens_Product
@enduml
EOS;
$this->assertSame($expected, implode(PHP_EOL, $rel->dump()), 'output PlantUML script.');
}

public function testDumpPackage1(): void
{
$directory = sprintf('%s/no-namespace', $this->fixtureDir);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
class Name {
private string $name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
use PhpParse\PhpParser;

class Price {
private int $price;
}
10 changes: 10 additions & 0 deletions test/fixtures/paths-with-hyphens/product-with-hyphens/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class Product {
private Name $name;
private Price $price;

/** @return Product product */
public function method1(string $param1): Product {
}
}

0 comments on commit 6ad67c4

Please sign in to comment.