File tree Expand file tree Collapse file tree
tests/data/type-inference Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -128,3 +128,23 @@ This extension provides precise return type for the static `getSharedInstance()`
128128> additionalServices:
129129> - Acme\Blog\Config\Services
130130> ```
131+
132+ # ## CacheFactoryGetHandlerReturnTypeExtension
133+
134+ **Class:** `CodeIgniter\PHPStan\Type\CacheFactoryGetHandlerReturnTypeExtension`
135+
136+ This extension provides precise return types for the static `CacheFactory::getHandler()` method, resolving
137+ the handler class from the `validHandlers` of the passed `Config\Cache` and the requested handler and backup
138+ handler names.
139+
140+ > [!NOTE]
141+ > **Configuration:**
142+ >
143+ > By default, only the resolved primary handler is used as the return type. To also include the backup handler
144+ > in the inferred return type, enable:
145+ >
146+ > ```yml
147+ > parameters:
148+ > codeigniter:
149+ > addBackupHandlerAsReturnType: true
150+ > ```
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ parameters:
1010 - CodeIgniter\Config\
1111 additionalModelNamespaces : []
1212 additionalServices : []
13+ addBackupHandlerAsReturnType : false
1314 checkArgumentTypeOfConfig : true
1415 checkArgumentTypeOfModel : true
1516 checkArgumentTypeOfFactories : true
@@ -19,6 +20,7 @@ parametersSchema:
1920 additionalConfigNamespaces : listOf (string ())
2021 additionalModelNamespaces : listOf (string ())
2122 additionalServices : listOf (string ())
23+ addBackupHandlerAsReturnType : bool ()
2224 checkArgumentTypeOfConfig : bool ()
2325 checkArgumentTypeOfModel : bool ()
2426 checkArgumentTypeOfFactories : bool ()
@@ -86,6 +88,13 @@ services:
8688 tags :
8789 - phpstan.broker.dynamicStaticMethodReturnTypeExtension
8890
91+ -
92+ class : CodeIgniter\PHPStan\Type\CacheFactoryGetHandlerReturnTypeExtension
93+ arguments :
94+ addBackupHandlerAsReturnType : %codeigniter.addBackupHandlerAsReturnType%
95+ tags :
96+ - phpstan.broker.dynamicStaticMethodReturnTypeExtension
97+
8998 -
9099 class : CodeIgniter\PHPStan\Rules\Functions\FactoriesFunctionArgumentTypeRule
91100 arguments :
Original file line number Diff line number Diff line change 1111 * the LICENSE file that was distributed with this source code.
1212 */
1313
14- namespace CodeIgniter \PHPStan \Tests \Fixtures \ Type ;
14+ namespace CodeIgniter \PHPStan \Tests \Type ;
1515
1616use CodeIgniter \Cache \CacheFactory ;
17+ use CodeIgniter \Cache \Handlers \ApcuHandler ;
1718use CodeIgniter \Cache \Handlers \BaseHandler ;
1819use CodeIgniter \Cache \Handlers \DummyHandler ;
1920use CodeIgniter \Cache \Handlers \FileHandler ;
2930assertType (FileHandler::class, CacheFactory::getHandler ($ cache ));
3031assertType (FileHandler::class, CacheFactory::getHandler ($ cache , null ));
3132
33+ assertType (ApcuHandler::class, CacheFactory::getHandler ($ cache , 'apcu ' ));
3234assertType (DummyHandler::class, CacheFactory::getHandler ($ cache , 'dummy ' ));
3335assertType (FileHandler::class, CacheFactory::getHandler ($ cache , 'file ' ));
3436assertType (MemcachedHandler::class, CacheFactory::getHandler ($ cache , 'memcached ' ));
You can’t perform that action at this time.
0 commit comments