These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Sonata Project package. |
||
7 | * |
||
8 | * (c) Thomas Rabaix <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Sonata\AdminBundle\Twig\Extension; |
||
15 | |||
16 | use Symfony\Component\String\UnicodeString as SymfonyUnicodeString; |
||
17 | use Twig\Environment; |
||
18 | use Twig\Extension\AbstractExtension; |
||
19 | use Twig\Extensions\TextExtension; |
||
20 | use Twig\TwigFilter; |
||
21 | |||
22 | /** |
||
23 | * NEXT_MAJOR: Remove this class. |
||
24 | * |
||
25 | * Decorates `Twig\Extra\String\StringExtension` in order to provide the `$cut` |
||
26 | * argument for `Symfony\Component\String\UnicodeString::truncate()`. |
||
27 | * This class must be removed when the component ships this feature. |
||
28 | * |
||
29 | * @internal |
||
30 | * |
||
31 | * @see https://github.com/symfony/symfony/pull/35649 |
||
32 | * @deprecated since sonata-project/admin-bundle 3.69, to be removed in 4.0. |
||
33 | * |
||
34 | * @author Javier Spagnoletti <[email protected]> |
||
35 | */ |
||
36 | final class StringExtension extends AbstractExtension |
||
37 | { |
||
38 | /** |
||
39 | * @var AbstractExtension|null |
||
40 | */ |
||
41 | private $legacyExtension; |
||
42 | |||
43 | public function __construct(?AbstractExtension $legacyExtension = null) |
||
44 | { |
||
45 | if (null !== $legacyExtension |
||
46 | && !$legacyExtension instanceof TextExtension |
||
0 ignored issues
–
show
|
|||
47 | && !$legacyExtension instanceof DeprecatedTextExtension |
||
48 | ) { |
||
49 | throw new \TypeError(sprintf( |
||
50 | 'Argument 1 passed to %s::__construct() must be instance of %s or %s or null', |
||
51 | self::class, |
||
52 | TextExtension::class, |
||
53 | DeprecatedTextExtension::class |
||
54 | )); |
||
55 | } |
||
56 | |||
57 | $this->legacyExtension = $legacyExtension; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return TwigFilter[] |
||
62 | */ |
||
63 | public function getFilters(): array |
||
64 | { |
||
65 | return [ |
||
66 | new TwigFilter('sonata_truncate', [$this, 'deprecatedTruncate'], ['needs_environment' => true]), |
||
67 | ]; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return SymfonyUnicodeString|string |
||
72 | */ |
||
73 | public function deprecatedTruncate(Environment $env, ?string $text, int $length = 30, bool $preserve = false, string $ellipsis = '...') |
||
74 | { |
||
75 | @trigger_error( |
||
76 | 'The "sonata_truncate" twig filter is deprecated' |
||
77 | .' since sonata-project/admin-bundle 3.69 and will be removed in 4.0. Use "u.truncate" instead.', |
||
78 | E_USER_DEPRECATED |
||
79 | ); |
||
80 | |||
81 | if ($this->legacyExtension instanceof TextExtension) { |
||
0 ignored issues
–
show
The class
Twig\Extensions\TextExtension does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed.
Loading history...
|
|||
82 | return twig_truncate_filter($env, $text, $length, $preserve, $ellipsis); |
||
83 | } elseif ($this->legacyExtension instanceof DeprecatedTextExtension) { |
||
84 | return $this->legacyExtension->twigTruncateFilter($env, $text, $length, $preserve, $ellipsis); |
||
85 | } |
||
86 | |||
87 | return $this->legacyTruncteWithUnicodeString($text, $length, $preserve, $ellipsis); |
||
88 | } |
||
89 | |||
90 | public function legacyTruncteWithUnicodeString(?string $text, int $length = 30, bool $preserve = false, string $ellipsis = '...'): SymfonyUnicodeString |
||
91 | { |
||
92 | return (new SymfonyUnicodeString($text ?? ''))->truncate($length, $ellipsis, $preserve); |
||
93 | } |
||
94 | } |
||
95 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.