11<?php
2+
23declare (strict_types=1 );
34
45namespace Sserbin \TwigLinter ;
1112class StubEnvironment extends Environment
1213{
1314 /**
14- * {@inheritdoc}
15+ * @param string $name
16+ * @psalm-suppress ImplementedReturnTypeMismatch
1517 */
16- public function getFilter ($ name )
18+ public function getFilter ($ name ): ? TwigFilter
1719 {
1820 /**
1921 * @var string[]
@@ -24,7 +26,7 @@ public function getFilter($name)
2426
2527 if ($ isDefault ) { // don't attempt to stub twig's builtin filter
2628 /** @psalm-suppress InternalMethod */
27- return parent ::getFilter ($ name );
29+ return parent ::getFilter ($ name ) ?: null ;
2830 }
2931
3032 return new TwigFilter ((string )$ name , $ this ->noop (), [
@@ -33,9 +35,10 @@ public function getFilter($name)
3335 }
3436
3537 /**
36- * {@inheritdoc}
38+ * @param string $name
39+ * @psalm-suppress ImplementedReturnTypeMismatch
3740 */
38- public function getFunction ($ name )
41+ public function getFunction ($ name ): ? TwigFunction
3942 {
4043 /**
4144 * @var string[]
@@ -46,7 +49,7 @@ public function getFunction($name)
4649
4750 if ($ isDefault ) { // don't attempt to stub twig's builtin function
4851 /** @psalm-suppress InternalMethod */
49- return parent ::getFunction ($ name );
52+ return parent ::getFunction ($ name ) ?: null ;
5053 }
5154
5255 return new TwigFunction ((string )$ name , $ this ->noop (), [
@@ -55,9 +58,10 @@ public function getFunction($name)
5558 }
5659
5760 /**
58- * {@inheritdoc}
61+ * @param string $name
62+ * @psalm-suppress ImplementedReturnTypeMismatch
5963 */
60- public function getTest ($ name )
64+ public function getTest ($ name ): ? TwigTest
6165 {
6266 /**
6367 * @var string[]
@@ -68,7 +72,16 @@ public function getTest($name)
6872
6973 if ($ isDefault ) { // don't attempt to stub twig's builtin test
7074 /** @psalm-suppress InternalMethod */
71- return parent ::getTest ($ name );
75+ $ parentTest = parent ::getTest ($ name );
76+
77+ if ($ parentTest instanceof TwigTest) {
78+ return $ parentTest ;
79+ }
80+
81+ // In twig 2.x this can return `false`.
82+ // Lets just force it here as null because
83+ // of the added typehint for Twig 3.x
84+ return null ;
7285 }
7386
7487 return new TwigTest ((string )$ name , $ this ->noop (), [
@@ -80,13 +93,15 @@ private function noop(): callable
8093 {
8194 /**
8295 * @param mixed $_
96+ * @param array $arg
8397 */
8498 return function ($ _ = null , array $ arg = []): void {
8599 };
86100 }
87101
88102 /**
89103 * @param string[] $list
104+ * @return bool
90105 */
91106 private function listContainsSubstring (array $ list , string $ needle ): bool
92107 {
0 commit comments