Skip to content

Commit

Permalink
Bump PHPStan to level 6 (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
BelleNottelling committed May 27, 2024
1 parent 7fdecf7 commit 2248d2f
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 5 deletions.
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
parameters:
level: 5
level: 6
paths:
- src
excludePaths:
analyse:
- src/Vendor
- src/Cache
- src/AntCMS/Users.php
bootstrapFiles:
- src/bootstrap.php
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![PHPStan Level](https://img.shields.io/badge/PHPStan-level%205-brightgreen)
![PHPStan Level](https://img.shields.io/badge/PHPStan-level%206-brightgreen)
[![CI](https://github.com/AntCMS-org/AntCMS/actions/workflows/ci.yml/badge.svg)](https://github.com/AntCMS-org/AntCMS/actions/workflows/ci.yml)
![Supported PHP Versions](https://img.shields.io/badge/PHP%20Versions-8.1%7C8.2%7C8.3-brightgreen)
![GitHub Release](https://img.shields.io/github/v/release/AntCMS-org/AntCMS)
Expand Down
3 changes: 3 additions & 0 deletions src/AntCMS/AntCMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public function serveContent(?string $path = null): void
}
}

/**
* @return mixed[]
*/
public static function getThemeConfig(string|null $theme = null): array
{
$theme ??= CURRENT_THEME;
Expand Down
8 changes: 6 additions & 2 deletions src/AntCMS/AntYaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
*/
class AntYaml
{
/** @var array $yamlCache An in-memory cache for parsed YAML files to prevent repeat hits from slowing down AntCMS. */
/** @var array<string, mixed> $yamlCache An in-memory cache for parsed YAML files to prevent repeat hits from slowing down AntCMS. */
private static array $yamlCache = [];

/**
* Parses a YAML file and returns the content as an array.
* @throws ParseException;
* @throws ParseException
* @return mixed[]
*/
public static function parseFile(string $path): array
{
Expand All @@ -43,6 +44,9 @@ public static function saveFile(string $path, array $data): bool
return (bool) file_put_contents($path, $yaml);
}

/**
* @return mixed[]
*/
public static function parseYaml(string $yaml): array
{
return Yaml::parse($yaml);
Expand Down
2 changes: 2 additions & 0 deletions src/AntCMS/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ private function sendResponse(ApiResponse $apiResponse): void
* - URL parameters (/foo/bar/)
* - The raw request body
* - If the request body was of valid JSON, an array of the decoded JSON
*
* @return array<string, mixed[]>
*/
private function getApiCallData(string $plugin, string $method): array
{
Expand Down
3 changes: 3 additions & 0 deletions src/AntCMS/ApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public function __construct(private mixed $result, private readonly bool $error
{
}

/**
* @return array<string, string>
*/
public function getBody(): array
{
$result = [
Expand Down
6 changes: 6 additions & 0 deletions src/AntCMS/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Cache
public static int $mediumLifespan = 86400 * 7; // 1 week
public static int $shortLifespan = 900; // 15 min (in-memory)

/**
* @param string[] $allowed
*/
public static function setup(array $allowed = []): void
{
$adapters = [];
Expand All @@ -40,6 +43,9 @@ public static function setup(array $allowed = []): void
}
}

/**
* @param mixed[] $metadata
*/
public static function get(string $key, callable|CallbackInterface $callable, ?float $beta = null, ?array &$metadata = []): mixed
{
return self::$adapter->get($key, $callable, $beta, $metadata);
Expand Down
1 change: 1 addition & 0 deletions src/AntCMS/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class Config
{
/** @var string[] */
private static array $ConfigKeys = [
'siteInfo',
'performance',
Expand Down
2 changes: 1 addition & 1 deletion src/AntCMS/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(string $name, public string $description)
/**
* Fires the hook
*
* @param array $params An array of values to pass to the callbacks registered for this hook
* @param mixed[] $params An array of values to pass to the callbacks registered for this hook
*/
public function fire(array $params): void
{
Expand Down
6 changes: 6 additions & 0 deletions src/AntCMS/HookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class HookController
/** @var Hook[] */
private static array $hooks = [];

/**
* @return Hook[]
*/
public static function getHookList(): array
{
return self::$hooks;
Expand Down Expand Up @@ -38,6 +41,9 @@ public static function registerCallback(string $name, callable $callback): void
self::$hooks[$name]->registerCallback($callback);
}

/**
* @param mixed[] $params
*/
public static function fire(string $name, array $params): void
{
if (self::isRegistered($name)) {
Expand Down
9 changes: 9 additions & 0 deletions src/AntCMS/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class Pages
{
private static string $currentPage = "";

/**
* @return array<string, mixed>
*/
private static function generatePageInfo(string $path): array
{
$contents = file_get_contents($path);
Expand All @@ -26,6 +29,9 @@ private static function generatePageInfo(string $path): array
];
}

/**
* @return array<string, mixed>
*/
private static function getDirectoryMeta(string $path): array
{
$metaPath = $path . DIRECTORY_SEPARATOR . 'meta.yaml';
Expand Down Expand Up @@ -131,6 +137,9 @@ private static function buildList(string $path = PATH_CONTENT): array
return $result;
}

/**
* @return mixed[]
*/
public static function getPages(string $currentPage = ''): array
{
self::$currentPage = $currentPage;
Expand Down
14 changes: 14 additions & 0 deletions src/AntCMS/PluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

class PluginController
{
/** @var string[] */
private static array $plugins = [];

/** @var array<string, string[]> */
private static array $sitemapUrls = [];

/** @var array<string, string[]> */
private static array $robotsTxtAdditons = [
'allow' => [],
'disallow' => [],
Expand Down Expand Up @@ -47,16 +52,25 @@ public static function init(): void
}
}

/**
* @return string[]
*/
public static function getLoadedPlugins(): array
{
return self::$plugins;
}

/**
* @return array<string, string[]>
*/
public static function getSitemapUrls(): array
{
return self::$sitemapUrls;
}

/**
* @return array<string, string[]>
*/
public static function getRobotsTxtEntries(): array
{
return self::$robotsTxtAdditons;
Expand Down
12 changes: 12 additions & 0 deletions src/AntCMS/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

class Tools
{
/**
* @var string[]
*/
private static array $textAssets = [
'css',
'html',
Expand Down Expand Up @@ -76,6 +79,10 @@ public static function convertFunctionaltoFullpath(string $path): string
return Tools::repairFilePath($pagePath);
}

/**
* @param string[] $required
* @param mixed[] $actual
*/
public static function valuesNotNull(array $required, array $actual): bool
{
foreach ($required as $key) {
Expand Down Expand Up @@ -202,6 +209,8 @@ public static function getAssetCacheKey(string $path): string
/**
* Automatically selects an ideal compression method for various types of assets.
* Impliments caching to prevent repeat processing of assets.
*
* @return string[] [contents, content encoding]
*/
public static function doAssetCompression(string $path): array
{
Expand Down Expand Up @@ -237,6 +246,9 @@ public static function doAssetCompression(string $path): array
return [$contents, $encoding];
}

/**
* @return array<string, float>
*/
public static function getPerformanceMetrics(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions src/AntCMS/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public static function templateExists(string $name): bool
return self::$twigEnvironment->getLoader()->exists($name);
}

/**
* @param array<string, mixed> $data
*/
public static function render(string $template, array $data = []): string
{
return self::$twigEnvironment->render($template, $data);
Expand Down
4 changes: 4 additions & 0 deletions src/Plugins/Sitemap/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public function __construct()
});
}

/**
* @param array<string, mixed> $list
* @param string[] $urls
*/
private function addPages(array $list, array &$urls): void
{
foreach ($list as $item) {
Expand Down
3 changes: 3 additions & 0 deletions src/Plugins/System/Api/PublicApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

class PublicApi
{
/**
* @param array<string, mixed> $data
*/
public function status(array $data): Response
{
return new Response('okay');
Expand Down
3 changes: 3 additions & 0 deletions src/Plugins/System/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

class Controller extends AbstractPlugin
{
/**
* @var array<string, string>
*/
private array $hooks = [
'contentHit' => 'This is fired when markdown content is accessed. The URI will be passed in the data.',
'performanceMetricsBuilt' => 'When fired, this event contains all performance metrics AntCMS was able to collect on a request. These are more complete & accurate than the metrics shown on the bottom of the screen.',
Expand Down

0 comments on commit 2248d2f

Please sign in to comment.