Skip to content

Commit 98ab2b1

Browse files
authored
Update usage doc (#11)
* add better usage doc * add to bundles.php tipp * * fix to command because of incompatibility * fix for fieldDef handling
1 parent 8f356f3 commit 98ab2b1

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ Before you can use the Bundle, you need to add the git repository to your compos
1313
composer require "mike4git/umlgeneration-bundle"
1414
```
1515

16+
and add it to your bundles.php:
17+
18+
```php
19+
<?php declare(strict_types=1);
20+
21+
return [
22+
// mostly dev environment is enough
23+
\UMLGenerationBundle\UMLGenerationBundle::class => ['dev' => true],
24+
];
25+
```
26+
1627
Additionally, you'll have to install GraphViz (`dot` executable).
1728
Users of Debian/Ubuntu-based distributions may simply invoke:
1829

@@ -38,6 +49,7 @@ Note that this will generate a myDotfileName.dot file
3849
```bash
3950
$ dot -Tsvg myDotfileName.dot -o image.svg
4051
```
52+
4153
After that you should see something like this:
4254

4355
![Sample UML class diagram](doc/images/result.png)

src/Command/UMLGenerationCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class UMLGenerationCommand extends AbstractCommand
1717
private const COMMAND_NAME = 'uml:generate';
1818

1919
public function __construct(
20-
string $name = null,
2120
private ClassDefinitionsRepositoryInterface $classDefinitionsRepository,
2221
private ClassDefinition2UMLService $classDefinition2UMLService,
2322
private PrinterService $printerService,
23+
string $name = null,
2424
) {
2525
parent::__construct($name);
2626
}

src/Service/ClassDefinition2UMLService.php

+15-13
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,22 @@ public function getClasses(): array
106106
private function addRelation(mixed $fieldDefinition, Relation $relation, ClassDefinition $classDefinition): void
107107
{
108108
// TODO Check cases where $fieldDefinition->getClasses() has more than one item
109-
/** @var string $class */
110-
$class = $fieldDefinition->getClasses()[0]['classes'];
111-
$relation->setSourceType($classDefinition->getName() ?? self::UNKNOWN)
112-
->setTargetType($class)
113-
->setSourceRolename($fieldDefinition->getTitle())
114-
->setMinimum($fieldDefinition->getMandatory() ? 1 : 0);
115-
116-
$relationsKey = sprintf('%s.%s - %s', $relation->getSourceType(), $fieldDefinition->getName(), $relation->getTargetType());
117-
118-
// if relation already exists it must be bidirectional
119-
if (\array_key_exists($relationsKey, $this->relations)) {
120-
$relation->setBidirectional(true);
109+
if (!empty($fieldDefinition->getClasses())) {
110+
/** @var string $class */
111+
$class = $fieldDefinition->getClasses()[0]['classes'];
112+
$relation->setSourceType($classDefinition->getName() ?? self::UNKNOWN)
113+
->setTargetType($class)
114+
->setSourceRolename($fieldDefinition->getTitle())
115+
->setMinimum($fieldDefinition->getMandatory() ? 1 : 0);
116+
117+
$relationsKey = sprintf('%s.%s - %s', $relation->getSourceType(), $fieldDefinition->getName(), $relation->getTargetType());
118+
119+
// if relation already exists it must be bidirectional
120+
if (\array_key_exists($relationsKey, $this->relations)) {
121+
$relation->setBidirectional(true);
122+
}
123+
$this->relations[$relationsKey] = $relation;
121124
}
122-
$this->relations[$relationsKey] = $relation;
123125
}
124126

125127
private function addReverseRelation(ClassDefinition\Data\ReverseObjectRelation $fieldDefinition, Relation $relation, ClassDefinition $classDefinition): void

0 commit comments

Comments
 (0)