Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[templates] add shuffle filter #3966

Open
wants to merge 4 commits into
base: 3.x
Choose a base branch
from

Conversation

Sarah-eit
Copy link

New feature :

The filter displays the values in an array at random.
I'm open of any feedback.

src/Extension/CoreExtension.php Outdated Show resolved Hide resolved
src/Extension/CoreExtension.php Outdated Show resolved Hide resolved
doc/filters/shuffle.rst Outdated Show resolved Hide resolved
@Sarah-eit Sarah-eit marked this pull request as ready for review January 31, 2024 11:10
2
6
3
3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests don't really test anything, right?

@@ -222,6 +222,7 @@ public function getFilters(): array

// string/array filters
new TwigFilter('reverse', [self::class, 'reverseFilter'], ['needs_environment' => true]),
new TwigFilter('shuffle', [self::class, 'shuffleFilter'], ['needs_environment' => true]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new TwigFilter('shuffle', [self::class, 'shuffleFilter'], ['needs_environment' => true]),
new TwigFilter('shuffle', [self::class, 'shuffleFilter'], ['needs_charset' => true]),

*
* @internal
*/
public static function shuffleFilter(Environment $env, mixed $item): mixed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static function shuffleFilter(Environment $env, mixed $item): mixed
public static function shuffleFilter(string $charset $item): mixed

For $item, we can be more precise than mixed o the phpdocs.

public static function shuffleFilter(Environment $env, mixed $item): mixed
{
if (\is_string($item)) {
$charset = $env->getCharset();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed

@@ -920,6 +921,38 @@ public static function reverseFilter(Environment $env, $item, $preserveKeys = fa
return $string;
}

/**
* Shuffle an array, a \Traversable instance, or a string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Shuffle an array, a \Traversable instance, or a string.
* Shuffles an array, a \Traversable instance, or a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants