Skip to content

Commit

Permalink
Other text functions now returns '[empty]' instead of ''
Browse files Browse the repository at this point in the history
  • Loading branch information
neveldo committed Mar 11, 2020
1 parent fbdc630 commit 952d2da
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# ChangeLog
Change log for TextGenerator

## 1.6.0 - February 11, 2020
- Other text functions now returns '[empty]' instead of ''

## 1.5.0 - February 11, 2020
- ProbabilityRandomFunction and RandomFunction now returns '[empty]'' instead of '' if there is no valid choices as arguments.
- ProbabilityRandomFunction and RandomFunction now returns '[empty]' instead of '' if there is no valid choices as arguments.

## 1.4.0 - February 11, 2020
- ExprFunction now returns [empty] if the expression thrown an Error or an Exception.
Expand Down
5 changes: 3 additions & 2 deletions src/TextGenerator/TextFunction/ChooseFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Neveldo\TextGenerator\TextFunction;

use Neveldo\TextGenerator\Tag\TagReplacer;
use Neveldo\TextGenerator\Tag\TagReplacerInterface;

/**
* Class ChooseFunction
* 'choose' function : returns one item from the function arguments
* Examples :
* #random{2|one|two|three} will output 'two'
* #choose{2|one|two|three} will output 'two'
*
* @package Neveldo\TextGenerator\TextFunction
*/
Expand Down Expand Up @@ -51,7 +52,7 @@ public function execute(array $arguments, array $originalArguments)
return $arguments[$index];
}

return '';
return TagReplacer::EMPTY_TAG;
}

}
12 changes: 2 additions & 10 deletions src/TextGenerator/TextFunction/CoalesceFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@

namespace Neveldo\TextGenerator\TextFunction;

use Neveldo\TextGenerator\Tag\TagReplacer;
use Neveldo\TextGenerator\Tag\TagReplacerInterface;

/**
* Class ChooseFunction
* 'choose' function : returns one item from the function arguments
* Examples :
* #random{2|one|two|three} will output 'two'
*
* @package Neveldo\TextGenerator\TextFunction
*/

/**
* Class CoalesceFunction
* 'coalesce' function : return the first non empty argument
Expand Down Expand Up @@ -51,7 +43,7 @@ public function execute(array $arguments, array $originalArguments)
}
}

return '';
return TagReplacer::EMPTY_TAG;
}

}
10 changes: 8 additions & 2 deletions src/TextGenerator/TextFunction/FilterFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Neveldo\TextGenerator\TextFunction;

use Neveldo\TextGenerator\Tag\TagReplacer;
use Neveldo\TextGenerator\Tag\TagReplacerInterface;

/**
Expand Down Expand Up @@ -190,9 +191,14 @@ public function execute(array $arguments, array $originalArguments)
}

if (is_callable($filter['function'])) {
return call_user_func_array($filter['function'], $arguments);
try {
return call_user_func_array($filter['function'], $arguments);
} catch (\Exception $e) {
return TagReplacer::EMPTY_TAG;
}
}
return '';

return TagReplacer::EMPTY_TAG;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/TextGenerator/TextFunction/IfFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Neveldo\TextGenerator\TextFunction;

use Neveldo\TextGenerator\Tag\TagReplacer;
use Neveldo\TextGenerator\Tag\TagReplacerInterface;
use Neveldo\TextGenerator\ExpressionLanguage\ExpressionLanguage;

Expand Down Expand Up @@ -57,7 +58,7 @@ public function execute(array $arguments, array $originalArguments)
} else if (isset($arguments[2])) {
return $arguments[2];
}
return '';
return TagReplacer::EMPTY_TAG;
}

}
3 changes: 2 additions & 1 deletion src/TextGenerator/TextFunction/LoopFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Neveldo\TextGenerator\TextFunction;

use Neveldo\TextGenerator\Tag\TagReplacer;
use Neveldo\TextGenerator\Tag\TagReplacerInterface;

/**
Expand Down Expand Up @@ -54,7 +55,7 @@ public function execute(array $arguments, array $originalArguments)
// Parse argument 0 : the tag that contain the data to loop on
$loopData = $this->tagReplacer->getTag($originalArguments[0]);
if (!is_array($loopData)) {
return '';
return TagReplacer::EMPTY_TAG;
}

$loopStrings = [];
Expand Down

0 comments on commit 952d2da

Please sign in to comment.