Skip to content

Commit

Permalink
Merge pull request #8114 from paulbalandan/phpstan-phpdocs
Browse files Browse the repository at this point in the history
docs: Use native PHPDocs instead of `@phpstan-`
  • Loading branch information
kenjis authored Oct 30, 2023
2 parents ab7d167 + 339d527 commit 6c06f84
Show file tree
Hide file tree
Showing 42 changed files with 94 additions and 148 deletions.
3 changes: 1 addition & 2 deletions app/Config/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class App extends BaseConfig
* 'http://accounts.example.com/':
* ['media.example.com', 'accounts.example.com']
*
* @var string[]
* @phpstan-var list<string>
* @var list<string>
*/
public array $allowedHostnames = [];

Expand Down
9 changes: 3 additions & 6 deletions app/Config/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class Autoload extends AutoloadConfig
* 'App' => APPPATH
* ];
*
* @var array<string, array<int, string>|string>
* @phpstan-var array<string, string|list<string>>
* @var array<string, list<string>|string>
*/
public $psr4 = [
APP_NAMESPACE => APPPATH, // For custom app namespace
Expand Down Expand Up @@ -81,8 +80,7 @@ class Autoload extends AutoloadConfig
* '/path/to/my/file.php',
* ];
*
* @var string[]
* @phpstan-var list<string>
* @var list<string>
*/
public $files = [];

Expand All @@ -95,8 +93,7 @@ class Autoload extends AutoloadConfig
* 'form',
* ];
*
* @var string[]
* @phpstan-var list<string>
* @var list<string>
*/
public $helpers = [];
}
3 changes: 1 addition & 2 deletions app/Config/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ class Cache extends BaseConfig
* This is an array of cache engine alias' and class names. Only engines
* that are listed here are allowed to be used.
*
* @var array<string, string>
* @phpstan-var array<string, class-string<CacheInterface>>
* @var array<string, class-string<CacheInterface>>
*/
public array $validHandlers = [
'dummy' => DummyHandler::class,
Expand Down
8 changes: 3 additions & 5 deletions app/Config/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class Filters extends BaseConfig
* Configures aliases for Filter classes to
* make reading things nicer and simpler.
*
* @var array<string, array<int, string>|string> [filter_name => classname]
* or [filter_name => [classname1, classname2, ...]]
* @phpstan-var array<string, class-string|list<class-string>>
* @var array<string, class-string|list<class-string>> [filter_name => classname]
* or [filter_name => [classname1, classname2, ...]]
*/
public array $aliases = [
'csrf' => CSRF::class,
Expand All @@ -31,8 +30,7 @@ class Filters extends BaseConfig
* List of filter aliases that are always
* applied before and after every request.
*
* @var array<string, array<string, array<string, string>>>|array<string, array<string>>
* @phpstan-var array<string, list<string>>|array<string, array<string, array<string, string>>>
* @var array<string, array<string, array<string, string>>>|array<string, list<string>>
*/
public array $globals = [
'before' => [
Expand Down
9 changes: 3 additions & 6 deletions app/Config/Kint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class Kint extends BaseConfig
*/

/**
* @var array<int, ConstructablePluginInterface|string>
* @phpstan-var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>
* @var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>
*/
public $plugins;

Expand All @@ -46,14 +45,12 @@ class Kint extends BaseConfig
public int $richSort = AbstractRenderer::SORT_FULL;

/**
* @var array<string, string>
* @phpstan-var array<string, class-string<ValuePluginInterface>>
* @var array<string, class-string<ValuePluginInterface>>
*/
public $richObjectPlugins;

/**
* @var array<string, string>
* @phpstan-var array<string, class-string<TabPluginInterface>>
* @var array<string, class-string<TabPluginInterface>>
*/
public $richTabPlugins;

Expand Down
2 changes: 1 addition & 1 deletion app/Config/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Session extends BaseConfig
* - `CodeIgniter\Session\Handlers\MemcachedHandler`
* - `CodeIgniter\Session\Handlers\RedisHandler`
*
* @phpstan-var class-string<BaseHandler>
* @var class-string<BaseHandler>
*/
public string $driver = FileHandler::class;

Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
];
$ignoreErrors[] = [
'message' => '#^Property Config\\\\Autoload\\:\\:\\$helpers \\(array\\<int, string\\>\\) in isset\\(\\) is not nullable\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/Autoloader.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 13,
Expand Down
11 changes: 4 additions & 7 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,15 @@ class Autoloader
/**
* Stores files as a list.
*
* @var string[]
* @phpstan-var list<string>
* @var list<string>
*/
protected $files = [];

/**
* Stores helper list.
* Always load the URL helper, it should be used in most apps.
*
* @var string[]
* @phpstan-var list<string>
* @var list<string>
*/
protected $helpers = ['url'];

Expand Down Expand Up @@ -119,7 +117,7 @@ public function initialize(Autoload $config, Modules $modules)
$this->files = $config->files;
}

if (isset($config->helpers)) { // @phpstan-ignore-line
if (isset($config->helpers)) {
$this->helpers = [...$this->helpers, ...$config->helpers];
}

Expand Down Expand Up @@ -185,8 +183,7 @@ public function unregister(): void
/**
* Registers namespaces with the autoloader.
*
* @param array<string, array<int, string>|string>|string $namespace
* @phpstan-param array<string, list<string>|string>|string $namespace
* @param array<string, list<string>|string>|string $namespace
*
* @return $this
*/
Expand Down
3 changes: 1 addition & 2 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ abstract class BaseModel
* The Database connection group that
* should be instantiated.
*
* @var string|null
* @phpstan-var non-empty-string|null
* @var non-empty-string|null
*/
protected $DBGroup;

Expand Down
7 changes: 3 additions & 4 deletions system/Cache/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ public static function validateKey($key, $prefix = ''): string
/**
* Get an item from the cache, or execute the given Closure and store the result.
*
* @param string $key Cache item name
* @param int $ttl Time to live
* @param Closure $callback Callback return value
* @phpstan-param Closure(): mixed $callback
* @param string $key Cache item name
* @param int $ttl Time to live
* @param Closure(): mixed $callback Callback return value
*
* @return array|bool|float|int|object|string|null
*/
Expand Down
3 changes: 1 addition & 2 deletions system/Cache/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ public function isSupported(): bool
* Does the heavy lifting of actually retrieving the file and
* verifying it's age.
*
* @return array<string, mixed>|false
* @phpstan-return array{data: mixed, ttl: int, time: int}|false
* @return array{data: mixed, ttl: int, time: int}|false
*/
protected function getItem(string $filename)
{
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Database/ShowTableInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ShowTableInfo extends BaseCommand
];

/**
* @phpstan-var list<list<string|int>> Table Data.
* @var list<list<int|string>> Table Data.
*/
private array $tbody;

Expand Down
3 changes: 1 addition & 2 deletions system/Commands/Utilities/Routes/AutoRouteCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public function __construct(string $namespace, string $defaultController, string
}

/**
* @return array<int, array<int, string>>
* @phpstan-return list<list<string>>
* @return list<list<string>>
*/
public function get(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public function __construct(
}

/**
* @return array<int, array<int, string>>
* @phpstan-return list<list<string>>
* @return list<list<string>>
*/
public function get(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ final class ControllerMethodReader
private string $namespace;

/**
* @var array<int, string>
* @phpstan-var list<string>
* @var list<string>
*/
private array $httpMethods;

Expand All @@ -44,10 +43,9 @@ public function __construct(string $namespace, array $httpMethods)
/**
* Returns found route info in the controller.
*
* @phpstan-param class-string $class
* @param class-string $class
*
* @return array<int, array<string, array|string>>
* @phpstan-return list<array<string, string|array>>
* @return list<array<string, array|string>>
*/
public function read(string $class, string $defaultController = 'Home', string $defaultMethod = 'index'): array
{
Expand Down Expand Up @@ -154,7 +152,7 @@ private function getParameters(ReflectionMethod $method): array
}

/**
* @phpstan-param class-string $classname
* @param class-string $classname
*
* @return string URI path part from the folder(s) and controller
*/
Expand All @@ -179,7 +177,7 @@ private function getUriByClass(string $classname): string
/**
* Gets a route for the default controller.
*
* @phpstan-return list<array>
* @return list<array>
*/
private function getRouteForDefaultController(
string $classShortname,
Expand Down
5 changes: 2 additions & 3 deletions system/Commands/Utilities/Routes/ControllerFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public function __construct(string $namespace)
}

/**
* @return string[]
* @phpstan-return class-string[]
* @return class-string[]
*/
public function find(): array
{
Expand All @@ -66,7 +65,7 @@ public function find(): array
$classnameOrEmpty = $this->locator->getClassname($file);

if ($classnameOrEmpty !== '') {
/** @phpstan-var class-string $classname */
/** @var class-string $classname */
$classname = $classnameOrEmpty;

$classes[] = $classname;
Expand Down
7 changes: 3 additions & 4 deletions system/Commands/Utilities/Routes/ControllerMethodReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ public function __construct(string $namespace)
}

/**
* @phpstan-param class-string $class
* @param class-string $class
*
* @return array<int, array{route: string, handler: string}>
* @phpstan-return list<array{route: string, handler: string}>
* @return list<array{route: string, handler: string}>
*/
public function read(string $class, string $defaultController = 'Home', string $defaultMethod = 'index'): array
{
Expand Down Expand Up @@ -128,7 +127,7 @@ private function hasRemap(ReflectionClass $class): bool
}

/**
* @phpstan-param class-string $classname
* @param class-string $classname
*
* @return string URI path part from the folder(s) and controller
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ function stringify_attributes($attributes, bool $js = false): string
* returns its return value if any.
* Otherwise will start or stop the timer intelligently.
*
* @phpstan-param (callable(): mixed)|null $callable
* @param (callable(): mixed)|null $callable
*
* @return Timer
*/
Expand Down
6 changes: 2 additions & 4 deletions system/Config/AutoloadConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class AutoloadConfig
* but this should be done prior to creating any namespaced classes,
* else you will need to modify all of those classes for this to work.
*
* @var array<string, array<int, string>|string>
* @phpstan-var array<string, string|list<string>>
* @var array<string, list<string>|string>
*/
public $psr4 = [];

Expand All @@ -72,8 +71,7 @@ class AutoloadConfig
* that will be autoloaded. This can be useful for bootstrap operations
* or for loading functions.
*
* @var array<int, string>
* @phpstan-var list<string>
* @var list<string>
*/
public $files = [];

Expand Down
13 changes: 5 additions & 8 deletions system/Config/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ class Factories
*
* [component => [alias => FQCN]]
*
* @var array<string, array<string, string>>
* @phpstan-var array<string, array<string, class-string>>
* @var array<string, array<string, class-string>>
*/
protected static $aliases = [];

Expand All @@ -76,8 +75,7 @@ class Factories
*
* [component => [FQCN => instance]]
*
* @var array<string, array<string, object>>
* @phpstan-var array<string, array<class-string, object>>
* @var array<string, array<class-string, object>>
*/
protected static $instances = [];

Expand All @@ -93,10 +91,9 @@ class Factories
/**
* Define the class to load. You can *override* the concrete class.
*
* @param string $component Lowercase, plural component name
* @param string $alias Class alias. See the $aliases property.
* @param string $classname FQCN to be loaded
* @phpstan-param class-string $classname FQCN to be loaded
* @param string $component Lowercase, plural component name
* @param string $alias Class alias. See the $aliases property.
* @param class-string $classname FQCN to be loaded
*/
public static function define(string $component, string $alias, string $classname): void
{
Expand Down
Loading

0 comments on commit 6c06f84

Please sign in to comment.