Add new "find" filter

by @smnandre

Some issues have been detected in this pull request

Issues that can be fixed by applying a patch

Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:

curl https://fabbot.io/patch/twigphp/Twig/3963/b6f0347bc05e58a5275345ea4638c0e62d934763/cs.diff | patch -p0
diff -ru src/Extension/CoreExtension.php src/Extension/CoreExtension.php
--- src/Extension/CoreExtension.php	2024-02-10 09:36:15.915878535 +0000
+++ src/Extension/CoreExtension.php	2024-02-10 09:36:21.407064888 +0000
@@ -84,7 +84,7 @@
 {
     private $dateFormats = ['F j, Y H:i', '%d days'];
     private $numberFormat = [0, '.', ','];
-    private $timezone = null;
+    private $timezone;
 
     /**
      * Sets the default format to be used by the date filter.
@@ -458,7 +458,6 @@
      * Returns a formatted string.
      *
      * @param string|null $format
-     * @param ...$values
      *
      * @return string
      *
@@ -543,7 +542,7 @@
     public static function replaceFilter($str, $from)
     {
         if (!is_iterable($from)) {
-            throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from)));
+            throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? $from::class : \gettype($from)));
         }
 
         return strtr($str ?? '', self::toArray($from));
@@ -1451,10 +1450,10 @@
     {
         if (null !== $object) {
             if ('class' === $constant) {
-                return \get_class($object);
+                return $object::class;
             }
 
-            $constant = \get_class($object).'::'.$constant;
+            $constant = $object::class.'::'.$constant;
         }
 
         if (!\defined($constant)) {
@@ -1485,7 +1484,7 @@
                 return true;
             }
 
-            $constant = \get_class($object).'::'.$constant;
+            $constant = $object::class.'::'.$constant;
         }
 
         return \defined($constant);
@@ -1505,7 +1504,7 @@
     public static function arrayBatch($items, $size, $fill = null, $preserveKeys = true)
     {
         if (!is_iterable($items)) {
-            throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items)));
+            throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? $items::class : \gettype($items)));
         }
 
         $size = ceil($size);
@@ -1567,9 +1566,9 @@
                 }
 
                 if ($object instanceof \ArrayAccess) {
-                    $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object));
+                    $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, $object::class);
                 } elseif (\is_object($object)) {
-                    $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object));
+                    $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, $object::class);
                 } elseif (\is_array($object)) {
                     if (empty($object)) {
                         $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem);
@@ -1633,7 +1632,7 @@
 
         static $cache = [];
 
-        $class = \get_class($object);
+        $class = $object::class;
 
         // object method
         // precedence: getXxx() > isXxx() > hasXxx()
@@ -1754,7 +1753,7 @@
     public static function arrayFilter(Environment $env, $array, $arrow)
     {
         if (!is_iterable($array)) {
-            throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array)));
+            throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? $array::class : \gettype($array)));
         }
 
         self::checkArrowInSandbox($env, $arrow, 'filter', 'filter');

0
Common Typos

0
File Permissions

0
Merge Commits

Issues that can be fixed by applying a patch

Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:

curl https://fabbot.io/patch/twigphp/Twig/3963/b6f0347bc05e58a5275345ea4638c0e62d934763/exception_messages.diff | patch -p0
diff -ru src/Extension/CoreExtension.php src/Extension/CoreExtension.php
--- src/Extension/CoreExtension.php	2024-02-10 09:36:15.915878535 +0000
+++ src/Extension/CoreExtension.php	2024-02-10 09:36:22.155090273 +0000
@@ -330,7 +330,7 @@
         }
 
         if (!\count($values)) {
-            throw new RuntimeError('The "cycle" function does not work on empty arrays');
+            throw new RuntimeError('The "cycle" function does not work on empty arrays.');
         }
 
         return $values[$position % \count($values)];
@@ -1067,7 +1067,7 @@
     public static function matches(string $regexp, ?string $str)
     {
         set_error_handler(function ($t, $m) use ($regexp) {
-            throw new RuntimeError(sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
+            throw new RuntimeError(sprintf('Regexp "%s" passed to "matches" is not valid.', $regexp).substr($m, 12));
         });
         try {
             return preg_match($regexp, $str ?? '');
@@ -1855,7 +1855,7 @@
     public static function checkArrowInSandbox(Environment $env, $arrow, $thing, $type)
     {
         if (!$arrow instanceof \Closure && $env->hasExtension('\Twig\Extension\SandboxExtension') && $env->getExtension('\Twig\Extension\SandboxExtension')->isSandboxed()) {
-            throw new RuntimeError(sprintf('The callable passed to the "%s" %s must be a Closure in sandbox mode.', $thing, $type));
+            throw new RuntimeError(sprintf('The callable passed to the "%s" "%s" must be a Closure in sandbox mode.', $thing, $type));
         }
     }
 }

0
Usage of void in test files

0
Use ::class whenever possible

0
Deprecation Messages