Skip to content

Commit

Permalink
Add ArgumentsSet VO.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Jul 14, 2021
1 parent 29fb877 commit cdfd597
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/Generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,20 @@ $list = [
];
```

If you want to reuse existing argument sets from other tasks, you can use the `ArgumentsSet` value object referencing them:

```php
use IdeHelper\Generator\Directive\ExpectedArguments;
use IdeHelper\ValueObject\ArgumentsSet;

$method = '\\' . static::CLASS_FORMAT_HELPER . '::sidebarLink()';
$list = [
ArgumentsSet::create(FormatIconFontAwesome5Task::SET_ICONS_FONTAWESOME),
];
$directive = new ExpectedArguments($method, 1, $list);
```
Just make sure those argument sets are actually available, as this is not checked for you.

##### ExitPoint
This new directive can help to let the IDE know what methods abort the current code flow.
It will show "Unreachable statement" warning and usually highlight the following code in yellow to inform you.
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Directive/RegisterArgumentsSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* \MyClass::REQUIRED
* );
*
* Then it can be used in other places as argumentsSet("mySet").
* Then it can be used in other places as argumentsSet('mySet').
*
* @see https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html#arguments-set
*/
Expand Down
51 changes: 51 additions & 0 deletions src/ValueObject/ArgumentsSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace IdeHelper\ValueObject;

/**
* Helps to use an existing argument set to be used in other directives for DRY code.
*
* Then it can be used in other places as argumentsSet('mySet').
*
* @see https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html#arguments-set
*/
class ArgumentsSet implements ValueObjectInterface {

/**
* @var string
*/
protected $value;

/**
* @param string $value
*/
private function __construct(string $value) {
$this->value = $value;
}

/**
* Creates itself from a string.
*
* @param string $value
*
* @return static
*/
public static function create(string $value) {
return new static($value);
}

/**
* @return string
*/
public function raw(): string {
return $this->value;
}

/**
* @return string
*/
public function __toString(): string {
return 'argumentsSet(\'' . $this->value . '\')';
}

}

0 comments on commit cdfd597

Please sign in to comment.