aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-04-05 23:26:38 +0200
committerGravatar GitHub <noreply@github.com> 2023-04-05 23:26:38 +0200
commit2118448133e327294ad2b69ed8736bc29879103d (patch)
tree00c003056dedbd8e3554801d6493a25641a260a5 /lib
parent4f078958b5603900592e14f9f3189bbebfc81bab (diff)
PHPStan level 6 for more files (#5264)
7 more files passing (see phpstan-next.txt)
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/ActionController.php16
-rw-r--r--lib/Minz/FrontController.php9
-rw-r--r--lib/Minz/ModelArray.php13
-rw-r--r--lib/Minz/Url.php20
4 files changed, 36 insertions, 22 deletions
diff --git a/lib/Minz/ActionController.php b/lib/Minz/ActionController.php
index c29ae8ad8..8cc9fbc0b 100644
--- a/lib/Minz/ActionController.php
+++ b/lib/Minz/ActionController.php
@@ -17,9 +17,13 @@ class Minz_ActionController {
/** @var array<string,string> */
private $csp_policies;
+ /** @var Minz_View */
protected $view;
- // Gives the possibility to override the default View type.
+ /**
+ * Gives the possibility to override the default View type.
+ * @var class-string
+ */
public static $viewType = 'Minz_View';
public function __construct () {
@@ -37,7 +41,7 @@ class Minz_ActionController {
/**
* Getteur
*/
- public function view () {
+ public function view(): Minz_View {
return $this->view;
}
@@ -45,7 +49,7 @@ class Minz_ActionController {
* Set default CSP policies.
* @param array<string,string> $policies An array where keys are directives and values are sources.
*/
- public static function _defaultCsp($policies) {
+ public static function _defaultCsp(array $policies): void {
if (!isset($policies['default-src'])) {
Minz_Log::warning('Default CSP policy is not declared', ADMIN_LOG);
}
@@ -61,9 +65,9 @@ class Minz_ActionController {
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src
*
- * @param array $policies An array where keys are directives and values are sources.
+ * @param array<string,string> $policies An array where keys are directives and values are sources.
*/
- protected function _csp($policies) {
+ protected function _csp(array $policies): void {
if (!isset($policies['default-src'])) {
$action = Minz_Request::controllerName() . '#' . Minz_Request::actionName();
Minz_Log::warning(
@@ -77,7 +81,7 @@ class Minz_ActionController {
/**
* Send HTTP Content-Security-Policy header based on declared policies.
*/
- public function declareCspHeader() {
+ public function declareCspHeader(): void {
$policies = [];
foreach ($this->csp_policies as $directive => $sources) {
$policies[] = $directive . ' ' . $sources;
diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php
index a5f73b59f..4837f89c1 100644
--- a/lib/Minz/FrontController.php
+++ b/lib/Minz/FrontController.php
@@ -24,6 +24,8 @@
* It is generally invoqued by an index.php file at the root.
*/
class Minz_FrontController {
+
+ /** @var Minz_Dispatcher */
protected $dispatcher;
/**
@@ -53,7 +55,7 @@ class Minz_FrontController {
/**
* Démarre l'application (lance le dispatcher et renvoie la réponse)
*/
- public function run() {
+ public function run(): void {
try {
$this->dispatcher->run();
} catch (Minz_Exception $e) {
@@ -80,8 +82,9 @@ class Minz_FrontController {
/**
* Kills the programme
+ * @return never
*/
- public static function killApp($txt = '') {
+ public static function killApp(string $txt = '') {
header('HTTP 1.1 500 Internal Server Error', true, 500);
if (function_exists('errorMessageInfo')) {
//If the application has defined a custom error message function
@@ -90,7 +93,7 @@ class Minz_FrontController {
die('### Application problem ###<br />' . "\n" . $txt);
}
- private function setReporting() {
+ private function setReporting(): void {
$envType = getenv('FRESHRSS_ENV');
if ($envType == '') {
$conf = Minz_Configuration::get('system');
diff --git a/lib/Minz/ModelArray.php b/lib/Minz/ModelArray.php
index 72de35f35..0d8b71f91 100644
--- a/lib/Minz/ModelArray.php
+++ b/lib/Minz/ModelArray.php
@@ -10,6 +10,7 @@
class Minz_ModelArray {
/**
* $filename est le nom du fichier
+ * @var string
*/
protected $filename;
@@ -22,7 +23,8 @@ class Minz_ModelArray {
$this->filename = $filename;
}
- protected function loadArray() {
+ /** @return array<string,mixed> */
+ protected function loadArray(): array {
if (!file_exists($this->filename)) {
throw new Minz_FileNotExistException($this->filename, Minz_Exception::WARNING);
} elseif (($handle = $this->getLock()) === false) {
@@ -42,8 +44,9 @@ class Minz_ModelArray {
/**
* Sauve le tableau $array dans le fichier $filename
- **/
- protected function writeArray($array) {
+ * @param array<string,mixed> $array
+ */
+ protected function writeArray(array $array): bool {
if (file_put_contents($this->filename, "<?php\n return " . var_export($array, true) . ';', LOCK_EX) === false) {
throw new Minz_PermissionDeniedException($this->filename);
}
@@ -53,6 +56,7 @@ class Minz_ModelArray {
return true;
}
+ /** @return resource|false */
private function getLock() {
$handle = fopen($this->filename, 'r');
if ($handle === false) {
@@ -73,7 +77,8 @@ class Minz_ModelArray {
}
}
- private function releaseLock($handle) {
+ /** @param resource $handle */
+ private function releaseLock($handle): void {
flock($handle, LOCK_UN);
fclose($handle);
}
diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php
index 0780a636f..efffb7f25 100644
--- a/lib/Minz/Url.php
+++ b/lib/Minz/Url.php
@@ -15,7 +15,7 @@ class Minz_Url {
* @param bool|string $absolute
* @return string Formatted URL
*/
- public static function display ($url = array (), $encoding = 'html', $absolute = false) {
+ public static function display($url = [], string $encoding = 'html', $absolute = false): string {
$isArray = is_array($url);
if ($isArray) {
@@ -60,7 +60,7 @@ class Minz_Url {
* @param string $encodage pour indiquer comment encoder les & (& ou &amp; pour html)
* @return string uri sous la forme ?key=value&key2=value2
*/
- private static function printUri($url, $encodage) {
+ private static function printUri($url, string $encodage): string {
$uri = '';
$separator = '?';
$anchor = '';
@@ -129,7 +129,8 @@ class Minz_Url {
return $url_checked;
}
- public static function serialize($url = []) {
+ /** @param array<string,string|array<string,string>> $url */
+ public static function serialize(array $url = []): string {
try {
return base64_encode(json_encode($url, JSON_THROW_ON_ERROR));
} catch (\Throwable $exception) {
@@ -137,19 +138,20 @@ class Minz_Url {
}
}
- public static function unserialize($url = '') {
+ /** @return array<string,string|array<string,string>> */
+ public static function unserialize(string $url = ''): array {
try {
- return json_decode(base64_decode($url), true, JSON_THROW_ON_ERROR);
+ return json_decode(base64_decode($url), true, JSON_THROW_ON_ERROR) ?? [];
} catch (\Throwable $exception) {
- return '';
+ return [];
}
}
/**
* Returns an array representing the URL as passed in the address bar
- * @return array URL representation
+ * @return array<string,string|array<string,string>> URL representation
*/
- public static function build () {
+ public static function build(): array {
$url = [
'c' => $_GET['c'] ?? Minz_Request::defaultControllerName(),
'a' => $_GET['a'] ?? Minz_Request::defaultActionName(),
@@ -170,7 +172,7 @@ class Minz_Url {
* @param string|int ...$args
* @return string|false
*/
-function _url ($controller, $action, ...$args) {
+function _url(string $controller, string $action, ...$args) {
$nb_args = count($args);
if ($nb_args % 2 !== 0) {