[ticket/12631] Some more cleanup and type hints for new finder files

PHPBB3-12631
This commit is contained in:
Marc Alexander 2021-10-10 11:52:47 +02:00
parent ed1566d217
commit cdd1e7849a
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
3 changed files with 16 additions and 10 deletions

View file

@ -13,6 +13,8 @@
namespace phpbb\finder; namespace phpbb\finder;
use phpbb\cache\service;
/** /**
* The finder provides a simple way to locate files in the core and a set of extensions * The finder provides a simple way to locate files in the core and a set of extensions
*/ */
@ -26,12 +28,12 @@ class factory
/** /**
* Creates a new finder instance with its dependencies * Creates a new finder instance with its dependencies
* *
* @param \phpbb\cache\service $cache A cache instance or null * @param service|null $cache A cache instance or null
* @param bool $use_cache Use cache or not * @param bool $use_cache Use cache or not
* @param string $phpbb_root_path Path to the phpbb root directory * @param string $phpbb_root_path Path to the phpbb root directory
* @param string $php_ext php file extension * @param string $php_ext php file extension
*/ */
public function __construct(/*\phpbb\cache\service */ $cache, $use_cache, $phpbb_root_path, $php_ext) public function __construct(?service $cache, bool $use_cache, string $phpbb_root_path, string $php_ext)
{ {
$this->cache = $cache; $this->cache = $cache;
$this->use_cache = $use_cache; $this->use_cache = $use_cache;
@ -44,10 +46,10 @@ class factory
* *
* Allows the use of multiple differently configured finders with the same cache. * Allows the use of multiple differently configured finders with the same cache.
* *
* @param string $cache_name The name of the cache variable, defaults to * @param string $cache_name The name of the cache variable, defaults to _ext_finder
* _ext_finder * @return finder New instance of finder
*/ */
public function get($cache_name = '_ext_finder') public function get(string $cache_name = '_ext_finder'): finder
{ {
return new finder($this->cache, $this->use_cache, $this->phpbb_root_path, $this->php_ext, $cache_name); return new finder($this->cache, $this->use_cache, $this->phpbb_root_path, $this->php_ext, $cache_name);
} }

View file

@ -13,6 +13,7 @@
namespace phpbb\finder; namespace phpbb\finder;
use phpbb\cache\service;
use phpbb\filesystem\helper as filesystem_helper; use phpbb\filesystem\helper as filesystem_helper;
/** /**
@ -51,12 +52,13 @@ class finder
* Creates a new finder instance with its dependencies * Creates a new finder instance with its dependencies
* *
* @param string $phpbb_root_path Path to the phpbb root directory * @param string $phpbb_root_path Path to the phpbb root directory
* @param \phpbb\cache\service|null $cache A cache instance or null * @param service|null $cache A cache instance or null
* @param bool $use_cache Flag whether cache should be used
* @param string $php_ext php file extension * @param string $php_ext php file extension
* @param string $cache_name The name of the cache variable, defaults to * @param string $cache_name The name of the cache variable, defaults to
* _ext_finder * _ext_finder
*/ */
public function __construct(/*\phpbb\cache\service */ $cache, $use_cache, $phpbb_root_path, $php_ext, $cache_name = '_ext_finder') public function __construct(?service $cache, bool $use_cache, string $phpbb_root_path, string $php_ext, string $cache_name = '_ext_finder')
{ {
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->cache = $cache; $this->cache = $cache;

View file

@ -46,7 +46,7 @@ class create_schema_file extends \phpbb\install\task_base
protected $php_ext; protected $php_ext;
/** /**
* @var string * @var bool
*/ */
protected $finder_cache; protected $finder_cache;
@ -58,6 +58,7 @@ class create_schema_file extends \phpbb\install\task_base
* @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem service * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem service
* @param string $phpbb_root_path Path phpBB's root * @param string $phpbb_root_path Path phpBB's root
* @param string $php_ext Extension of PHP files * @param string $php_ext Extension of PHP files
* @param bool $finder_cache Flag whether to cache finder
*/ */
public function __construct(\phpbb\install\helper\config $config, public function __construct(\phpbb\install\helper\config $config,
\phpbb\install\helper\database $db_helper, \phpbb\install\helper\database $db_helper,
@ -124,7 +125,8 @@ class create_schema_file extends \phpbb\install\task_base
include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext); include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext);
} }
$finder = new \phpbb\finder\finder(null, $this->finder_cache, $this->phpbb_root_path, $this->php_ext); $finder_factory = new \phpbb\finder\factory(null, $this->finder_cache, $this->phpbb_root_path, $this->php_ext);
$finder = $finder_factory->get();
$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($this->db, true); $db_tools = $factory->get($this->db, true);