diff options
| author | 2025-12-17 10:11:18 +0100 | |
|---|---|---|
| committer | 2025-12-17 10:11:18 +0100 | |
| commit | 00cd5df294c875ea1e00ab2f645a338a6bd92c8e (patch) | |
| tree | e1dc56d3d01bffea632d1d4c08a1153d7ea7a7c5 /lib/Minz | |
| parent | 4bd503591469f47e710f1afbf0b5883f7770065d (diff) | |
Use native PHP #[Deprecated] (#8325)
https://php.watch/versions/8.4/Deprecated
And enfore it with PHPUnit + PHPStan.
Especially useful for extensions.
Diffstat (limited to 'lib/Minz')
| -rw-r--r-- | lib/Minz/ActionController.php | 6 | ||||
| -rw-r--r-- | lib/Minz/Configuration.php | 42 | ||||
| -rw-r--r-- | lib/Minz/Request.php | 2 | ||||
| -rw-r--r-- | lib/Minz/Session.php | 2 | ||||
| -rw-r--r-- | lib/Minz/View.php | 5 |
5 files changed, 34 insertions, 23 deletions
diff --git a/lib/Minz/ActionController.php b/lib/Minz/ActionController.php index 9549a146f..eb6e8477d 100644 --- a/lib/Minz/ActionController.php +++ b/lib/Minz/ActionController.php @@ -27,6 +27,8 @@ abstract class Minz_ActionController { * Gives the possibility to override the default view model type. * @var class-string * @deprecated Use constructor with view type instead + * @access private + * @internal */ public static string $defaultViewType = Minz_View::class; @@ -43,8 +45,8 @@ abstract class Minz_ActionController { $view = null; } } - if ($view === null && class_exists(self::$defaultViewType)) { - $view = new self::$defaultViewType(); + if ($view === null && class_exists(self::$defaultViewType)) { /// @phpstan-ignore staticProperty.deprecated + $view = new self::$defaultViewType(); // @phpstan-ignore staticProperty.deprecated if (!($view instanceof Minz_View)) { $view = null; } diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index e0480b414..45988f4a9 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -26,7 +26,7 @@ class Minz_Configuration { * @param string $namespace the name of the current configuration * @param string $config_filename the filename of the configuration * @param string $default_filename a filename containing default values for the configuration - * @param Minz_ConfigurationSetterInterface $configuration_setter an optional helper to set values in configuration + * @param Minz_ConfigurationSetterInterface $configuration_setter an optional helper to set values in configuration @deprecated * @throws Minz_FileNotExistException */ public static function register(string $namespace, string $config_filename, ?string $default_filename = null, @@ -102,7 +102,7 @@ class Minz_Configuration { * @param string $namespace the name of the current configuration. * @param string $config_filename the file containing configuration values. * @param string $default_filename the file containing default values, null by default. - * @param Minz_ConfigurationSetterInterface $configuration_setter an optional helper to set values in configuration + * @param Minz_ConfigurationSetterInterface $configuration_setter an optional helper to set values in configuration @deprecated * @throws Minz_FileNotExistException */ final private function __construct(string $namespace, string $config_filename, ?string $default_filename = null, @@ -138,6 +138,7 @@ class Minz_Configuration { } } + #[Deprecated] public function configurationSetter(): ?Minz_ConfigurationSetterInterface { return $this->configuration_setter; } @@ -155,13 +156,12 @@ class Minz_Configuration { * @param string $key the name of the param. * @param mixed $default default value to return if key does not exist. * @return array|mixed value corresponding to the key. - * @access private - * @deprecated Use `attribute*()` methods instead. */ + #[Deprecated('Use `attribute*()` methods instead.')] public function param(string $key, mixed $default = null): mixed { if (isset($this->data[$key])) { return $this->data[$key]; - } elseif (!is_null($default)) { + } elseif ($default !== null) { return $default; } else { Minz_Log::warning($key . ' does not exist in configuration'); @@ -170,13 +170,14 @@ class Minz_Configuration { } /** - * A wrapper for param(). * @return array|mixed - * @access private - * @deprecated */ public function __get(string $key): mixed { - return $this->param($key); + if (isset($this->data[$key])) { + return $this->data[$key]; + } + Minz_Log::warning($key . ' does not exist in configuration'); + return null; } /** @@ -184,13 +185,12 @@ class Minz_Configuration { * * @param string $key the param name to set. * @param mixed $value the value to set. If null, the key is removed from the configuration. - * @access private - * @deprecated Use `_attribute()` instead. */ + #[Deprecated('Use `_attribute()` instead.')] public function _param(string $key, mixed $value = null): void { if ($this->configuration_setter !== null && $this->configuration_setter->support($key)) { $this->configuration_setter->handle($this->data, $key, $value); - } elseif (isset($this->data[$key]) && is_null($value)) { + } elseif (isset($this->data[$key]) && $value === null) { unset($this->data[$key]); } elseif ($value !== null) { $this->data[$key] = $value; @@ -198,12 +198,16 @@ class Minz_Configuration { } /** - * A wrapper for _param(). - * @access private - * @deprecated + * {@see Minz_Configuration::_attribute()} instead. + * @param string $key the param name to set. + * @param mixed $value the value to set. If null, the key is removed. */ public function __set(string $key, mixed $value): void { - $this->_param($key, $value); + if ($value === null) { + unset($this->data[$key]); + } else { + $this->data[$key] = $value; + } } /** @@ -266,6 +270,10 @@ class Minz_Configuration { * @param array<string,mixed>|mixed|null $value Value, not HTML-encoded */ public function _attribute(string $key, $value = null): void { - self::_param($key, $value); + if (isset($this->data[$key]) && $value === null) { + unset($this->data[$key]); + } elseif ($value !== null) { + $this->data[$key] = $value; + } } } diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index 8667c6442..cfb309ff6 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -42,8 +42,8 @@ class Minz_Request { * @param mixed $default default value, if no parameter is given * @param bool $specialchars `true` to return special characters, `false` (default) to XML-encode them * @return mixed value of the parameter - * @deprecated use typed versions instead */ + #[Deprecated('Use typed versions instead')] public static function param(string $key, mixed $default = false, bool $specialchars = false): mixed { if (isset(self::$params[$key])) { $p = self::$params[$key]; diff --git a/lib/Minz/Session.php b/lib/Minz/Session.php index 2f4058905..d9eab6434 100644 --- a/lib/Minz/Session.php +++ b/lib/Minz/Session.php @@ -61,8 +61,8 @@ class Minz_Session { * @param string $p the parameter to retrieve * @param mixed|false $default the default value if the parameter doesn’t exist * @return mixed|false the value of the session variable, false if doesn’t exist - * @deprecated Use typed versions instead */ + #[Deprecated('Use typed versions instead')] public static function param(string $p, $default = false): mixed { return $_SESSION[$p] ?? $default; } diff --git a/lib/Minz/View.php b/lib/Minz/View.php index 65573c7bd..eebd7ee92 100644 --- a/lib/Minz/View.php +++ b/lib/Minz/View.php @@ -39,8 +39,9 @@ class Minz_View { } /** - * @deprecated Change the view file based on controller and action. + * Change the view file based on controller and action. */ + #[Deprecated('Use Minz_View::_path() instead.')] public function change_view(string $controller_name, string $action_name): void { Minz_Log::warning('Minz_View::change_view is deprecated, it will be removed in a future version. Please use Minz_View::_path instead.'); $this->_path($controller_name . '/' . $action_name . '.phtml'); @@ -170,9 +171,9 @@ class Minz_View { /** * Choose if we want to use the layout or not. - * @deprecated Please use the `_layout` function instead. * @param bool $use true if we want to use the layout, false else */ + #[Deprecated('Use Minz_View::_layout() instead.')] public function _useLayout(bool $use): void { Minz_Log::warning('Minz_View::_useLayout is deprecated, it will be removed in a future version. Please use Minz_View::_layout instead.'); if ($use) { |
